@@ -11,7 +11,6 @@ import { cloneDeep } from 'lodash';
11
11
import { closestCorners } from '@dnd-kit/core' ;
12
12
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 ,
@@ -289,13 +288,15 @@ describe('<CourseOutline />', () => {
289
288
} ) ;
290
289
291
290
it ( 'check that new section list is saved when dragged' , async ( ) => {
292
- const { findAllByRole } = render ( < RootWrapper /> ) ;
293
- const courseBlockId = courseOutlineIndexMock . courseStructure . id ;
291
+ const { findAllByRole, findByTestId } = render ( < RootWrapper /> ) ;
292
+ const expandAllButton = await findByTestId ( 'expand-collapse-all-button' ) ;
293
+ fireEvent . click ( expandAllButton ) ;
294
+ const [ section ] = store . getState ( ) . courseOutline . sectionsList ;
294
295
const sectionsDraggers = await findAllByRole ( 'button' , { name : 'Drag to reorder' } ) ;
295
- const draggableButton = sectionsDraggers [ 6 ] ;
296
+ const draggableButton = sectionsDraggers [ 1 ] ;
296
297
297
298
axiosMock
298
- . onPut ( getCourseBlockApiUrl ( courseBlockId ) )
299
+ . onPut ( getCourseBlockApiUrl ( section . id ) )
299
300
. reply ( 200 , { dummy : 'value' } ) ;
300
301
301
302
const section1 = store . getState ( ) . courseOutline . sectionsList [ 0 ] . id ;
@@ -314,13 +315,15 @@ describe('<CourseOutline />', () => {
314
315
} ) ;
315
316
316
317
it ( 'check section list is restored to original order when API call fails' , async ( ) => {
317
- const { findAllByRole } = render ( < RootWrapper /> ) ;
318
- const courseBlockId = courseOutlineIndexMock . courseStructure . id ;
318
+ const { findAllByRole, findByTestId } = render ( < RootWrapper /> ) ;
319
+ const expandAllButton = await findByTestId ( 'expand-collapse-all-button' ) ;
320
+ fireEvent . click ( expandAllButton ) ;
321
+ const [ section ] = store . getState ( ) . courseOutline . sectionsList ;
319
322
const sectionsDraggers = await findAllByRole ( 'button' , { name : 'Drag to reorder' } ) ;
320
- const draggableButton = sectionsDraggers [ 6 ] ;
323
+ const draggableButton = sectionsDraggers [ 1 ] ;
321
324
322
325
axiosMock
323
- . onPut ( getCourseBlockApiUrl ( courseBlockId ) )
326
+ . onPut ( getCourseBlockApiUrl ( section . id ) )
324
327
. reply ( 500 ) ;
325
328
326
329
const section1 = store . getState ( ) . courseOutline . sectionsList [ 0 ] . id ;
@@ -395,8 +398,6 @@ describe('<CourseOutline />', () => {
395
398
const { findAllByTestId } = render ( < RootWrapper /> ) ;
396
399
const [ sectionElement ] = await findAllByTestId ( 'section-card' ) ;
397
400
const [ subsectionElement ] = await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ;
398
- const expandBtn = await within ( subsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
399
- fireEvent . click ( expandBtn ) ;
400
401
const units = await within ( subsectionElement ) . findAllByTestId ( 'unit-card' ) ;
401
402
expect ( units . length ) . toBe ( 1 ) ;
402
403
@@ -421,8 +422,6 @@ describe('<CourseOutline />', () => {
421
422
render ( < RootWrapper /> ) ;
422
423
const [ sectionElement ] = await screen . findAllByTestId ( 'section-card' ) ;
423
424
const [ subsectionElement ] = await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ;
424
- const expandBtn = await within ( subsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
425
- fireEvent . click ( expandBtn ) ;
426
425
const units = await within ( subsectionElement ) . findAllByTestId ( 'unit-card' ) ;
427
426
expect ( units . length ) . toBe ( 1 ) ;
428
427
@@ -646,8 +645,6 @@ describe('<CourseOutline />', () => {
646
645
await checkEditTitle ( section , subsectionElement , subsection , 'New subsection name' , 'subsection' ) ;
647
646
648
647
// check unit
649
- const expandBtn = await within ( subsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
650
- fireEvent . click ( expandBtn ) ;
651
648
const [ unit ] = subsection . childInfo . children ;
652
649
const [ unitElement ] = await within ( subsectionElement ) . findAllByTestId ( 'unit-card' ) ;
653
650
await checkEditTitle ( section , unitElement , unit , 'New unit name' , 'unit' ) ;
@@ -660,8 +657,6 @@ describe('<CourseOutline />', () => {
660
657
const [ sectionElement ] = await screen . findAllByTestId ( 'section-card' ) ;
661
658
const [ subsection ] = section . childInfo . children ;
662
659
const [ subsectionElement ] = await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ;
663
- const expandBtn = await within ( subsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
664
- fireEvent . click ( expandBtn ) ;
665
660
const [ unit ] = subsection . childInfo . children ;
666
661
const [ unitElement ] = await within ( subsectionElement ) . findAllByTestId ( 'unit-card' ) ;
667
662
@@ -700,8 +695,6 @@ describe('<CourseOutline />', () => {
700
695
const [ sectionElement ] = await findAllByTestId ( 'section-card' ) ;
701
696
const [ subsection ] = section . childInfo . children ;
702
697
const [ subsectionElement ] = await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ;
703
- const expandBtn = await within ( subsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
704
- fireEvent . click ( expandBtn ) ;
705
698
const [ unit ] = subsection . childInfo . children ;
706
699
const [ unitElement ] = await within ( subsectionElement ) . findAllByTestId ( 'unit-card' ) ;
707
700
@@ -771,8 +764,6 @@ describe('<CourseOutline />', () => {
771
764
const [ sectionElement ] = await findAllByTestId ( 'section-card' ) ;
772
765
const [ subsection ] = section . childInfo . children ;
773
766
const [ subsectionElement ] = await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ;
774
- const expandBtn = await within ( subsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
775
- fireEvent . click ( expandBtn ) ;
776
767
const [ unit ] = subsection . childInfo . children ;
777
768
const [ unitElement ] = await within ( subsectionElement ) . findAllByTestId ( 'unit-card' ) ;
778
769
@@ -1481,8 +1472,6 @@ describe('<CourseOutline />', () => {
1481
1472
1482
1473
const [ firstSection ] = await findAllByTestId ( 'section-card' ) ;
1483
1474
const [ firstSubsection ] = await within ( firstSection ) . findAllByTestId ( 'subsection-card' ) ;
1484
- const subsectionExpandButton = await within ( firstSubsection ) . getByTestId ( 'subsection-card-header__expanded-btn' ) ;
1485
- fireEvent . click ( subsectionExpandButton ) ;
1486
1475
const [ firstUnit ] = await within ( firstSubsection ) . findAllByTestId ( 'unit-card' ) ;
1487
1476
const unitDropdownButton = await within ( firstUnit ) . findByTestId ( 'unit-card-header__menu-button' ) ;
1488
1477
@@ -1842,8 +1831,6 @@ describe('<CourseOutline />', () => {
1842
1831
const [ , sectionElement ] = await findAllByTestId ( 'section-card' ) ;
1843
1832
const [ , subsection ] = section . childInfo . children ;
1844
1833
const [ , subsectionElement ] = await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ;
1845
- const expandBtn = await within ( subsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
1846
- await act ( async ( ) => fireEvent . click ( expandBtn ) ) ;
1847
1834
const [ , secondUnit ] = subsection . childInfo . children ;
1848
1835
const [ , unitElement ] = await within ( subsectionElement ) . findAllByTestId ( 'unit-card' ) ;
1849
1836
@@ -1883,8 +1870,6 @@ describe('<CourseOutline />', () => {
1883
1870
const [ , sectionElement ] = await findAllByTestId ( 'section-card' ) ;
1884
1871
const [ firstSubsection , subsection ] = section . childInfo . children ;
1885
1872
const [ , subsectionElement ] = await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ;
1886
- const expandBtn = await within ( subsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
1887
- await act ( async ( ) => fireEvent . click ( expandBtn ) ) ;
1888
1873
const [ unit ] = subsection . childInfo . children ;
1889
1874
const [ unitElement ] = await within ( subsectionElement ) . findAllByTestId ( 'unit-card' ) ;
1890
1875
@@ -1920,8 +1905,6 @@ describe('<CourseOutline />', () => {
1920
1905
const [ subsection ] = secondSection . childInfo . children ;
1921
1906
const firstSectionLastSubsection = firstSection . childInfo . children [ firstSection . childInfo . children . length - 1 ] ;
1922
1907
const [ subsectionElement ] = await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ;
1923
- const expandBtn = await within ( subsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
1924
- await act ( async ( ) => fireEvent . click ( expandBtn ) ) ;
1925
1908
const [ unit ] = subsection . childInfo . children ;
1926
1909
const [ unitElement ] = await within ( subsectionElement ) . findAllByTestId ( 'unit-card' ) ;
1927
1910
@@ -1966,8 +1949,6 @@ describe('<CourseOutline />', () => {
1966
1949
const [ , sectionElement ] = await findAllByTestId ( 'section-card' ) ;
1967
1950
const [ firstSubsection , subsection ] = section . childInfo . children ;
1968
1951
const [ subsectionElement ] = await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ;
1969
- const expandBtn = await within ( subsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
1970
- await act ( async ( ) => fireEvent . click ( expandBtn ) ) ;
1971
1952
const lastUnitIdx = firstSubsection . childInfo . children . length - 1 ;
1972
1953
const unit = firstSubsection . childInfo . children [ lastUnitIdx ] ;
1973
1954
const unitElement = ( await within ( subsectionElement ) . findAllByTestId ( 'unit-card' ) ) [ lastUnitIdx ] ;
@@ -2005,8 +1986,6 @@ describe('<CourseOutline />', () => {
2005
1986
const secondSectionLastSubsection = secondSection . childInfo . children [ lastSubIndex ] ;
2006
1987
const thirdSectionFirstSubsection = thirdSection . childInfo . children [ 0 ] ;
2007
1988
const subsectionElement = ( await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ) [ lastSubIndex ] ;
2008
- const expandBtn = await within ( subsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
2009
- await act ( async ( ) => fireEvent . click ( expandBtn ) ) ;
2010
1989
const lastUnitIdx = secondSectionLastSubsection . childInfo . children . length - 1 ;
2011
1990
const unit = secondSectionLastSubsection . childInfo . children [ lastUnitIdx ] ;
2012
1991
const unitElement = ( await within ( subsectionElement ) . findAllByTestId ( 'unit-card' ) ) [ lastUnitIdx ] ;
@@ -2051,8 +2030,6 @@ describe('<CourseOutline />', () => {
2051
2030
const sections = await findAllByTestId ( 'section-card' ) ;
2052
2031
const [ sectionElement ] = sections ;
2053
2032
const [ subsectionElement ] = await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ;
2054
- const expandBtn = await within ( subsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
2055
- await act ( async ( ) => fireEvent . click ( expandBtn ) ) ;
2056
2033
// get first and only unit in the subsection
2057
2034
const [ firstUnit ] = await within ( subsectionElement ) . findAllByTestId ( 'unit-card' ) ;
2058
2035
@@ -2072,8 +2049,6 @@ describe('<CourseOutline />', () => {
2072
2049
const lastSection = sections [ sections . length - 1 ] ;
2073
2050
// it has only one subsection
2074
2051
const [ lastSubsectionElement ] = await within ( lastSection ) . findAllByTestId ( 'subsection-card' ) ;
2075
- const lastExpandBtn = await within ( lastSubsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
2076
- await act ( async ( ) => fireEvent . click ( lastExpandBtn ) ) ;
2077
2052
// get last and the only unit in the subsection
2078
2053
const [ lastUnit ] = await within ( lastSubsectionElement ) . findAllByTestId ( 'unit-card' ) ;
2079
2054
@@ -2094,6 +2069,9 @@ describe('<CourseOutline />', () => {
2094
2069
const { findAllByTestId } = render ( < RootWrapper /> ) ;
2095
2070
2096
2071
const [ sectionElement ] = await findAllByTestId ( 'section-card' ) ;
2072
+ const [ subsectionElement ] = await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ;
2073
+ const expandBtn = await within ( subsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
2074
+ fireEvent . click ( expandBtn ) ;
2097
2075
const [ section ] = store . getState ( ) . courseOutline . sectionsList ;
2098
2076
const subsectionsDraggers = within ( sectionElement ) . getAllByRole ( 'button' , { name : 'Drag to reorder' } ) ;
2099
2077
const draggableButton = subsectionsDraggers [ 1 ] ;
@@ -2125,6 +2103,9 @@ describe('<CourseOutline />', () => {
2125
2103
const { findAllByTestId } = render ( < RootWrapper /> ) ;
2126
2104
2127
2105
const [ sectionElement ] = await findAllByTestId ( 'section-card' ) ;
2106
+ const [ subsectionElement ] = await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ;
2107
+ const expandBtn = await within ( subsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
2108
+ fireEvent . click ( expandBtn ) ;
2128
2109
const [ section ] = store . getState ( ) . courseOutline . sectionsList ;
2129
2110
const subsectionsDraggers = within ( sectionElement ) . getAllByRole ( 'button' , { name : 'Drag to reorder' } ) ;
2130
2111
const draggableButton = subsectionsDraggers [ 1 ] ;
@@ -2154,8 +2135,6 @@ describe('<CourseOutline />', () => {
2154
2135
const [ subsectionElement ] = await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ;
2155
2136
const section = store . getState ( ) . courseOutline . sectionsList [ 2 ] ;
2156
2137
const [ subsection ] = section . childInfo . children ;
2157
- const expandBtn = within ( subsectionElement ) . getByTestId ( 'subsection-card-header__expanded-btn' ) ;
2158
- fireEvent . click ( expandBtn ) ;
2159
2138
const unitDraggers = await within ( subsectionElement ) . findAllByRole ( 'button' , { name : 'Drag to reorder' } ) ;
2160
2139
const draggableButton = unitDraggers [ 1 ] ;
2161
2140
const sections = courseOutlineIndexMock . courseStructure . childInfo . children ;
@@ -2190,8 +2169,6 @@ describe('<CourseOutline />', () => {
2190
2169
const [ subsectionElement ] = await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ;
2191
2170
const section = store . getState ( ) . courseOutline . sectionsList [ 2 ] ;
2192
2171
const [ subsection ] = section . childInfo . children ;
2193
- const expandBtn = within ( subsectionElement ) . getByTestId ( 'subsection-card-header__expanded-btn' ) ;
2194
- fireEvent . click ( expandBtn ) ;
2195
2172
const unitDraggers = await within ( subsectionElement ) . findAllByRole ( 'button' , { name : 'Drag to reorder' } ) ;
2196
2173
const draggableButton = unitDraggers [ 1 ] ;
2197
2174
const sections = courseOutlineIndexMock . courseStructure . childInfo . children ;
@@ -2229,8 +2206,6 @@ describe('<CourseOutline />', () => {
2229
2206
. onGet ( getXBlockApiUrl ( section . id ) )
2230
2207
. reply ( 200 , courseSectionMock ) ;
2231
2208
let [ subsectionElement ] = await within ( sectionElement ) . findAllByTestId ( 'subsection-card' ) ;
2232
- const expandBtn = await within ( subsectionElement ) . findByTestId ( 'subsection-card-header__expanded-btn' ) ;
2233
- userEvent . click ( expandBtn ) ;
2234
2209
const [ unit ] = subsection . childInfo . children ;
2235
2210
const [ unitElement ] = await within ( subsectionElement ) . findAllByTestId ( 'unit-card' ) ;
2236
2211
0 commit comments