From a061c7ece78450715120af12f3ee5850fe942ab5 Mon Sep 17 00:00:00 2001 From: cahrens Date: Thu, 29 Aug 2013 14:35:16 -0400 Subject: [PATCH] Rewriting of links for Course Updates and Course Handouts. STUD-669. --- .../features/course-updates.feature | 22 +++ .../contentstore/features/course-updates.py | 17 +++ cms/djangoapps/contentstore/views/course.py | 4 +- cms/envs/common.py | 2 +- .../coffee/spec/views/course_info_spec.coffee | 144 ++++++++++++++++++ cms/static/js/views/course_info_edit.js | 122 ++++++++------- cms/static/js_test.yml | 2 + cms/templates/course_info.html | 1 + common/lib/xmodule/xmodule/js/js_test.yml | 1 + .../xmodule/xmodule/js/src/html/edit.coffee | 15 +- common/static/js/spec/utility_spec.js | 13 ++ common/static/js/{ => src}/utility.js | 10 ++ common/static/js_test.yml | 2 + lms/envs/common.py | 2 +- 14 files changed, 290 insertions(+), 67 deletions(-) create mode 100644 cms/static/coffee/spec/views/course_info_spec.coffee create mode 100644 common/static/js/spec/utility_spec.js rename common/static/js/{ => src}/utility.js (83%) diff --git a/cms/djangoapps/contentstore/features/course-updates.feature b/cms/djangoapps/contentstore/features/course-updates.feature index 41ee785db5..bc73479c5f 100644 --- a/cms/djangoapps/contentstore/features/course-updates.feature +++ b/cms/djangoapps/contentstore/features/course-updates.feature @@ -45,3 +45,25 @@ Feature: Course updates When I modify the handout to "
    Test
" Then I see the handout "Test" And I see a "saving" notification + + Scenario: Static links are rewritten when previewing a course update + Given I have opened a new course in Studio + And I go to the course updates page + When I add a new update with the text "" + # Can only do partial text matches because of the quotes with in quotes (and regexp step matching). + Then I should see the update "/c4x/MITx/999/asset/my_img.jpg" + And I change the update from "/static/my_img.jpg" to "" + Then I should see the update "/c4x/MITx/999/asset/modified.jpg" + And when I reload the page + Then I should see the update "/c4x/MITx/999/asset/modified.jpg" + + Scenario: Static links are rewritten when previewing handouts + Given I have opened a new course in Studio + And I go to the course updates page + When I modify the handout to "
" + # Can only do partial text matches because of the quotes with in quotes (and regexp step matching). + Then I see the handout "/c4x/MITx/999/asset/my_img.jpg" + And I change the handout from "/static/my_img.jpg" to "" + Then I see the handout "/c4x/MITx/999/asset/modified.jpg" + And when I reload the page + Then I see the handout "/c4x/MITx/999/asset/modified.jpg" diff --git a/cms/djangoapps/contentstore/features/course-updates.py b/cms/djangoapps/contentstore/features/course-updates.py index f431af9cf5..3278805a48 100644 --- a/cms/djangoapps/contentstore/features/course-updates.py +++ b/cms/djangoapps/contentstore/features/course-updates.py @@ -38,6 +38,16 @@ def modify_update(_step, text): change_text(text) +@step(u'I change the update from "([^"]*)" to "([^"]*)"$') +def change_existing_update(_step, before, after): + verify_text_in_editor_and_update('div.post-preview a.edit-button', before, after) + + +@step(u'I change the handout from "([^"]*)" to "([^"]*)"$') +def change_existing_handout(_step, before, after): + verify_text_in_editor_and_update('div.course-handouts a.edit-button', before, after) + + @step(u'I delete the update$') def click_button(_step): button_css = 'div.post-preview a.delete-button' @@ -80,3 +90,10 @@ def change_text(text): type_in_codemirror(0, text) save_css = 'a.save-button' world.css_click(save_css) + + +def verify_text_in_editor_and_update(button_css, before, after): + world.css_click(button_css) + text = world.css_find(".cm-string").html + assert before in text + change_text(after) diff --git a/cms/djangoapps/contentstore/views/course.py b/cms/djangoapps/contentstore/views/course.py index aad56e4a2e..939286a765 100644 --- a/cms/djangoapps/contentstore/views/course.py +++ b/cms/djangoapps/contentstore/views/course.py @@ -18,6 +18,7 @@ from mitxmako.shortcuts import render_to_response from xmodule.modulestore.django import modulestore from xmodule.modulestore.inheritance import own_metadata +from xmodule.contentstore.content import StaticContent from xmodule.modulestore.exceptions import ( ItemNotFoundError, InvalidLocationError) @@ -206,7 +207,8 @@ def course_info(request, org, course, name, provided_id=None): 'context_course': course_module, 'url_base': "/" + org + "/" + course + "/", 'course_updates': json.dumps(get_course_updates(location)), - 'handouts_location': Location(['i4x', org, course, 'course_info', 'handouts']).url() }) + 'handouts_location': Location(['i4x', org, course, 'course_info', 'handouts']).url(), + 'base_asset_url': StaticContent.get_base_url_path_for_course_assets(location) + '/'}) @expect_json diff --git a/cms/envs/common.py b/cms/envs/common.py index 29e99b2551..3e3b642b36 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -246,7 +246,7 @@ PIPELINE_JS = { 'js/models/metadata_model.js', 'js/views/metadata_editor_view.js', 'js/models/uploads.js', 'js/views/uploads.js', 'js/models/textbook.js', 'js/views/textbook.js', - 'js/views/assets.js', 'js/utility.js', + 'js/views/assets.js', 'js/src/utility.js', 'js/models/settings/course_grading_policy.js'], 'output_filename': 'js/cms-application.js', 'test_order': 0 diff --git a/cms/static/coffee/spec/views/course_info_spec.coffee b/cms/static/coffee/spec/views/course_info_spec.coffee new file mode 100644 index 0000000000..297e78f34a --- /dev/null +++ b/cms/static/coffee/spec/views/course_info_spec.coffee @@ -0,0 +1,144 @@ +courseInfoPage = """ +
+
+
+
    +
    +
    + +
    + """ + +commonSetup = () -> + window.analytics = jasmine.createSpyObj('analytics', ['track']) + window.course_location_analytics = jasmine.createSpy() + window.courseUpdatesXhr = sinon.useFakeXMLHttpRequest() + requests = [] + window.courseUpdatesXhr.onCreate = (xhr) -> requests.push(xhr) + return requests + +commonCleanup = () -> + window.courseUpdatesXhr.restore() + delete window.analytics + delete window.course_location_analytics + +describe "Course Updates", -> + courseInfoTemplate = readFixtures('course_info_update.underscore') + + beforeEach -> + setFixtures($("