1
1
import {
2
- act , fireEvent , initializeMocks , render , screen , within ,
2
+ act , fireEvent , initializeMocks , render , screen , waitFor , within ,
3
3
} from '@src/testUtils' ;
4
4
import { XBlock } from '@src/data/types' ;
5
5
import SectionCard from './SectionCard' ;
6
6
7
- const mockPathname = '/foo-bar' ;
7
+ const mockUseAcceptLibraryBlockChanges = jest . fn ( ) ;
8
+ const mockUseIgnoreLibraryBlockChanges = jest . fn ( ) ;
8
9
9
- jest . mock ( 'react-router-dom' , ( ) => ( {
10
- ...jest . requireActual ( 'react-router-dom' ) ,
11
- useLocation : ( ) => ( {
12
- pathname : mockPathname ,
10
+ jest . mock ( '@src/course-unit/data/apiHooks' , ( ) => ( {
11
+ useAcceptLibraryBlockChanges : ( ) => ( {
12
+ mutateAsync : mockUseAcceptLibraryBlockChanges ,
13
+ } ) ,
14
+ useIgnoreLibraryBlockChanges : ( ) => ( {
15
+ mutateAsync : mockUseIgnoreLibraryBlockChanges ,
13
16
} ) ,
14
17
} ) ) ;
15
18
@@ -74,7 +77,7 @@ const section = {
74
77
75
78
const onEditSectionSubmit = jest . fn ( ) ;
76
79
77
- const renderComponent = ( props ?: object , entry = '/' ) => render (
80
+ const renderComponent = ( props ?: object , entry = '/course/:courseId ' ) => render (
78
81
< SectionCard
79
82
section = { section }
80
83
index = { 1 }
@@ -98,7 +101,8 @@ const renderComponent = (props?: object, entry = '/') => render(
98
101
< span > children</ span >
99
102
</ SectionCard > ,
100
103
{
101
- path : '/' ,
104
+ path : '/course/:courseId' ,
105
+ params : { courseId : '5' } ,
102
106
routerProps : {
103
107
initialEntries : [ entry ] ,
104
108
} ,
@@ -182,7 +186,7 @@ describe('<SectionCard />', () => {
182
186
const collapsedSections = { ...section } ;
183
187
// @ts -ignore-next-line
184
188
collapsedSections . isSectionsExpanded = false ;
185
- renderComponent ( collapsedSections , `?show=${ subsection . id } ` ) ;
189
+ renderComponent ( collapsedSections , `/course/:courseId ?show=${ subsection . id } ` ) ;
186
190
187
191
const cardSubsections = await screen . findByTestId ( 'section-card__subsections' ) ;
188
192
const newSubsectionButton = await screen . findByRole ( 'button' , { name : 'New subsection' } ) ;
@@ -194,7 +198,7 @@ describe('<SectionCard />', () => {
194
198
const collapsedSections = { ...section } ;
195
199
// @ts -ignore-next-line
196
200
collapsedSections . isSectionsExpanded = false ;
197
- renderComponent ( collapsedSections , `?show=${ unit . id } ` ) ;
201
+ renderComponent ( collapsedSections , `/course/:courseId ?show=${ unit . id } ` ) ;
198
202
199
203
const cardSubsections = await screen . findByTestId ( 'section-card__subsections' ) ;
200
204
const newSubsectionButton = await screen . findByRole ( 'button' , { name : 'New subsection' } ) ;
@@ -207,11 +211,58 @@ describe('<SectionCard />', () => {
207
211
const collapsedSections = { ...section } ;
208
212
// @ts -ignore-next-line
209
213
collapsedSections . isSectionsExpanded = false ;
210
- renderComponent ( collapsedSections , `?show=${ randomId } ` ) ;
214
+ renderComponent ( collapsedSections , `/course/:courseId ?show=${ randomId } ` ) ;
211
215
212
216
const cardSubsections = screen . queryByTestId ( 'section-card__subsections' ) ;
213
217
const newSubsectionButton = screen . queryByRole ( 'button' , { name : 'New subsection' } ) ;
214
218
expect ( cardSubsections ) . toBeNull ( ) ;
215
219
expect ( newSubsectionButton ) . toBeNull ( ) ;
216
220
} ) ;
221
+
222
+ it ( 'should sync section changes from upstream' , async ( ) => {
223
+ renderComponent ( ) ;
224
+
225
+ expect ( await screen . findByTestId ( 'section-card-header' ) ) . toBeInTheDocument ( ) ;
226
+
227
+ // Click on sync button
228
+ const syncButton = screen . getByRole ( 'button' , { name : / u p d a t e a v a i l a b l e - c l i c k t o s y n c / i } ) ;
229
+ fireEvent . click ( syncButton ) ;
230
+
231
+ // Should open compare preview modal
232
+ expect ( screen . getByRole ( 'heading' , { name : / p r e v i e w c h a n g e s : s e c t i o n n a m e / i } ) ) . toBeInTheDocument ( ) ;
233
+ expect ( screen . getByText ( 'Preview not available' ) ) . toBeInTheDocument ( ) ;
234
+
235
+ // Click on accept changes
236
+ const acceptChangesButton = screen . getByText ( / a c c e p t c h a n g e s / i) ;
237
+ fireEvent . click ( acceptChangesButton ) ;
238
+
239
+ await waitFor ( ( ) => expect ( mockUseAcceptLibraryBlockChanges ) . toHaveBeenCalled ( ) ) ;
240
+ } ) ;
241
+
242
+ it ( 'should decline sync section changes from upstream' , async ( ) => {
243
+ renderComponent ( ) ;
244
+
245
+ expect ( await screen . findByTestId ( 'section-card-header' ) ) . toBeInTheDocument ( ) ;
246
+
247
+ // Click on sync button
248
+ const syncButton = screen . getByRole ( 'button' , { name : / u p d a t e a v a i l a b l e - c l i c k t o s y n c / i } ) ;
249
+ fireEvent . click ( syncButton ) ;
250
+
251
+ // Should open compare preview modal
252
+ expect ( screen . getByRole ( 'heading' , { name : / p r e v i e w c h a n g e s : s e c t i o n n a m e / i } ) ) . toBeInTheDocument ( ) ;
253
+ expect ( screen . getByText ( 'Preview not available' ) ) . toBeInTheDocument ( ) ;
254
+
255
+ // Click on ignore changes
256
+ const ignoreChangesButton = screen . getByRole ( 'button' , { name : / i g n o r e c h a n g e s / i } ) ;
257
+ fireEvent . click ( ignoreChangesButton ) ;
258
+
259
+ // Should open the confirmation modal
260
+ expect ( screen . getByRole ( 'heading' , { name : / i g n o r e t h e s e c h a n g e s \? / i } ) ) . toBeInTheDocument ( ) ;
261
+
262
+ // Click on ignore button
263
+ const ignoreButton = screen . getByRole ( 'button' , { name : / i g n o r e / i } ) ;
264
+ fireEvent . click ( ignoreButton ) ;
265
+
266
+ await waitFor ( ( ) => expect ( mockUseIgnoreLibraryBlockChanges ) . toHaveBeenCalled ( ) ) ;
267
+ } ) ;
217
268
} ) ;
0 commit comments