From 85d498dbf713f7b063425c12f1f6da3cb8e8fe32 Mon Sep 17 00:00:00 2001 From: Pooja Kulkarni Date: Mon, 2 Sep 2024 16:51:16 -0400 Subject: [PATCH] fix: Set active courses as default in studio home --- src/studio-home/StudioHome.test.jsx | 46 +++++++++++++++++++ src/studio-home/data/slice.js | 2 +- src/studio-home/data/slice.test.js | 2 +- src/studio-home/hooks.jsx | 8 ++-- .../__snapshots__/index.test.jsx.snap | 2 +- .../__snapshots__/index.test.jsx.snap | 2 +- .../courses-types-filter-menu/index.jsx | 2 +- .../courses-types-filter-menu/index.test.jsx | 8 ++-- 8 files changed, 59 insertions(+), 13 deletions(-) diff --git a/src/studio-home/StudioHome.test.jsx b/src/studio-home/StudioHome.test.jsx index c130d63195..afd01cd34f 100644 --- a/src/studio-home/StudioHome.test.jsx +++ b/src/studio-home/StudioHome.test.jsx @@ -42,6 +42,11 @@ jest.mock('react-router-dom', () => ({ useNavigate: () => mockNavigate, })); +jest.mock('@edx/frontend-platform', () => ({ + ...jest.requireActual('@edx/frontend-platform'), + getConfig: jest.fn(), +})); + const queryClient = new QueryClient(); const RootWrapper = () => ( @@ -72,6 +77,9 @@ const RootWrapper = () => ( describe('', () => { describe('api fetch fails', () => { beforeEach(async () => { + getConfig.mockImplementation(() => ({ + ...jest.requireActual('@edx/frontend-platform').getConfig(), + })); initializeMockApp({ authenticatedUser: { userId: 3, @@ -100,6 +108,9 @@ describe('', () => { describe('api fetch succeeds', () => { beforeEach(async () => { + getConfig.mockImplementation(() => ({ + ...jest.requireActual('@edx/frontend-platform').getConfig(), + })); initializeMockApp({ authenticatedUser: { userId: 3, @@ -332,5 +343,40 @@ describe('', () => { expect(getByText('Looking for help with Studio?')).toBeInTheDocument(); expect(getByText('LMS')).toHaveAttribute('href', process.env.LMS_BASE_URL); }); + + 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(); + }); + }); }); }); diff --git a/src/studio-home/data/slice.js b/src/studio-home/data/slice.js index 89ee211c0f..8bb5aaae15 100644 --- a/src/studio-home/data/slice.js +++ b/src/studio-home/data/slice.js @@ -22,7 +22,7 @@ const slice = createSlice({ search: undefined, order: 'display_name', archivedOnly: undefined, - activeOnly: undefined, + activeOnly: true, isFiltered: false, cleanFilters: false, }, diff --git a/src/studio-home/data/slice.test.js b/src/studio-home/data/slice.test.js index 7340e56793..a788dadcaf 100644 --- a/src/studio-home/data/slice.test.js +++ b/src/studio-home/data/slice.test.js @@ -20,7 +20,7 @@ describe('updateStudioHomeCoursesCustomParams action', () => { search: undefined, order: 'display_name', archivedOnly: undefined, - activeOnly: undefined, + activeOnly: true, isFiltered: false, cleanFilters: false, }, 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: '' })); } diff --git a/src/studio-home/tabs-section/courses-tab/courses-filters/__snapshots__/index.test.jsx.snap b/src/studio-home/tabs-section/courses-tab/courses-filters/__snapshots__/index.test.jsx.snap index a98777a5ed..7e095ba8e2 100644 --- a/src/studio-home/tabs-section/courses-tab/courses-filters/__snapshots__/index.test.jsx.snap +++ b/src/studio-home/tabs-section/courses-tab/courses-filters/__snapshots__/index.test.jsx.snap @@ -81,7 +81,7 @@ exports[`CoursesFilters snapshot 1`] = ` id="dropdown-toggle-course-type-menu" type="button" > - All courses + Active diff --git a/src/studio-home/tabs-section/courses-tab/courses-filters/courses-types-filter-menu/index.jsx b/src/studio-home/tabs-section/courses-tab/courses-filters/courses-types-filter-menu/index.jsx index 70189e8fed..f668a577b4 100644 --- a/src/studio-home/tabs-section/courses-tab/courses-filters/courses-types-filter-menu/index.jsx +++ b/src/studio-home/tabs-section/courses-tab/courses-filters/courses-types-filter-menu/index.jsx @@ -39,7 +39,7 @@ const CoursesTypesFilterMenu = ({ onItemMenuSelected }) => { id="dropdown-toggle-course-type-menu" menuItems={courseTypes} onItemMenuSelected={handleCourseTypeSelected} - defaultItemSelectedText={intl.formatMessage(messages.coursesTypesFilterMenuAllCurses)} + defaultItemSelectedText={intl.formatMessage(messages.coursesTypesFilterMenuActiveCurses)} /> ); }; diff --git a/src/studio-home/tabs-section/courses-tab/courses-filters/courses-types-filter-menu/index.test.jsx b/src/studio-home/tabs-section/courses-tab/courses-filters/courses-types-filter-menu/index.test.jsx index ddd2fd9746..4e07ea3a1f 100644 --- a/src/studio-home/tabs-section/courses-tab/courses-filters/courses-types-filter-menu/index.test.jsx +++ b/src/studio-home/tabs-section/courses-tab/courses-filters/courses-types-filter-menu/index.test.jsx @@ -60,11 +60,11 @@ describe('CoursesTypesFilterMenu', () => { const { defaultMessage: activeCoursesMenuText } = message.coursesTypesFilterMenuActiveCurses; const { defaultMessage: allCoursesMenuText } = message.coursesTypesFilterMenuAllCurses; const { defaultMessage: archiveCoursesMenuText } = message.coursesTypesFilterMenuArchivedCurses; - const activeCoursesMenuItem = screen.getByText(activeCoursesMenuText); - const allCoursesMenuItem = screen.getByTestId('item-menu-all-courses'); + const activeCoursesMenuItem = screen.getByTestId('item-menu-active-courses'); + const allCoursesMenuItem = screen.getByText(allCoursesMenuText); const archiveCoursesMenuItem = screen.getByText(archiveCoursesMenuText); - expect(activeCoursesMenuItem).toBeInTheDocument(); - expect(allCoursesMenuItem.textContent).toContain(allCoursesMenuText); + expect(activeCoursesMenuItem.textContent).toContain(activeCoursesMenuText); + expect(allCoursesMenuItem).toBeInTheDocument(); expect(archiveCoursesMenuItem).toBeInTheDocument(); });