From 1039d109b3e0878469d63303dcff3502a1833b85 Mon Sep 17 00:00:00 2001 From: Pooja Kulkarni Date: Tue, 10 Sep 2024 13:22:39 -0400 Subject: [PATCH 1/2] fix: Alternative fix for default filter --- src/studio-home/hooks.jsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/studio-home/hooks.jsx b/src/studio-home/hooks.jsx index e596e18be0..bb2a716395 100644 --- a/src/studio-home/hooks.jsx +++ b/src/studio-home/hooks.jsx @@ -33,7 +33,7 @@ const useStudioHome = (isPaginated = false) => { useEffect(() => { if (!isPaginated) { - dispatch(fetchStudioHomeData(location.search ?? '')); + dispatch(fetchStudioHomeData(location.search ?? '', false, { active_only: true })); setShowNewCourseContainer(false); } }, [location.search]); @@ -41,21 +41,21 @@ const useStudioHome = (isPaginated = false) => { useEffect(() => { if (isPaginated) { const firstPage = 1; - dispatch(fetchStudioHomeData(location.search ?? '', false, { page: firstPage }, true)); + dispatch(fetchStudioHomeData(location.search ?? '', false, { page: firstPage, active_only: true }, true)); } }, []); useEffect(() => { if (courseCreatorSavingStatus === RequestStatus.SUCCESSFUL) { dispatch(updateSavingStatuses({ courseCreatorSavingStatus: '' })); - dispatch(fetchStudioHomeData()); + dispatch(fetchStudioHomeData('', false, { active_only: true })); } }, [courseCreatorSavingStatus]); useEffect(() => { if (deleteNotificationSavingStatus === RequestStatus.SUCCESSFUL) { dispatch(updateSavingStatuses({ courseCreatorSavingStatus: '' })); - dispatch(fetchStudioHomeData()); + dispatch(fetchStudioHomeData('', false, { active_only: true })); } else if (deleteNotificationSavingStatus === RequestStatus.FAILED) { dispatch(updateSavingStatuses({ deleteNotificationSavingStatus: '' })); } From e3f7bef245c512fd0fca54238c9f0b3dde33ccb8 Mon Sep 17 00:00:00 2001 From: Pooja Kulkarni Date: Fri, 13 Sep 2024 10:05:54 -0400 Subject: [PATCH 2/2] fix: update tests --- src/studio-home/StudioHome.test.jsx | 70 ++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/src/studio-home/StudioHome.test.jsx b/src/studio-home/StudioHome.test.jsx index ad02f4373f..f0a4ec8b83 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,58 @@ 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(); + }); + + it('should dispatch updateSavingStatuses and fetchStudioHomeData when deleteNotificationSavingStatus is SUCCESSFUL', () => { + useSelector.mockReturnValue({ + deleteNotificationSavingStatus: 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(); }); });