diff --git a/packages/suite-base/src/providers/CurrentLayoutProvider/index.test.tsx b/packages/suite-base/src/providers/CurrentLayoutProvider/index.test.tsx index 37b1fc6b11..db378e69b1 100644 --- a/packages/suite-base/src/providers/CurrentLayoutProvider/index.test.tsx +++ b/packages/suite-base/src/providers/CurrentLayoutProvider/index.test.tsx @@ -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")), @@ -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(); + }); });