1
1
import React from 'react' ;
2
2
import { initializeMockApp } from '@edx/frontend-platform' ;
3
- import { render , screen } from '@testing-library/react' ;
3
+ import { fireEvent , render , screen } from '@testing-library/react' ;
4
4
import { IntlProvider } from '@edx/frontend-platform/i18n' ;
5
5
import { AppProvider } from '@edx/frontend-platform/react' ;
6
6
@@ -10,6 +10,7 @@ import { studioHomeMock } from '../../__mocks__';
10
10
import { initialState } from '../../factories/mockApiResponses' ;
11
11
12
12
import CoursesTab from '.' ;
13
+ import { studioHomeCoursesRequestParamsDefault } from '../../data/slice' ;
13
14
14
15
const onClickNewCourse = jest . fn ( ) ;
15
16
const isLoading = false ;
@@ -31,22 +32,25 @@ const renderComponent = (overrideProps = {}, studioHomeState = {}) => {
31
32
// Initialize the store with the custom initial state
32
33
const store = initializeStore ( customInitialState ) ;
33
34
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
+ } ;
50
54
} ;
51
55
52
56
describe ( '<CoursesTab />' , ( ) => {
@@ -98,7 +102,7 @@ describe('<CoursesTab />', () => {
98
102
} ) ;
99
103
100
104
it ( 'should render CollapsibleStateWithAction when courseCreatorStatus is true' , ( ) => {
101
- const props = { isShowProcessing : true , isEnabledPagination : false } ;
105
+ const props = { isEnabledPagination : false } ;
102
106
const customStoreData = {
103
107
studioHomeData : {
104
108
inProcessCourseActions : [ ] ,
@@ -109,4 +113,17 @@ describe('<CoursesTab />', () => {
109
113
const collapsibleStateWithAction = screen . queryByTestId ( 'collapsible-state-with-action' ) ;
110
114
expect ( collapsibleStateWithAction ) . toBeInTheDocument ( ) ;
111
115
} ) ;
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
+ } ) ;
112
129
} ) ;
0 commit comments