Skip to content

Commit

Permalink
insert unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
aneuwald-ctw committed Oct 15, 2024
1 parent f5c6975 commit 1beebb1
Showing 1 changed file with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function makeMockLayoutManager() {
setError: jest.fn(/*noop*/),
setOnline: jest.fn(/*noop*/),
getLayouts: jest.fn(),
getLayout: jest.fn().mockImplementation(mockThrow("getLayout")),
getLayout: jest.fn(),
saveNewLayout: jest.fn().mockImplementation(mockThrow("saveNewLayout")),
updateLayout: jest.fn().mockImplementation(mockThrow("updateLayout")),
deleteLayout: jest.fn().mockImplementation(mockThrow("deleteLayout")),
Expand Down Expand Up @@ -240,4 +240,43 @@ describe("CurrentLayoutProvider", () => {
expect(result.current.actions.savePanelConfigs).toBe(actions.savePanelConfigs);
(console.warn as jest.Mock).mockClear();
});

it("selects the first layout in alphabetic order, when there is no selected layout", async () => {
const mockLayoutManager = makeMockLayoutManager();
mockLayoutManager.getLayout.mockImplementation(async () => undefined);
mockLayoutManager.getLayouts.mockImplementation(async () => {
return [
{
id: "layout1",
name: "LAYOUT 1",
data: { data: TEST_LAYOUT },
},
{
id: "layout2",
name: "ABC Layout 2",
data: { data: TEST_LAYOUT },
},
];
});

const mockUserProfile = makeMockUserProfile();
mockUserProfile.getUserProfile.mockResolvedValue({ currentLayoutId: undefined });

const { result, all } = renderTest({
mockLayoutManager,
mockUserProfile,
});

await act(async () => {
await result.current.childMounted;
});

const selectedLayout = all.find((item) => item.layoutState.selectedLayout?.id)?.layoutState
.selectedLayout?.id;

expect(selectedLayout).toBeDefined();
expect(selectedLayout).toBe("layout2");

(console.warn as jest.Mock).mockClear();
});
});

0 comments on commit 1beebb1

Please sign in to comment.