Skip to content

Commit

Permalink
fix: Set active courses as default in studio home
Browse files Browse the repository at this point in the history
  • Loading branch information
pkulkark committed Sep 17, 2024
1 parent 82a3b7c commit 85d498d
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 13 deletions.
46 changes: 46 additions & 0 deletions src/studio-home/StudioHome.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => (
Expand Down Expand Up @@ -72,6 +77,9 @@ const RootWrapper = () => (
describe('<StudioHome />', () => {
describe('api fetch fails', () => {
beforeEach(async () => {
getConfig.mockImplementation(() => ({
...jest.requireActual('@edx/frontend-platform').getConfig(),
}));
initializeMockApp({
authenticatedUser: {
userId: 3,
Expand Down Expand Up @@ -100,6 +108,9 @@ describe('<StudioHome />', () => {

describe('api fetch succeeds', () => {
beforeEach(async () => {
getConfig.mockImplementation(() => ({
...jest.requireActual('@edx/frontend-platform').getConfig(),
}));
initializeMockApp({
authenticatedUser: {
userId: 3,
Expand Down Expand Up @@ -332,5 +343,40 @@ describe('<StudioHome />', () => {
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(<RootWrapper />);
expect(getByText(`${studioShortName} home`)).toBeInTheDocument();
});
});
});
});
2 changes: 1 addition & 1 deletion src/studio-home/data/slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const slice = createSlice({
search: undefined,
order: 'display_name',
archivedOnly: undefined,
activeOnly: undefined,
activeOnly: true,
isFiltered: false,
cleanFilters: false,
},
Expand Down
2 changes: 1 addition & 1 deletion src/studio-home/data/slice.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('updateStudioHomeCoursesCustomParams action', () => {
search: undefined,
order: 'display_name',
archivedOnly: undefined,
activeOnly: undefined,
activeOnly: true,
isFiltered: false,
cleanFilters: false,
},
Expand Down
8 changes: 4 additions & 4 deletions src/studio-home/hooks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,29 @@ const useStudioHome = (isPaginated = false) => {

useEffect(() => {
if (!isPaginated) {
dispatch(fetchStudioHomeData(location.search ?? ''));
dispatch(fetchStudioHomeData(location.search ?? '', false, { active_only: true }));
setShowNewCourseContainer(false);
}
}, [location.search]);

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 }));

Check warning on line 51 in src/studio-home/hooks.jsx

View check run for this annotation

Codecov / codecov/patch

src/studio-home/hooks.jsx#L51

Added line #L51 was not covered by tests
}
}, [courseCreatorSavingStatus]);

useEffect(() => {
if (deleteNotificationSavingStatus === RequestStatus.SUCCESSFUL) {
dispatch(updateSavingStatuses({ courseCreatorSavingStatus: '' }));
dispatch(fetchStudioHomeData());
dispatch(fetchStudioHomeData('', false, { active_only: true }));

Check warning on line 58 in src/studio-home/hooks.jsx

View check run for this annotation

Codecov / codecov/patch

src/studio-home/hooks.jsx#L58

Added line #L58 was not covered by tests
} else if (deleteNotificationSavingStatus === RequestStatus.FAILED) {
dispatch(updateSavingStatuses({ deleteNotificationSavingStatus: '' }));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ exports[`CoursesFilters snapshot 1`] = `
id="dropdown-toggle-course-type-menu"
type="button"
>
All courses
Active
</button>
</div>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exports[`CoursesTypesFilterMenu snapshot 1`] = `
id="dropdown-toggle-course-type-menu"
type="button"
>
All courses
Active
</button>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down

0 comments on commit 85d498d

Please sign in to comment.