From 5a6b2d840179599a1bfd0813ec37eb87d498b6cf Mon Sep 17 00:00:00 2001 From: Pooja Kulkarni Date: Fri, 13 Sep 2024 10:05:54 -0400 Subject: [PATCH] fix: update tests --- src/studio-home/StudioHome.test.jsx | 45 +++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/studio-home/StudioHome.test.jsx b/src/studio-home/StudioHome.test.jsx index ad02f4373f..65ab6862cd 100644 --- a/src/studio-home/StudioHome.test.jsx +++ b/src/studio-home/StudioHome.test.jsx @@ -260,3 +260,48 @@ describe('', async () => { }); }); }); + +describe('Enable pagination', () => { + beforeEach(async () => { + initializeMockApp({ + authenticatedUser: { + userId: 3, + username: 'abc123', + administrator: true, + roles: [], + }, + }); + store = initializeStore(); + axiosMock = new MockAdapter(getAuthenticatedHttpClient()); + global.window = Object.create(window); + Object.defineProperty(window, 'location', { + value: { + search: '?search=test', + }, + }); + }); + + const RootWrapperWithPagination = () => ( + + + + + + ); + + it('should dispatch fetchStudioHomeData with paginated parameters on component mount', async () => { + axiosMock.onGet(getStudioHomeApiUrl()).reply(200, studioHomeMock); + + const { getByText } = render(); + + expect(getByText(`${studioShortName} home`)).toBeInTheDocument(); + }); + + it('should only dispatch fetchStudioHomeData once when pagination is enabled', async () => { + axiosMock.onGet(getStudioHomeApiUrl()).reply(200, studioHomeMock); + + render(); + + expect(axiosMock.history.get.length).toBe(1); + }); +});