Skip to content

Commit c6b6c64

Browse files
committed
test: filter reset functionality in CoursesTab component
1 parent 5cddae4 commit c6b6c64

File tree

3 files changed

+38
-21
lines changed

3 files changed

+38
-21
lines changed

src/studio-home/data/slice.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createSlice } from '@reduxjs/toolkit';
33

44
import { RequestStatus } from '../../data/constants';
55

6-
const studioHomeCoursesRequestParamsDefault = {
6+
export const studioHomeCoursesRequestParamsDefault = {
77
currentPage: 1,
88
search: '',
99
order: 'display_name',

src/studio-home/tabs-section/courses-tab/index.test.tsx

+35-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { initializeMockApp } from '@edx/frontend-platform';
3-
import { render, screen } from '@testing-library/react';
3+
import { fireEvent, render, screen } from '@testing-library/react';
44
import { IntlProvider } from '@edx/frontend-platform/i18n';
55
import { AppProvider } from '@edx/frontend-platform/react';
66

@@ -10,6 +10,7 @@ import { studioHomeMock } from '../../__mocks__';
1010
import { initialState } from '../../factories/mockApiResponses';
1111

1212
import CoursesTab from '.';
13+
import { studioHomeCoursesRequestParamsDefault } from '../../data/slice';
1314

1415
const onClickNewCourse = jest.fn();
1516
const isLoading = false;
@@ -31,22 +32,25 @@ const renderComponent = (overrideProps = {}, studioHomeState = {}) => {
3132
// Initialize the store with the custom initial state
3233
const store = initializeStore(customInitialState);
3334

34-
return render(
35-
<AppProvider store={store}>
36-
<IntlProvider locale="en" messages={{}}>
37-
<CoursesTab
38-
coursesDataItems={studioHomeMock.courses}
39-
showNewCourseContainer={showNewCourseContainer}
40-
onClickNewCourse={onClickNewCourse}
41-
isLoading={isLoading}
42-
isFailed={isFailed}
43-
numPages={numPages}
44-
coursesCount={coursesCount}
45-
{...overrideProps}
46-
/>
47-
</IntlProvider>
48-
</AppProvider>,
49-
);
35+
return {
36+
...render(
37+
<AppProvider store={store}>
38+
<IntlProvider locale="en" messages={{}}>
39+
<CoursesTab
40+
coursesDataItems={studioHomeMock.courses}
41+
showNewCourseContainer={showNewCourseContainer}
42+
onClickNewCourse={onClickNewCourse}
43+
isLoading={isLoading}
44+
isFailed={isFailed}
45+
numPages={numPages}
46+
coursesCount={coursesCount}
47+
{...overrideProps}
48+
/>
49+
</IntlProvider>
50+
</AppProvider>,
51+
),
52+
store,
53+
};
5054
};
5155

5256
describe('<CoursesTab />', () => {
@@ -98,7 +102,7 @@ describe('<CoursesTab />', () => {
98102
});
99103

100104
it('should render CollapsibleStateWithAction when courseCreatorStatus is true', () => {
101-
const props = { isShowProcessing: true, isEnabledPagination: false };
105+
const props = { isEnabledPagination: false };
102106
const customStoreData = {
103107
studioHomeData: {
104108
inProcessCourseActions: [],
@@ -109,4 +113,17 @@ describe('<CoursesTab />', () => {
109113
const collapsibleStateWithAction = screen.queryByTestId('collapsible-state-with-action');
110114
expect(collapsibleStateWithAction).toBeInTheDocument();
111115
});
116+
117+
it('should reset filters when in pressed the button to clean them', () => {
118+
const props = { isLoading: false, coursesDataItems: [] };
119+
const customStoreData = { studioHomeCoursesRequestParams: { isFiltered: true } };
120+
const { store } = renderComponent(props, customStoreData);
121+
const cleanFiltersButton = screen.queryByTestId('clean-filters');
122+
expect(cleanFiltersButton).toBeInTheDocument();
123+
124+
fireEvent.click(cleanFiltersButton!);
125+
126+
const state = store.getState();
127+
expect(state.studioHome.studioHomeCoursesRequestParams).toStrictEqual(studioHomeCoursesRequestParamsDefault);
128+
});
112129
});

src/studio-home/tabs-section/courses-tab/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const CoursesTab: React.FC<Props> = ({
8989
};
9090

9191
const handleCleanFilters = () => {
92-
dispatch(resetStudioHomeCoursesCustomParams);
92+
dispatch(resetStudioHomeCoursesCustomParams());
9393
dispatch(fetchStudioHomeData(locationValue, false, { page: 1, order: 'display_name' }));
9494
};
9595

@@ -180,7 +180,7 @@ const CoursesTab: React.FC<Props> = ({
180180
<p data-testid="courses-not-found-alert">
181181
{intl.formatMessage(messages.coursesTabCourseNotFoundAlertMessage)}
182182
</p>
183-
<Button variant="primary" onClick={handleCleanFilters}>
183+
<Button data-testid="clean-filters" variant="primary" onClick={handleCleanFilters}>
184184
{intl.formatMessage(messages.coursesTabCourseNotFoundAlertCleanFiltersButton)}
185185
</Button>
186186
</Alert>

0 commit comments

Comments
 (0)