Skip to content

Commit 77f5790

Browse files
committed
tidy
1 parent f4552e4 commit 77f5790

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

ui/src/pages/Newsfeed/__tests__/Newsfeed.test.tsx

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ vi.mock("components/ComponentInjector", () => ({
2222
},
2323
}));
2424

25+
const mockSetTab = vi.fn();
26+
27+
// Mock the useNewsFeed hook
28+
vi.mock("./useNewsFeed", () => ({
29+
data: [], // Assume empty data for simplicity
30+
isLoading: false,
31+
isError: false,
32+
setTab: mockSetTab,
33+
}));
34+
2535
const user = userEvent.setup();
2636

2737
describe("News component", () => {
@@ -77,18 +87,16 @@ describe("News component", () => {
7787
});
7888
});
7989

80-
it("calls the SetTabValue function with the correct argument when a tab is changed", async () => {
81-
// Iterate over each tab item defined in TAB_ITEMS
82-
TAB_ITEMS.forEach(async (tabItem, index) => {
83-
// Simulate clicking on the tab
84-
await user.click(tabs[index]);
90+
it("calls setTab with the new tab value on tab change", async () => {
91+
// This example simulates clicking the second tab
92+
const secondTab = TAB_ITEMS[1];
93+
await user.click(
94+
screen.getByRole("tab", { name: secondTab.label })
95+
);
8596

86-
// Assert that mockSetTab was called with the 'key' of the current tabItem
87-
expect(mockSetTab).toHaveBeenCalledWith(tabItem.key);
88-
89-
// Reset mock function history after each assertion to ensure independence
90-
mockSetTab.mockClear();
91-
});
97+
// Verify setTab was called with the value of the second tab
98+
expect(mockSetTab).toHaveBeenCalledWith(secondTab.key);
99+
mockSetTab.mockClear();
92100
});
93101
});
94102
});

0 commit comments

Comments
 (0)