From 1bf6ecd75ed7e652f9f50705517e8a618b4c679b 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 | 62 ++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/src/studio-home/StudioHome.test.jsx b/src/studio-home/StudioHome.test.jsx index ad02f4373f..e461f2720b 100644 --- a/src/studio-home/StudioHome.test.jsx +++ b/src/studio-home/StudioHome.test.jsx @@ -1,6 +1,6 @@ import React from 'react'; import { useSelector } from 'react-redux'; -import { initializeMockApp } from '@edx/frontend-platform'; +import { initializeMockApp, getConfig } from '@edx/frontend-platform'; import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; import { IntlProvider, injectIntl } from '@edx/frontend-platform/i18n'; import { AppProvider } from '@edx/frontend-platform/react'; @@ -41,6 +41,11 @@ jest.mock('react-router-dom', () => ({ }), })); +jest.mock('@edx/frontend-platform', () => ({ + ...jest.requireActual('@edx/frontend-platform'), + getConfig: jest.fn(), +})); + const RootWrapper = () => ( @@ -52,6 +57,9 @@ const RootWrapper = () => ( describe('', async () => { describe('api fetch fails', () => { beforeEach(async () => { + getConfig.mockImplementation(() => ({ + ...jest.requireActual('@edx/frontend-platform').getConfig(), + })); initializeMockApp({ authenticatedUser: { userId: 3, @@ -80,6 +88,9 @@ describe('', async () => { describe('api fetch succeeds', () => { beforeEach(async () => { + getConfig.mockImplementation(() => ({ + ...jest.requireActual('@edx/frontend-platform').getConfig(), + })); initializeMockApp({ authenticatedUser: { userId: 3, @@ -95,6 +106,10 @@ describe('', async () => { useSelector.mockReturnValue(studioHomeMock); }); + afterEach(() => { + jest.restoreAllMocks(); + }); + it('should render page and page title correctly', () => { const { getByText } = render(); expect(getByText(`${studioShortName} home`)).toBeInTheDocument(); @@ -258,5 +273,50 @@ describe('', async () => { expect(getByText('Looking for help with Studio?')).toBeInTheDocument(); expect(getByText('LMS')).toHaveAttribute('href', process.env.LMS_BASE_URL); }); + + it('should dispatch updateSavingStatuses and fetchStudioHomeData when courseCreatorSavingStatus is SUCCESSFUL', () => { + useSelector.mockReturnValue({ + courseCreatorSavingStatus: RequestStatus.SUCCESSFUL, + }); + const { getByText } = render(); + expect(getByText(`${studioShortName} home`)).toBeInTheDocument(); + }); + }); +}); + +describe('Enable pagination', () => { + beforeEach(async () => { + getConfig.mockImplementation(() => ({ + ...jest.requireActual('@edx/frontend-platform').getConfig(), + ENABLE_HOME_PAGE_COURSE_API_V2: true, + })); + 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', + }, + }); + }); + + afterEach(() => { + jest.restoreAllMocks(); + }); + + 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(); }); });