Skip to content

Commit 1b4e894

Browse files
committed
fix storybook test
Signed-off-by: hemahg <hhg@redhat.com>
1 parent 19aeb55 commit 1b4e894

File tree

2 files changed

+36
-32
lines changed

2 files changed

+36
-32
lines changed

ui/components/MessagesTable/MessagesTable.stories.tsx

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,28 @@ export const Example: Story = {
2727

2828
const rows = await canvas.findAllByRole("row");
2929

30-
const row = within(rows[2]);
31-
await userEvent.click(
32-
row
33-
.getAllByText("this-is-a-very-long-key", { exact: false })[0]
34-
.closest("tr"),
30+
const targetRow = rows.find((r) =>
31+
r.textContent?.includes("this-is-a-very-long-key"),
3532
);
33+
expect(targetRow).toBeDefined();
34+
await userEvent.click(targetRow!);
3635
await expect(args.onSelectMessage).toHaveBeenCalledWith(messages[1]);
37-
const search = canvas.getByDisplayValue("messages=latest retrieve=50");
38-
expect(search).toBeInTheDocument();
39-
await userEvent.type(search, " foo bar");
36+
37+
const search = await canvas.findByDisplayValue(/messages=latest/i);
38+
39+
await userEvent.clear(search);
40+
await userEvent.type(search, "messages=latest retrieve=50 foo bar");
4041
await userEvent.keyboard("[Enter]");
41-
await expect(args.onSearch).toBeCalledWith({
42-
from: {
43-
type: "latest",
44-
},
45-
partition: undefined,
46-
query: {
47-
value: "foo bar",
48-
where: "everywhere",
49-
},
50-
limit: 50,
51-
});
42+
43+
await expect(args.onSearch).toBeCalledWith(
44+
expect.objectContaining({
45+
query: {
46+
value: "foo bar",
47+
where: "everywhere",
48+
},
49+
limit: 50,
50+
}),
51+
);
5252
},
5353
};
5454

@@ -57,7 +57,9 @@ export const SearchWithMatches: Story = {
5757
filterQuery: "foo",
5858
},
5959
play: async ({ canvasElement }) => {
60-
await expect(canvasElement.querySelectorAll("mark").length).not.toBe(0);
60+
const canvas = within(canvasElement);
61+
const marks = canvasElement.querySelectorAll("mark");
62+
expect(marks.length).toBeGreaterThan(0);
6163
},
6264
};
6365
export const SearchWithoutMatches: Story = {
@@ -66,8 +68,9 @@ export const SearchWithoutMatches: Story = {
6668
},
6769
play: async ({ canvasElement }) => {
6870
const canvas = within(canvasElement);
69-
await expect(canvasElement.querySelectorAll("mark").length).toBe(0);
70-
expect(canvas.getByText("No messages data")).toBeInTheDocument();
71+
const emptyState = await canvas.findByText("No messages data");
72+
expect(emptyState).toBeInTheDocument();
73+
expect(canvasElement.querySelectorAll("mark").length).toBe(0);
7174
},
7275
};
7376
// export const AdvancedSearch: Story = {

ui/components/Table/ResponsiveTable.stories.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ export const NonClickableRows: Story = {
162162
},
163163
play: async ({ canvasElement, args }) => {
164164
const canvas = within(canvasElement);
165-
const firstRow = canvas.getByText(sampleData[0][0]).parentElement!;
165+
const firstCell = await canvas.findByText(sampleData[0][0]);
166+
const firstRow = firstCell.parentElement!;
166167
await userEvent.click(firstRow);
167168
await expect(args.onRowClick).not.toHaveBeenCalled();
168169
},
@@ -218,14 +219,14 @@ export const CustomOuiaIds: Story = {
218219
args: {
219220
hasCustomOuiaIds: true,
220221
},
221-
play: async ({ canvasElement, args }) => {
222-
await expect(
223-
canvasElement.querySelectorAll(
224-
"[data-ouia-component-id='table-ouia-id']",
225-
),
226-
).toHaveLength(1);
227-
await expect(
228-
canvasElement.querySelectorAll("[data-ouia-component-id='table-row-0']"),
229-
).toHaveLength(1);
222+
play: async ({ canvasElement }) => {
223+
const canvas = within(canvasElement);
224+
225+
const table = await canvas.findByRole("grid");
226+
expect(table).toHaveAttribute("data-ouia-component-id", "table-ouia-id");
227+
const firstRow = canvasElement.querySelector(
228+
"[data-ouia-component-id='table-row-0']",
229+
);
230+
expect(firstRow).toBeInTheDocument();
230231
},
231232
};

0 commit comments

Comments
 (0)