@@ -11,7 +11,6 @@ import { cloneDeep } from 'lodash';
11
11
import { closestCorners } from '@dnd-kit/core' ;
12
12
import { logError } from '@edx/frontend-platform/logging' ;
13
13
import { useLocation } from 'react-router-dom' ;
14
- import userEvent from '@testing-library/user-event' ;
15
14
import {
16
15
getCourseBestPracticesApiUrl ,
17
16
getCourseLaunchApiUrl ,
@@ -308,13 +307,15 @@ describe('<CourseOutline />', () => {
308
307
} ) ;
309
308
310
309
it ( 'check that new section list is saved when dragged' , async ( ) => {
311
- const { findAllByRole } = render ( < RootWrapper /> ) ;
312
- const courseBlockId = courseOutlineIndexMock . courseStructure . id ;
310
+ const { findAllByRole, findByTestId } = render ( < RootWrapper /> ) ;
311
+ const expandAllButton = await findByTestId ( 'expand-collapse-all-button' ) ;
312
+ fireEvent . click ( expandAllButton ) ;
313
+ const [ section ] = store . getState ( ) . courseOutline . sectionsList ;
313
314
const sectionsDraggers = await findAllByRole ( 'button' , { name : 'Drag to reorder' } ) ;
314
- const draggableButton = sectionsDraggers [ 6 ] ;
315
+ const draggableButton = sectionsDraggers [ 1 ] ;
315
316
316
317
axiosMock
317
- . onPut ( getCourseBlockApiUrl ( courseBlockId ) )
318
+ . onPut ( getCourseBlockApiUrl ( section . id ) )
318
319
. reply ( 200 , { dummy : 'value' } ) ;
319
320
320
321
const section1 = store . getState ( ) . courseOutline . sectionsList [ 0 ] . id ;
@@ -333,13 +334,15 @@ describe('<CourseOutline />', () => {
333
334
} ) ;
334
335
335
336
it ( 'check section list is restored to original order when API call fails' , async ( ) => {
336
- const { findAllByRole } = render ( < RootWrapper /> ) ;
337
- const courseBlockId = courseOutlineIndexMock . courseStructure . id ;
337
+ const { findAllByRole, findByTestId } = render ( < RootWrapper /> ) ;
338
+ const expandAllButton = await findByTestId ( 'expand-collapse-all-button' ) ;
339
+ fireEvent . click ( expandAllButton ) ;
340
+ const [ section ] = store . getState ( ) . courseOutline . sectionsList ;
338
341
const sectionsDraggers = await findAllByRole ( 'button' , { name : 'Drag to reorder' } ) ;
339
- const draggableButton = sectionsDraggers [ 6 ] ;
342
+ const draggableButton = sectionsDraggers [ 1 ] ;
340
343
341
344
axiosMock
342
- . onPut ( getCourseBlockApiUrl ( courseBlockId ) )
345
+ . onPut ( getCourseBlockApiUrl ( section . id ) )
343
346
. reply ( 500 ) ;
344
347
345
348
const section1 = store . getState ( ) . courseOutline . sectionsList [ 0 ] . id ;
@@ -414,8 +417,6 @@ describe('<CourseOutline />', () => {
414
417
const { findAllByTestId } = render ( < RootWrapper /> ) ;
415
418
const [ sectionElement ] = await findAllByTestId ( 'section-card' ) ;
416
419
const [ subsectionElement ] = await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ;
417
- const expandBtn = await within ( subsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
418
- fireEvent . click ( expandBtn ) ;
419
420
const units = await within ( subsectionElement ) . findAllByTestId ( 'unit-card' ) ;
420
421
expect ( units . length ) . toBe ( 1 ) ;
421
422
@@ -440,8 +441,6 @@ describe('<CourseOutline />', () => {
440
441
render ( < RootWrapper /> ) ;
441
442
const [ sectionElement ] = await screen . findAllByTestId ( 'section-card' ) ;
442
443
const [ subsectionElement ] = await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ;
443
- const expandBtn = await within ( subsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
444
- fireEvent . click ( expandBtn ) ;
445
444
const units = await within ( subsectionElement ) . findAllByTestId ( 'unit-card' ) ;
446
445
expect ( units . length ) . toBe ( 1 ) ;
447
446
@@ -665,8 +664,6 @@ describe('<CourseOutline />', () => {
665
664
await checkEditTitle ( section , subsectionElement , subsection , 'New subsection name' , 'subsection' ) ;
666
665
667
666
// check unit
668
- const expandBtn = await within ( subsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
669
- fireEvent . click ( expandBtn ) ;
670
667
const [ unit ] = subsection . childInfo . children ;
671
668
const [ unitElement ] = await within ( subsectionElement ) . findAllByTestId ( 'unit-card' ) ;
672
669
await checkEditTitle ( section , unitElement , unit , 'New unit name' , 'unit' ) ;
@@ -679,8 +676,6 @@ describe('<CourseOutline />', () => {
679
676
const [ sectionElement ] = await screen . findAllByTestId ( 'section-card' ) ;
680
677
const [ subsection ] = section . childInfo . children ;
681
678
const [ subsectionElement ] = await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ;
682
- const expandBtn = await within ( subsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
683
- fireEvent . click ( expandBtn ) ;
684
679
const [ unit ] = subsection . childInfo . children ;
685
680
const [ unitElement ] = await within ( subsectionElement ) . findAllByTestId ( 'unit-card' ) ;
686
681
@@ -719,8 +714,6 @@ describe('<CourseOutline />', () => {
719
714
const [ sectionElement ] = await findAllByTestId ( 'section-card' ) ;
720
715
const [ subsection ] = section . childInfo . children ;
721
716
const [ subsectionElement ] = await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ;
722
- const expandBtn = await within ( subsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
723
- fireEvent . click ( expandBtn ) ;
724
717
const [ unit ] = subsection . childInfo . children ;
725
718
const [ unitElement ] = await within ( subsectionElement ) . findAllByTestId ( 'unit-card' ) ;
726
719
@@ -790,8 +783,6 @@ describe('<CourseOutline />', () => {
790
783
const [ sectionElement ] = await findAllByTestId ( 'section-card' ) ;
791
784
const [ subsection ] = section . childInfo . children ;
792
785
const [ subsectionElement ] = await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ;
793
- const expandBtn = await within ( subsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
794
- fireEvent . click ( expandBtn ) ;
795
786
const [ unit ] = subsection . childInfo . children ;
796
787
const [ unitElement ] = await within ( subsectionElement ) . findAllByTestId ( 'unit-card' ) ;
797
788
@@ -1500,8 +1491,6 @@ describe('<CourseOutline />', () => {
1500
1491
1501
1492
const [ firstSection ] = await findAllByTestId ( 'section-card' ) ;
1502
1493
const [ firstSubsection ] = await within ( firstSection ) . findAllByTestId ( 'subsection-card' ) ;
1503
- const subsectionExpandButton = await within ( firstSubsection ) . getByTestId ( 'subsection-card-header__expanded-btn' ) ;
1504
- fireEvent . click ( subsectionExpandButton ) ;
1505
1494
const [ firstUnit ] = await within ( firstSubsection ) . findAllByTestId ( 'unit-card' ) ;
1506
1495
const unitDropdownButton = await within ( firstUnit ) . findByTestId ( 'unit-card-header__menu-button' ) ;
1507
1496
@@ -1861,8 +1850,6 @@ describe('<CourseOutline />', () => {
1861
1850
const [ , sectionElement ] = await findAllByTestId ( 'section-card' ) ;
1862
1851
const [ , subsection ] = section . childInfo . children ;
1863
1852
const [ , subsectionElement ] = await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ;
1864
- const expandBtn = await within ( subsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
1865
- await act ( async ( ) => fireEvent . click ( expandBtn ) ) ;
1866
1853
const [ , secondUnit ] = subsection . childInfo . children ;
1867
1854
const [ , unitElement ] = await within ( subsectionElement ) . findAllByTestId ( 'unit-card' ) ;
1868
1855
@@ -1902,8 +1889,6 @@ describe('<CourseOutline />', () => {
1902
1889
const [ , sectionElement ] = await findAllByTestId ( 'section-card' ) ;
1903
1890
const [ firstSubsection , subsection ] = section . childInfo . children ;
1904
1891
const [ , subsectionElement ] = await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ;
1905
- const expandBtn = await within ( subsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
1906
- await act ( async ( ) => fireEvent . click ( expandBtn ) ) ;
1907
1892
const [ unit ] = subsection . childInfo . children ;
1908
1893
const [ unitElement ] = await within ( subsectionElement ) . findAllByTestId ( 'unit-card' ) ;
1909
1894
@@ -1939,8 +1924,6 @@ describe('<CourseOutline />', () => {
1939
1924
const [ subsection ] = secondSection . childInfo . children ;
1940
1925
const firstSectionLastSubsection = firstSection . childInfo . children [ firstSection . childInfo . children . length - 1 ] ;
1941
1926
const [ subsectionElement ] = await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ;
1942
- const expandBtn = await within ( subsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
1943
- await act ( async ( ) => fireEvent . click ( expandBtn ) ) ;
1944
1927
const [ unit ] = subsection . childInfo . children ;
1945
1928
const [ unitElement ] = await within ( subsectionElement ) . findAllByTestId ( 'unit-card' ) ;
1946
1929
@@ -1985,8 +1968,6 @@ describe('<CourseOutline />', () => {
1985
1968
const [ , sectionElement ] = await findAllByTestId ( 'section-card' ) ;
1986
1969
const [ firstSubsection , subsection ] = section . childInfo . children ;
1987
1970
const [ subsectionElement ] = await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ;
1988
- const expandBtn = await within ( subsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
1989
- await act ( async ( ) => fireEvent . click ( expandBtn ) ) ;
1990
1971
const lastUnitIdx = firstSubsection . childInfo . children . length - 1 ;
1991
1972
const unit = firstSubsection . childInfo . children [ lastUnitIdx ] ;
1992
1973
const unitElement = ( await within ( subsectionElement ) . findAllByTestId ( 'unit-card' ) ) [ lastUnitIdx ] ;
@@ -2024,8 +2005,6 @@ describe('<CourseOutline />', () => {
2024
2005
const secondSectionLastSubsection = secondSection . childInfo . children [ lastSubIndex ] ;
2025
2006
const thirdSectionFirstSubsection = thirdSection . childInfo . children [ 0 ] ;
2026
2007
const subsectionElement = ( await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ) [ lastSubIndex ] ;
2027
- const expandBtn = await within ( subsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
2028
- await act ( async ( ) => fireEvent . click ( expandBtn ) ) ;
2029
2008
const lastUnitIdx = secondSectionLastSubsection . childInfo . children . length - 1 ;
2030
2009
const unit = secondSectionLastSubsection . childInfo . children [ lastUnitIdx ] ;
2031
2010
const unitElement = ( await within ( subsectionElement ) . findAllByTestId ( 'unit-card' ) ) [ lastUnitIdx ] ;
@@ -2070,8 +2049,6 @@ describe('<CourseOutline />', () => {
2070
2049
const sections = await findAllByTestId ( 'section-card' ) ;
2071
2050
const [ sectionElement ] = sections ;
2072
2051
const [ subsectionElement ] = await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ;
2073
- const expandBtn = await within ( subsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
2074
- await act ( async ( ) => fireEvent . click ( expandBtn ) ) ;
2075
2052
// get first and only unit in the subsection
2076
2053
const [ firstUnit ] = await within ( subsectionElement ) . findAllByTestId ( 'unit-card' ) ;
2077
2054
@@ -2091,8 +2068,6 @@ describe('<CourseOutline />', () => {
2091
2068
const lastSection = sections [ sections . length - 1 ] ;
2092
2069
// it has only one subsection
2093
2070
const [ lastSubsectionElement ] = await within ( lastSection ) . findAllByTestId ( 'subsection-card' ) ;
2094
- const lastExpandBtn = await within ( lastSubsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
2095
- await act ( async ( ) => fireEvent . click ( lastExpandBtn ) ) ;
2096
2071
// get last and the only unit in the subsection
2097
2072
const [ lastUnit ] = await within ( lastSubsectionElement ) . findAllByTestId ( 'unit-card' ) ;
2098
2073
@@ -2113,6 +2088,9 @@ describe('<CourseOutline />', () => {
2113
2088
const { findAllByTestId } = render ( < RootWrapper /> ) ;
2114
2089
2115
2090
const [ sectionElement ] = await findAllByTestId ( 'section-card' ) ;
2091
+ const [ subsectionElement ] = await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ;
2092
+ const expandBtn = await within ( subsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
2093
+ fireEvent . click ( expandBtn ) ;
2116
2094
const [ section ] = store . getState ( ) . courseOutline . sectionsList ;
2117
2095
const subsectionsDraggers = within ( sectionElement ) . getAllByRole ( 'button' , { name : 'Drag to reorder' } ) ;
2118
2096
const draggableButton = subsectionsDraggers [ 1 ] ;
@@ -2144,6 +2122,9 @@ describe('<CourseOutline />', () => {
2144
2122
const { findAllByTestId } = render ( < RootWrapper /> ) ;
2145
2123
2146
2124
const [ sectionElement ] = await findAllByTestId ( 'section-card' ) ;
2125
+ const [ subsectionElement ] = await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ;
2126
+ const expandBtn = await within ( subsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
2127
+ fireEvent . click ( expandBtn ) ;
2147
2128
const [ section ] = store . getState ( ) . courseOutline . sectionsList ;
2148
2129
const subsectionsDraggers = within ( sectionElement ) . getAllByRole ( 'button' , { name : 'Drag to reorder' } ) ;
2149
2130
const draggableButton = subsectionsDraggers [ 1 ] ;
@@ -2173,8 +2154,6 @@ describe('<CourseOutline />', () => {
2173
2154
const [ subsectionElement ] = await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ;
2174
2155
const section = store . getState ( ) . courseOutline . sectionsList [ 2 ] ;
2175
2156
const [ subsection ] = section . childInfo . children ;
2176
- const expandBtn = within ( subsectionElement ) . getByTestId ( 'subsection-card-header__expanded-btn' ) ;
2177
- fireEvent . click ( expandBtn ) ;
2178
2157
const unitDraggers = await within ( subsectionElement ) . findAllByRole ( 'button' , { name : 'Drag to reorder' } ) ;
2179
2158
const draggableButton = unitDraggers [ 1 ] ;
2180
2159
const sections = courseOutlineIndexMock . courseStructure . childInfo . children ;
@@ -2209,8 +2188,6 @@ describe('<CourseOutline />', () => {
2209
2188
const [ subsectionElement ] = await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ;
2210
2189
const section = store . getState ( ) . courseOutline . sectionsList [ 2 ] ;
2211
2190
const [ subsection ] = section . childInfo . children ;
2212
- const expandBtn = within ( subsectionElement ) . getByTestId ( 'subsection-card-header__expanded-btn' ) ;
2213
- fireEvent . click ( expandBtn ) ;
2214
2191
const unitDraggers = await within ( subsectionElement ) . findAllByRole ( 'button' , { name : 'Drag to reorder' } ) ;
2215
2192
const draggableButton = unitDraggers [ 1 ] ;
2216
2193
const sections = courseOutlineIndexMock . courseStructure . childInfo . children ;
@@ -2248,8 +2225,6 @@ describe('<CourseOutline />', () => {
2248
2225
. onGet ( getXBlockApiUrl ( section . id ) )
2249
2226
. reply ( 200 , courseSectionMock ) ;
2250
2227
let [ subsectionElement ] = await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ;
2251
- const expandBtn = await within ( subsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
2252
- userEvent . click ( expandBtn ) ;
2253
2228
const [ unit ] = subsection . childInfo . children ;
2254
2229
const [ unitElement ] = await within ( subsectionElement ) . findAllByTestId ( 'unit-card' ) ;
2255
2230
0 commit comments