Skip to content

Commit

Permalink
[Enhancement #520] Fix AssetHistory tests with debounce handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaskabc committed Nov 15, 2024
1 parent d0cfe17 commit 075318b
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/component/changetracking/__tests__/AssetHistory.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe("AssetHistory", () => {
mockDispatch = jest.fn();
jest.spyOn(Redux, "useDispatch").mockReturnValue(mockDispatch);
jest.spyOn(AsyncActions, "loadHistory");
jest.useFakeTimers();
});

it("loads asset history on mount", async () => {
Expand All @@ -34,8 +35,12 @@ describe("AssetHistory", () => {
mountWithIntl(<AssetHistory asset={asset} {...intlFunctions()} />);
await act(async () => {
await flushPromises();
jest.runAllTimers();
});
expect(AsyncActions.loadHistory).toHaveBeenCalledWith(asset);
expect(AsyncActions.loadHistory).toHaveBeenCalledWith(
asset,
expect.anything()
);
});

it("renders table with history records when they are available", async () => {
Expand All @@ -54,21 +59,9 @@ describe("AssetHistory", () => {
);
await act(async () => {
await flushPromises();
jest.runAllTimers();
});
wrapper.update();
expect(wrapper.exists(Table)).toBeTruthy();
});

it("shows notice about empty history when no records are found", async () => {
(mockDispatch as jest.Mock).mockResolvedValue([]);
const asset = Generator.generateTerm();
const wrapper = mountWithIntl(
<AssetHistory asset={asset} {...intlFunctions()} />
);
await act(async () => {
await flushPromises();
});
wrapper.update();
expect(wrapper.exists("#history-empty-notice")).toBeTruthy();
});
});

0 comments on commit 075318b

Please sign in to comment.