Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectronicBlueberry committed Mar 15, 2024
1 parent 61efe13 commit da7349a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
22 changes: 11 additions & 11 deletions client/src/components/TagsMultiselect/HeadlessMultiselect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe("HeadlessMultiselect", () => {
});
};

const sampleOptions = ["#named", "#named_2", "#named_3", "abc", "def", "ghi"];
const sampleOptions = ["name:named", "name:named_2", "name:named_3", "abc", "def", "ghi"];

const selectors = {
openButton: ".toggle-button",
Expand Down Expand Up @@ -197,27 +197,27 @@ describe("HeadlessMultiselect", () => {
const input = await open(wrapper);

await keyPress(input, "Enter");
expect(wrapper.emitted()["input"]?.[0]?.[0]).toEqual(["#named"]);
expect(wrapper.emitted()["input"]?.[0]?.[0]).toEqual(["name:named"]);

await keyPress(input, "ArrowDown");
await keyPress(input, "Enter");
expect(wrapper.emitted()["input"]?.[1]?.[0]).toEqual(["#named_2"]);
expect(wrapper.emitted()["input"]?.[1]?.[0]).toEqual(["name:named_2"]);
});

it("deselects options via keyboard", async () => {
const wrapper = mountWithProps({
options: sampleOptions,
selected: ["#named", "#named_2", "#named_3"],
selected: ["name:named", "name:named_2", "name:named_3"],
});

const input = await open(wrapper);

await keyPress(input, "Enter");
expect(wrapper.emitted()["input"]?.[0]?.[0]).toEqual(["#named_2", "#named_3"]);
expect(wrapper.emitted()["input"]?.[0]?.[0]).toEqual(["name:named_2", "name:named_3"]);

await keyPress(input, "ArrowDown");
await keyPress(input, "Enter");
expect(wrapper.emitted()["input"]?.[1]?.[0]).toEqual(["#named", "#named_3"]);
expect(wrapper.emitted()["input"]?.[1]?.[0]).toEqual(["name:named", "name:named_3"]);
});

it("allows for adding new options", async () => {
Expand All @@ -243,26 +243,26 @@ describe("HeadlessMultiselect", () => {
const options = wrapper.findAll(selectors.option);

await options.at(0).trigger("click");
expect(wrapper.emitted()["input"]?.[0]?.[0]).toEqual(["#named"]);
expect(wrapper.emitted()["input"]?.[0]?.[0]).toEqual(["name:named"]);

await options.at(1).trigger("click");
expect(wrapper.emitted()["input"]?.[1]?.[0]).toEqual(["#named_2"]);
expect(wrapper.emitted()["input"]?.[1]?.[0]).toEqual(["name:named_2"]);
});

it("deselects options with mouse", async () => {
const wrapper = mountWithProps({
options: sampleOptions,
selected: ["#named", "#named_2", "#named_3"],
selected: ["name:named", "name:named_2", "name:named_3"],
});

await open(wrapper);
const options = wrapper.findAll(selectors.option);

await options.at(0).trigger("click");
expect(wrapper.emitted()["input"]?.[0]?.[0]).toEqual(["#named_2", "#named_3"]);
expect(wrapper.emitted()["input"]?.[0]?.[0]).toEqual(["name:named_2", "name:named_3"]);

await options.at(1).trigger("click");
expect(wrapper.emitted()["input"]?.[1]?.[0]).toEqual(["#named", "#named_3"]);
expect(wrapper.emitted()["input"]?.[1]?.[0]).toEqual(["name:named", "name:named_3"]);
});
});
});
12 changes: 9 additions & 3 deletions client/src/components/TagsMultiselect/StatelessTags.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { useToast } from "composables/toast";
import { getLocalVue } from "tests/jest/helpers";
import { computed } from "vue";

import { useUserTagsStore } from "@/stores/userTagsStore";
import { normalizeTag, useUserTagsStore } from "@/stores/userTagsStore";

import StatelessTags from "./StatelessTags";

const autocompleteTags = ["#named_user_tag", "abc", "my_tag"];
const autocompleteTags = ["name:named_user_tag", "abc", "my_tag"];
const toggleButton = ".toggle-button";

const localVue = getLocalVue();
Expand All @@ -28,6 +28,12 @@ useUserTagsStore.mockReturnValue({
onMultipleNewTagsSeen: jest.fn(),
});

function normalize(tag) {
return tag.replace(/^#/, "name:");
}

normalizeTag.mockImplementation(normalize);

jest.mock("composables/toast");
const warningMock = jest.fn((message, title) => {
return { message, title };
Expand Down Expand Up @@ -88,7 +94,7 @@ describe("StatelessTags", () => {
expect(visibleOptions.length).toBe(autocompleteTags.length);

visibleOptions.wrappers.forEach((option, i) => {
expect(option.text()).toContain(autocompleteTags[i]);
expect(normalize(option.text())).toContain(autocompleteTags[i]);
});
});

Expand Down

0 comments on commit da7349a

Please sign in to comment.