Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions packages/lib/src/resultset-table/ResultsetTable.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { act, fireEvent, render } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { fireEvent, render } from "@testing-library/react";
import DxcCheckbox from "../checkbox/Checkbox";
import DxcResultsetTable from "./ResultsetTable";

Expand Down Expand Up @@ -375,12 +374,12 @@ describe("Resultset table component tests", () => {
expect(getByText("Louis")).toBeTruthy();
expect(getByText("Lana")).toBeTruthy();
expect(getAllByRole("row").length - 1).toEqual(3);
const goToPageSelect = getAllByRole("button")[3];
const goToPageSelect = getAllByRole("combobox")[0];
if (goToPageSelect) {
userEvent.click(goToPageSelect);
fireEvent.click(goToPageSelect);
}
const goToPageOption = getByText("2");
userEvent.click(goToPageOption);
fireEvent.click(goToPageOption);
expect(getByText("4 to 6 of 10")).toBeTruthy();
expect(getByText("Rick")).toBeTruthy();
expect(getByText("Mark")).toBeTruthy();
Expand Down Expand Up @@ -551,23 +550,17 @@ describe("Resultset table component tests", () => {
},
],
];
const { getAllByRole, getByRole, getByText } = render(
const { getByRole, getByText, getByTitle } = render(
<DxcResultsetTable columns={columns} rows={actionRows} itemsPerPage={3} />
);
const dropdown = getAllByRole("button")[2];
act(() => {
if (dropdown) {
userEvent.click(dropdown);
}
});
const dropdown = getByTitle("icon1");
fireEvent.click(dropdown);
expect(getByRole("menu")).toBeTruthy();
const option = getByText("Aliexpress");
userEvent.click(option);
fireEvent.click(option);
expect(onSelectOption).toHaveBeenCalledWith("3");
const action = getAllByRole("button")[1];
if (action) {
userEvent.click(action);
}
const action = getByRole("button", { name: "icon2" });
fireEvent.click(action);
expect(onClick).toHaveBeenCalled();
});

Expand Down
18 changes: 8 additions & 10 deletions packages/lib/src/table/Table.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { act, render } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { fireEvent, render } from "@testing-library/react";
import DxcTable from "./Table";

global.ResizeObserver = jest.fn().mockImplementation(() => ({
Expand Down Expand Up @@ -50,7 +49,7 @@ describe("Table component tests", () => {
expect(getByText("cell-6")).toBeTruthy();
});

test("Table ActionsCell", () => {
test("Table ActionsCell", async () => {
const onSelectOption = jest.fn();
const onClick = jest.fn();
const actions = [
Expand Down Expand Up @@ -105,18 +104,17 @@ describe("Table component tests", () => {
);

const dropdown = getAllByRole("button")[1];
act(() => {
if (dropdown) {
userEvent.click(dropdown);
}
});
if (!dropdown) {
throw new Error("Expected the actions dropdown to be rendered");
}
await Promise.resolve(fireEvent.click(dropdown));
expect(getByRole("menu")).toBeTruthy();
const option = getByText("Aliexpress");
userEvent.click(option);
await Promise.resolve(fireEvent.click(option));
expect(onSelectOption).toHaveBeenCalledWith("3");
const action = getAllByRole("button")[0];
if (action) {
userEvent.click(action);
await Promise.resolve(fireEvent.click(action));
}
expect(onClick).toHaveBeenCalled();
});
Expand Down
Loading