Skip to content

Commit

Permalink
test: add tests for outline modals
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielVZ96 committed Apr 2, 2024
1 parent 836a127 commit 84ad5ee
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 12 deletions.
8 changes: 1 addition & 7 deletions cms/djangoapps/contentstore/tests/test_utils.py
Expand Up @@ -353,6 +353,7 @@ def setUp(self):
self.vertical = self.store.get_item(vertical.location)
self.html = self.store.get_item(html.location)
self.problem = self.store.get_item(problem.location)
self.orphan = BlockFactory.create(category='vertical', parent_location=self.sequential.location)

def set_optional_completion(self, xblock, value):
""" Sets optional_completion to specified value and calls update_item to persist the change. """
Expand All @@ -371,13 +372,6 @@ def test_no_inheritance(self):
self.update_optional_completions(False, False, True)
self.assertFalse(utils.ancestor_has_optional_completion(self.vertical))

def test_inheritance_in_optional_section(self):
"""Tests that a vertical in an optional section has an inherited optional completion"""
self.update_optional_completions(True, False, False)
self.assertTrue(utils.ancestor_has_optional_completion(self.vertical))
self.update_optional_completions(True, False, True)
self.assertTrue(utils.ancestor_has_optional_completion(self.vertical))

def test_inheritance_in_optional_subsection(self):
"""Tests that a vertical in an optional subsection has an inherited optional completion"""
self.update_optional_completions(False, True, False)
Expand Down
2 changes: 1 addition & 1 deletion cms/djangoapps/contentstore/views/tests/test_block.py
Expand Up @@ -2630,7 +2630,7 @@ def test_json_responses(self):

@ddt.data(
(ModuleStoreEnum.Type.split, 3, 3),
(ModuleStoreEnum.Type.mongo, 8, 12),
(ModuleStoreEnum.Type.mongo, 10, 14),
)
@ddt.unpack
def test_xblock_outline_handler_mongo_calls(self, store_type, chapter_queries, chapter_queries_1):
Expand Down
59 changes: 55 additions & 4 deletions cms/static/js/spec/views/pages/course_outline_spec.js
Expand Up @@ -15,6 +15,7 @@ describe('CourseOutlinePage', function() {
createMockSubsectionJSON, verifyTypePublishable, mockCourseJSON, mockEmptyCourseJSON, setSelfPaced, setSelfPacedCustomPLS,
mockSingleSectionCourseJSON, createMockVerticalJSON, createMockIndexJSON, mockCourseEntranceExamJSON,
selectOnboardingExam, createMockCourseJSONWithReviewRules,mockCourseJSONWithReviewRules,
expectOptionalCompletion, mockCourseWithoutCompletionJSON, expectOptionalCompletionDisabled,
mockOutlinePage = readFixtures('templates/mock/mock-course-outline-page.underscore'),
mockRerunNotification = readFixtures('templates/mock/mock-course-rerun-notification.underscore');

Expand Down Expand Up @@ -42,7 +43,8 @@ describe('CourseOutlinePage', function() {
user_partition_info: {},
highlights_enabled: true,
highlights_enabled_for_messaging: false,
show_delete_button: true
show_delete_button: true,
completion_tracking_enabled: true,
}, options, {child_info: {children: children}});
};

Expand Down Expand Up @@ -70,6 +72,7 @@ describe('CourseOutlinePage', function() {
user_partition_info: {},
highlights_enabled: true,
highlights_enabled_for_messaging: false,
completion_tracking_enabled: true,
show_delete_button: true
}, options, {child_info: {children: children}});
};
Expand All @@ -96,6 +99,7 @@ describe('CourseOutlinePage', function() {
user_partition_info: {},
highlights: [],
highlights_enabled: true,
completion_tracking_enabled: true,
show_delete_button: true
}, options, {child_info: {children: children}});
};
Expand Down Expand Up @@ -127,6 +131,7 @@ describe('CourseOutlinePage', function() {
user_partitions: [],
group_access: {},
user_partition_info: {},
completion_tracking_enabled: true,
show_delete_button: true
}, options, {child_info: {children: children}});
};
Expand All @@ -146,6 +151,7 @@ describe('CourseOutlinePage', function() {
user_partitions: [],
group_access: {},
user_partition_info: {},
completion_tracking_enabled: true,
show_delete_button: true
}, options);
};
Expand Down Expand Up @@ -220,6 +226,7 @@ describe('CourseOutlinePage', function() {
createCourseOutlinePage = function(test, courseJSON, createOnly) {
requests = AjaxHelpers.requests(test);
model = new XBlockOutlineInfo(courseJSON, {parse: true});
console.warn("course:", model)
outlinePage = new CourseOutlinePage({
model: model,
el: $('#content')
Expand Down Expand Up @@ -313,10 +320,10 @@ describe('CourseOutlinePage', function() {
'staff-lock-editor', 'unit-access-editor', 'discussion-editor', 'content-visibility-editor',
'settings-modal-tabs', 'timed-examination-preference-editor', 'access-editor',
'show-correctness-editor', 'highlights-editor', 'highlights-enable-editor',
'course-highlights-enable'
'course-highlights-enable', 'optional-completion-editor'
]);
appendSetFixtures(mockOutlinePage);
mockCourseJSON = createMockCourseJSON({}, [
mockCourseJSON = createMockCourseJSON({completion_tracking_enabled: true}, [
createMockSectionJSON({}, [
createMockSubsectionJSON({}, [
createMockVerticalJSON()
Expand All @@ -341,6 +348,22 @@ describe('CourseOutlinePage', function() {
])
])
]);
mockCourseWithoutCompletionJSON = createMockCourseJSON({completion_tracking_enabled: false}, [
createMockSectionJSON({}, [
createMockSubsectionJSON({}, [
createMockVerticalJSON()
])
])
]);

expectOptionalCompletion = function(exists) {
expect($('#optional_completion').length).toBeGreaterThanOrEqual(exists, `optional completion existence should be ${exists}`);
};

expectOptionalCompletionDisabled = function(disabled) {
expect($('#optional_completion').is(':disabled')).toBe(disabled)
};


// Create a mock Course object as the JS now expects it.
window.course = new Course({
Expand Down Expand Up @@ -944,6 +967,7 @@ describe('CourseOutlinePage', function() {
createCourseOutlinePage(this, mockCourseJSON, false);
outlinePage.$('.section-header-actions .configure-button').click();
$('#start_date').val('1/2/2015');

// Section release date can't be cleared.
expect($('.wrapper-modal-window .action-clear')).not.toExist();

Expand Down Expand Up @@ -1021,6 +1045,33 @@ describe('CourseOutlinePage', function() {
);
expect($modalWindow.find('.outline-subsection').length).toBe(2);
});

it('hides optional completion checkbox when completion tracking is disabled', function() {
createCourseOutlinePage(this, mockCourseWithoutCompletionJSON, false);
outlinePage.$('.section-header-actions .configure-button').click();
expect($('.edit-optional-completion').length).toBe(0);
});

describe('Optional Completion', function () {
beforeEach(function() {
createMockCourseJSON({}, [
createMockSectionJSON({optional_completion: true}, [
createMockSubsectionJSON({ancestor_has_optional_completion: true}, [])
])
]);
});

it('displays optional completion message and disables children optional completion checkboxes', function() {
expect($('.status-message-copy')).toExist()
outlinePage.$('.section-header-actions .configure-button').click();
expectOptionalCompletion(1);
$('.wrapper-modal-window .action-cancel').click();
outlinePage.$('.subsection-header-actions .configure-button').click();
expectOptionalCompletion(1);
expectOptionalCompletionDisabled(true);
expect($('.tip-warning')).toExist();
});
});
});

describe('Subsection', function() {
Expand Down Expand Up @@ -2423,7 +2474,7 @@ describe('CourseOutlinePage', function() {
it('hides discussion settings if unit level discussions are disabled', function() {
getUnitStatus({}, {unit_level_discussions: false});
outlinePage.$('.outline-unit .configure-button').click();
expect($('.modal-section .edit-discussion')).not.toExist();
expect($('.modal-section .edit-discussion').length).toBe(0);
});

});
Expand Down

0 comments on commit 84ad5ee

Please sign in to comment.