Skip to content

Commit

Permalink
Rework some of the multi-select components tests
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklafrance committed Oct 11, 2019
1 parent 5fce2f9 commit 1b231e9
Showing 1 changed file with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,47 +83,47 @@ test("open the dropdown menu on enter keydown", async () => {
test("close the dropdown menu on esc keydown", async () => {
const { getByTestId, container } = render(createMultiSelect());

const menuNode = await openDropdownMenu(getByTestId, container);
await openDropdownMenu(getByTestId, container);

fireEvent.keyDown(document, { key: "Escape", keyCode: 27 });
await wait();

expect(menuNode).not.toBeInTheDocument();
expect(getDropdownMenu(container)).not.toBeInTheDocument();
});

test("close the dropdown menu on outside click", async () => {
const { getByTestId, container } = render(createMultiSelect());

const menuNode = await openDropdownMenu(getByTestId, container);
await openDropdownMenu(getByTestId, container);

userEvent.click(document.body);
await wait();

expect(menuNode).not.toBeInTheDocument();
expect(getDropdownMenu(container)).not.toBeInTheDocument();
});

test("close the dropdown menu on focusout", async () => {
const { getByTestId, container } = render(createMultiSelect({
defaultValues: [GROUP_CREATED_VALUE]
}));

const menuNode = await openDropdownMenu(getByTestId, container);
await openDropdownMenu(getByTestId, container);

fireEvent.focusOut(getByTestId(SEARCH_INPUT_ID));
await wait();

expect(menuNode).not.toBeInTheDocument();
expect(getDropdownMenu(container)).not.toBeInTheDocument();
});

test("close the dropdown menu on trigger click", async () => {
const { getByTestId, container } = render(createMultiSelect());

const menuNode = await openDropdownMenu(getByTestId, container);
await openDropdownMenu(getByTestId, container);

userEvent.click(getByTestId(TRIGGER_ID));
await wait();

expect(menuNode).not.toBeInTheDocument();
expect(getDropdownMenu(container)).not.toBeInTheDocument();
});

test("when disabled, dont open the dropdown menu on trigger click", async () => {
Expand Down Expand Up @@ -167,64 +167,64 @@ test("dont close the dropdown menu on search input click", async () => {
orbitId: "I AM 1"
}));

const menuNode = await openDropdownMenu(getByTestId, container);
await openDropdownMenu(getByTestId, container);

userEvent.click(getByTestId(SEARCH_INPUT_ID));
await wait();

expect(menuNode).toBeInTheDocument();
expect(getDropdownMenu(container)).toBeInTheDocument();
});

test("when closeOnSelect is false, dont close the dropdown menu on item click", async () => {
const { getByTestId, getAllByTestId, container } = render(createMultiSelect({
orbitId: "I AM 2"
}));

const menuNode = await openDropdownMenu(getByTestId, container);
await openDropdownMenu(getByTestId, container);

userEvent.click(getAllByTestId(MENU_ITEM_ID)[0]);
await wait();

expect(menuNode).toBeInTheDocument();
expect(getDropdownMenu(container)).toBeInTheDocument();
});

test("when closeOnSelect is false, dont close the dropdown menu on item enter keydown", async () => {
const { getByTestId, container } = render(createMultiSelect());

const menuNode = await openDropdownMenu(getByTestId, container);
await openDropdownMenu(getByTestId, container);

fireEvent.keyDown(document, { key: "ArrowDown", keyCode: 40 });
fireEvent.keyDown(document, { key: "Enter", keyCode: 13 });
await wait();

expect(menuNode).toBeInTheDocument();
expect(getDropdownMenu(container)).toBeInTheDocument();
});

test("when closeOnSelect is true, close the dropdown menu on item click", async () => {
const { getByTestId, getAllByTestId, container } = render(createMultiSelect({
closeOnSelect: true
}));

const menuNode = await openDropdownMenu(getByTestId, container);
await openDropdownMenu(getByTestId, container);

userEvent.click(getAllByTestId(MENU_ITEM_ID)[0]);
await wait();

expect(menuNode).not.toBeInTheDocument();
expect(getDropdownMenu(container)).not.toBeInTheDocument();
});

test("when closeOnSelect is true, close the dropdown menu on item enter keydown", async () => {
const { getByTestId, container } = render(createMultiSelect({
closeOnSelect: true
}));

const menuNode = await openDropdownMenu(getByTestId, container);
await openDropdownMenu(getByTestId, container);

fireEvent.keyDown(document, { key: "ArrowDown", keyCode: 40 });
fireEvent.keyDown(document, { key: "Enter", keyCode: 13 });
await wait();

expect(menuNode).not.toBeInTheDocument();
expect(getDropdownMenu(container)).not.toBeInTheDocument();
});

test("without a search input, all the dropdown menu items are displayed", async () => {
Expand Down Expand Up @@ -371,12 +371,12 @@ test("when closeOnBlur is false, dont close the dropdown menu on blur", async ()
closeOnBlur: false
}));

const menuNode = await openDropdownMenu(getByTestId, container);
await openDropdownMenu(getByTestId, container);

userEvent.click(document.body);
await wait();

expect(menuNode).toBeInTheDocument();
expect(getDropdownMenu(container)).toBeInTheDocument();
});

test("when closeOnBlur is false and closeOnOutsideClick is true, close the dropdown menu on outside click", async () => {
Expand All @@ -385,12 +385,12 @@ test("when closeOnBlur is false and closeOnOutsideClick is true, close the dropd
closeOnOutsideClick: true
}));

const menuNode = await openDropdownMenu(getByTestId, container);
await openDropdownMenu(getByTestId, container);

userEvent.click(document.body);
await wait();

expect(menuNode).not.toBeInTheDocument();
expect(getDropdownMenu(container)).not.toBeInTheDocument();
});

// ***** Handlers *****
Expand Down

0 comments on commit 1b231e9

Please sign in to comment.