From e4635aaa69fca763bdaf36b43e3457a6d21c4ea0 Mon Sep 17 00:00:00 2001 From: Ben McMorran Date: Tue, 5 Aug 2014 11:15:46 -0400 Subject: [PATCH] Don't release date if it hasn't been changed. STUD-2056 --- .../js/views/modals/edit_outline_item.js | 14 ++++++++++- .../acceptance/tests/test_studio_outline.py | 24 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/cms/static/js/views/modals/edit_outline_item.js b/cms/static/js/views/modals/edit_outline_item.js index 1a4274dcf9..94d6b55d9a 100644 --- a/cms/static/js/views/modals/edit_outline_item.js +++ b/cms/static/js/views/modals/edit_outline_item.js @@ -184,6 +184,14 @@ define(['jquery', 'backbone', 'underscore', 'gettext', 'js/views/modals/base_mod ReleaseDateView = BaseDateView.extend({ fieldName: 'start', + startingReleaseDate: null, + + afterRender: function () { + BaseDateView.prototype.afterRender.call(this); + // Store the starting date and time so that we can determine if the user + // actually changed it when "Save" is pressed. + this.startingReleaseDate = this.getValue(); + }, getValue: function () { return DateUtils.getDate(this.$('#start_date'), this.$('#start_time')); @@ -195,8 +203,12 @@ define(['jquery', 'backbone', 'underscore', 'gettext', 'js/views/modals/base_mod }, getMetadata: function () { + var newReleaseDate = this.getValue(); + if (JSON.stringify(newReleaseDate) === JSON.stringify(this.startingReleaseDate)) { + return {}; + } return { - 'start': this.getValue() + 'start': newReleaseDate }; } }); diff --git a/common/test/acceptance/tests/test_studio_outline.py b/common/test/acceptance/tests/test_studio_outline.py index 46d8d5f40e..303d979658 100644 --- a/common/test/acceptance/tests/test_studio_outline.py +++ b/common/test/acceptance/tests/test_studio_outline.py @@ -375,6 +375,30 @@ class EditingSectionsTest(CourseOutlineTest): self.assertEqual(u'Problem', progress_page.grading_formats[0]) + def test_unchanged_release_date_is_not_saved(self): + """ + Scenario: Saving a subsection without changing the release date will not override the release date + Given that I have created a section with a subsection + When I open the settings modal for the subsection + And I pressed save + And I open the settings modal for the section + And I change the release date to 07/20/1969 + And I press save + Then the subsection and the section have the release date 07/20/1969 + """ + self.course_outline_page.visit() + + modal = self.course_outline_page.section_at(0).subsection_at(0).edit() + modal.save() + + modal = self.course_outline_page.section_at(0).edit() + modal.release_date = '7/20/1969' + modal.save() + + release_text = 'Released: Jul 20, 1969' + self.assertIn(release_text, self.course_outline_page.section_at(0).release_date) + self.assertIn(release_text, self.course_outline_page.section_at(0).subsection_at(0).release_date) + class EditNamesTest(CourseOutlineTest): """