@@ -15,7 +15,6 @@ describe('CourseOutlinePage', function() {
1515 createMockSubsectionJSON , verifyTypePublishable , mockCourseJSON , mockEmptyCourseJSON , setSelfPaced , setSelfPacedCustomPLS ,
1616 mockSingleSectionCourseJSON , createMockVerticalJSON , createMockIndexJSON , mockCourseEntranceExamJSON ,
1717 selectOnboardingExam , createMockCourseJSONWithReviewRules , mockCourseJSONWithReviewRules ,
18- expectOptionalCompletion , mockCourseWithoutCompletionJSON , expectOptionalCompletionDisabled ,
1918 mockOutlinePage = readFixtures ( 'templates/mock/mock-course-outline-page.underscore' ) ,
2019 mockRerunNotification = readFixtures ( 'templates/mock/mock-course-rerun-notification.underscore' ) ;
2120
@@ -348,22 +347,6 @@ describe('CourseOutlinePage', function() {
348347 ] )
349348 ] )
350349 ] ) ;
351- mockCourseWithoutCompletionJSON = createMockCourseJSON ( { completion_tracking_enabled : false } , [
352- createMockSectionJSON ( { } , [
353- createMockSubsectionJSON ( { } , [
354- createMockVerticalJSON ( )
355- ] )
356- ] )
357- ] ) ;
358-
359- expectOptionalCompletion = function ( exists ) {
360- expect ( $ ( '#optional_completion' ) . length ) . toBeGreaterThanOrEqual ( exists , `optional completion existence should be ${ exists } ` ) ;
361- } ;
362-
363- expectOptionalCompletionDisabled = function ( disabled ) {
364- expect ( $ ( '#optional_completion' ) . is ( ':disabled' ) ) . toBe ( disabled )
365- } ;
366-
367350
368351 // Create a mock Course object as the JS now expects it.
369352 window . course = new Course ( {
@@ -1046,30 +1029,41 @@ describe('CourseOutlinePage', function() {
10461029 expect ( $modalWindow . find ( '.outline-subsection' ) . length ) . toBe ( 2 ) ;
10471030 } ) ;
10481031
1049- it ( 'hides optional completion checkbox when completion tracking is disabled ' , function ( ) {
1050- createCourseOutlinePage ( this , mockCourseWithoutCompletionJSON , false ) ;
1032+ it ( 'hides optional completion checkbox by default ' , function ( ) {
1033+ createCourseOutlinePage ( this , mockCourseJSON , false ) ;
10511034 outlinePage . $ ( '.section-header-actions .configure-button' ) . click ( ) ;
1052- expect ( $ ( '.edit-optional-completion' ) . length ) . toBe ( 0 ) ;
1035+ expect ( $ ( '.edit-optional-completion' ) ) . not . toExist ( ) ;
10531036 } ) ;
10541037
1055- describe ( 'Optional Completion ' , function ( ) {
1038+ describe ( 'supports optional completion and ' , function ( ) {
10561039 beforeEach ( function ( ) {
1057- createMockCourseJSON ( { } , [
1058- createMockSectionJSON ( { optional_completion : true } , [
1059- createMockSubsectionJSON ( { ancestor_has_optional_completion : true } , [ ] )
1060- ] )
1061- ] ) ;
1040+ window . course . attributes . completion_tracking_enabled = true ;
1041+ } ) ;
1042+
1043+ it ( 'shows optional completion checkbox unchecked by default' , function ( ) {
1044+ createCourseOutlinePage ( this , mockCourseJSON , false ) ;
1045+ outlinePage . $ ( '.section-header-actions .configure-button' ) . click ( ) ;
1046+ expect ( $ ( '.edit-optional-completion' ) ) . toExist ( ) ;
1047+ expect ( $ ( '#optional_completion' ) . is ( ':checked' ) ) . toBe ( false ) ;
10621048 } ) ;
10631049
1064- it ( 'displays optional completion message and disables children optional completion checkboxes' , function ( ) {
1065- expect ( $ ( '.status-message-copy' ) ) . toExist ( )
1050+ it ( 'shows optional completion checkbox checked' , function ( ) {
1051+ var mockCourseJSON = createMockCourseJSON ( { } , [
1052+ createMockSectionJSON ( { optional_completion : true } )
1053+ ] ) ;
1054+ createCourseOutlinePage ( this , mockCourseJSON , false ) ;
10661055 outlinePage . $ ( '.section-header-actions .configure-button' ) . click ( ) ;
1067- expectOptionalCompletion ( 1 ) ;
1068- $ ( '.wrapper-modal-window .action-cancel' ) . click ( ) ;
1069- outlinePage . $ ( '.subsection-header-actions .configure-button' ) . click ( ) ;
1070- expectOptionalCompletion ( 1 ) ;
1071- expectOptionalCompletionDisabled ( true ) ;
1072- expect ( $ ( '.tip-warning' ) ) . toExist ( ) ;
1056+ expect ( $ ( '#optional_completion' ) . is ( ':disabled' ) ) . toBe ( false ) ;
1057+ expect ( $ ( '#optional_completion' ) . is ( ':checked' ) ) . toBe ( true ) ;
1058+ } ) ;
1059+
1060+ it ( 'disables optional completion checkbox when the parent uses optional completion' , function ( ) {
1061+ var mockCourseJSON = createMockCourseJSON ( { } , [
1062+ createMockSectionJSON ( { ancestor_has_optional_completion : true } )
1063+ ] ) ;
1064+ createCourseOutlinePage ( this , mockCourseJSON , false ) ;
1065+ outlinePage . $ ( '.section-header-actions .configure-button' ) . click ( ) ;
1066+ expect ( $ ( '#optional_completion' ) . is ( ':disabled' ) ) . toBe ( true ) ;
10731067 } ) ;
10741068 } ) ;
10751069 } ) ;
@@ -2372,6 +2366,48 @@ describe('CourseOutlinePage', function() {
23722366 ) ;
23732367 } ) ;
23742368 } )
2369+
2370+ it ( 'hides optional completion checkbox by default' , function ( ) {
2371+ createCourseOutlinePage ( this , mockCourseJSON , false ) ;
2372+ outlinePage . $ ( '.outline-subsection .configure-button' ) . click ( ) ;
2373+ expect ( $ ( '.edit-optional-completion' ) ) . not . toExist ( ) ;
2374+ } ) ;
2375+
2376+ describe ( 'supports optional completion and' , function ( ) {
2377+ beforeEach ( function ( ) {
2378+ window . course . attributes . completion_tracking_enabled = true ;
2379+ } ) ;
2380+
2381+ it ( 'shows optional completion checkbox unchecked by default' , function ( ) {
2382+ createCourseOutlinePage ( this , mockCourseJSON , false ) ;
2383+ outlinePage . $ ( '.outline-subsection .configure-button' ) . click ( ) ;
2384+ expect ( $ ( '.edit-optional-completion' ) ) . toExist ( ) ;
2385+ expect ( $ ( '#optional_completion' ) . is ( ':checked' ) ) . toBe ( false ) ;
2386+ } ) ;
2387+
2388+ it ( 'shows optional completion checkbox checked' , function ( ) {
2389+ var mockCourseJSON = createMockCourseJSON ( { } , [
2390+ createMockSectionJSON ( { } , [
2391+ createMockSubsectionJSON ( { optional_completion : true } , [ ] )
2392+ ] )
2393+ ] ) ;
2394+ createCourseOutlinePage ( this , mockCourseJSON , false ) ;
2395+ outlinePage . $ ( '.outline-subsection .configure-button' ) . click ( ) ;
2396+ expect ( $ ( '#optional_completion' ) . is ( ':disabled' ) ) . toBe ( false ) ;
2397+ expect ( $ ( '#optional_completion' ) . is ( ':checked' ) ) . toBe ( true ) ;
2398+ } ) ;
2399+
2400+ it ( 'disables optional completion checkbox when the parent uses optional completion' , function ( ) {
2401+ var mockCourseJSON = createMockCourseJSON ( { } , [
2402+ createMockSectionJSON ( { } , [
2403+ createMockSubsectionJSON ( { ancestor_has_optional_completion : true } , [ ] )
2404+ ] )
2405+ ] ) ;
2406+ createCourseOutlinePage ( this , mockCourseJSON , false ) ;
2407+ outlinePage . $ ( '.outline-subsection .configure-button' ) . click ( ) ;
2408+ expect ( $ ( '#optional_completion' ) . is ( ':disabled' ) ) . toBe ( true ) ;
2409+ } ) ;
2410+ } ) ;
23752411 } ) ;
23762412
23772413 // Note: most tests for units can be found in Bok Choy
@@ -2488,6 +2524,38 @@ describe('CourseOutlinePage', function() {
24882524 ] )
24892525 ] ) ;
24902526 } ) ;
2527+
2528+ it ( 'hides optional completion checkbox by default' , function ( ) {
2529+ getUnitStatus ( { } , { } ) ;
2530+ outlinePage . $ ( '.outline-unit .configure-button' ) . click ( ) ;
2531+ expect ( $ ( '.edit-optional-completion' ) ) . not . toExist ( ) ;
2532+ } ) ;
2533+
2534+ describe ( 'supports optional completion and' , function ( ) {
2535+ beforeEach ( function ( ) {
2536+ window . course . attributes . completion_tracking_enabled = true ;
2537+ } ) ;
2538+
2539+ it ( 'shows optional completion checkbox unchecked by default' , function ( ) {
2540+ getUnitStatus ( { } , { } ) ;
2541+ outlinePage . $ ( '.outline-unit .configure-button' ) . click ( ) ;
2542+ expect ( $ ( '.edit-optional-completion' ) ) . toExist ( ) ;
2543+ expect ( $ ( '#optional_completion' ) . is ( ':checked' ) ) . toBe ( false ) ;
2544+ } ) ;
2545+
2546+ it ( 'shows optional completion checkbox checked' , function ( ) {
2547+ getUnitStatus ( { optional_completion : true } , { } ) ;
2548+ outlinePage . $ ( '.outline-unit .configure-button' ) . click ( ) ;
2549+ expect ( $ ( '#optional_completion' ) . is ( ':disabled' ) ) . toBe ( false ) ;
2550+ expect ( $ ( '#optional_completion' ) . is ( ':checked' ) ) . toBe ( true ) ;
2551+ } ) ;
2552+
2553+ it ( 'disables optional completion checkbox when the parent uses optional completion' , function ( ) {
2554+ getUnitStatus ( { ancestor_has_optional_completion : true } , { } ) ;
2555+ outlinePage . $ ( '.outline-unit .configure-button' ) . click ( ) ;
2556+ expect ( $ ( '#optional_completion' ) . is ( ':disabled' ) ) . toBe ( true ) ;
2557+ } ) ;
2558+ } ) ;
24912559 } ) ;
24922560
24932561 describe ( 'Date and Time picker' , function ( ) {
0 commit comments