<NME> course_creation_spec.rb
<BEF> # frozen_string_literal: true

require 'rails_helper'

def interact_with_clone_form
  fill_in 'Course term:', with: 'Spring 2016'
  fill_in 'Course description:', with: 'A new course'

  find('.course_start-datetime-control input').set(course.start)
  find('.course_end-datetime-control input').set(course.end)

  within('.wizard__form') { click_button 'Save New Course' }

  within('.sidebar') { expect(page).to have_content(term) }
  within('.primary') { expect(page).to have_content(desc) }

  click_button 'Save This Course'
end

def go_through_course_dates_and_timeline_dates
  find('span[title="Wednesday"]', match: :first).click
  within('.wizard__panel.active') do
    expect(page).to have_css('button.dark[disabled=""]')
  end
  find('.wizard__form.course-dates input[type=checkbox]', match: :first).set(true)
  within('.wizard__panel.active') do
    expect(page).not_to have_css('button.dark[disabled=disabled]')
  end

  click_button 'Next'
  sleep 1
end

def go_through_researchwrite_wizard
  go_through_course_dates_and_timeline_dates

  # Choose researchwrite option
  find('.wizard__option', match: :first).find('button', match: :first).click
  click_button 'Next'
  sleep 1

  # Click through the offered choices
  find('.wizard__option', match: :first).find('button', match: :first).click # Training not graded
  click_button 'Next'
  sleep 1

  click_button 'Next' # Default getting started options
  sleep 1

  # Working in groups
  find('.wizard__option', match: :first).find('button', match: :first).click
  click_button 'Next'
  sleep 1

  # Instructor prepares list
  find('.wizard__option', match: :first).find('button', match: :first).click
  click_button 'Next'
  sleep 1

  find('.wizard__option', match: :first).find('button', match: :first).click # Yes, medical articles
  click_button 'Next'
  sleep 1

  # Choose the first handout
  omniclick find('.wizard__option', match: :first).find('button', match: :first)
  click_button 'Next'
  sleep 1

  click_button 'Next' # Default 2 peer reviews
  sleep 1

  click_button 'Next' # Default 3 discussions
  sleep 1

  click_button 'Next' # No supplementary assignments
  sleep 1

  # DYK/GA option removed for ~Spring 2021
  # click_button 'Next' # No DYK/GA
  # sleep 1

  ####################################
  # Fall 2020 supplemental questions #
  ####################################
  # contribute substantially
  omniclick find('.wizard__option', match: :first).find('button', match: :first)
  click_button 'Next'
  sleep 1
  # only assignment
  omniclick find('.wizard__option', match: :first).find('button', match: :first)
  click_button 'Next'
  sleep 1
  # # sandboxes unacceptable
  # omniclick find('.wizard__option', match: :first).find('button', match: :first)
  # click_button 'Next'
  sleep 1

  click_button 'Generate Timeline'
  sleep 1
end

describe 'New course creation and editing', type: :feature do
  before do
    page.current_window.resize_to(1920, 1080)
    TrainingModule.load_all
    stub_oauth_edit

    user = create(:user,
                  id: 1,
                  permissions: User::Permissions::INSTRUCTOR)
    create(:training_modules_users, user_id: user.id,
                                    training_module_id: 3,
                                    completed_at: Time.zone.now)
    login_as(user, scope: :user)

    visit root_path
  end

  after do
    logout
  end

  describe 'course workflow', js: true do
    let(:expected_course_blocks) { 21 }
    let(:module_name) { 'Get started on Wikipedia' }

    it 'allows the user to create a course' do
      allow_any_instance_of(User).to receive(:returning_instructor?).and_return(true)
      click_link 'Create Course'

      expect(page).to have_content 'Create a New Course'
      find('#course_title').set('My awesome new course - Foo 101')

      click_button 'Next'

      # If we click before filling out all require fields, only the invalid
      # fields get restyled to indicate the problem.
      expect(find('#course_title')['class']).not_to include('invalid title')
      expect(find('#course_school')['class']).to include('invalid school')
      expect(find('#course_term')['class']).to include('invalid term')

      # Now we fill out all the fields and continue.
      find('#course_school').set('University of Wikipedia, East Campus')
      find('#course_term').set('Fall 2015')

      find('#course_subject').click
      within '#course_subject' do
        all('div', text: 'Chemistry')[2].click
      end
      find('#course_expected_students').set('500')
      find('#course_level').click
      within '#course_level' do
        all('div', text: 'Introductory')[2].click
      end
      find('#course_format').click
      within '#course_format' do
        all('div', text: 'In-person')[2].click
      end
      find('#course_description').set('In this course, we study things.')
      click_button 'Next'

      start_date = '2015-01-01'
      end_date = '2015-12-15'
      find('.course_start-datetime-control input').set(start_date)
      find('div.DayPicker-Day--selected', text: '1').click
      find('.course_end-datetime-control input').set('2015-12-01')
      find('div.DayPicker-Day', text: '15').click

      sleep 1

      # This click should create the course and start the wizard
      click_button 'Create my Course!'

      # Go through the wizard, checking necessary options.

      # This is the course dates screen
      sleep 3
      # validate either blackout date chosen
      # or "no blackout dates" checkbox checked
      expect(page).to have_css('button.dark[disabled=""]')
      start_input = find('input.start', match: :first).value
      sleep 1
      expect(start_input.to_date).to be_within(1.day).of(start_date.to_date)
      end_input = find('input.end', match: :first).value
      expect(end_input.to_date).to be_within(1.day).of(end_date.to_date)

      # capybara doesn't like trying to click the calendar
      # to set a blackout date
      go_through_course_dates_and_timeline_dates

      # This is the assignment type chooser
      # Translation assignment
      page.all('.wizard__option')[2].first('button').click
      sleep 1
      click_button 'Next'
      sleep 1
      click_button 'Yes, training will be graded.'
      click_button 'Next'

      # Choosing articles
      sleep 1
      page.all('div.wizard__option')[0].click # Instructor prepares list
      click_button 'Next'

      # Optional assignment
      sleep 1
      click_button 'Do not include fact-checking assignment'
      click_button 'Next'

      # on the summary
      sleep 1
      # go back and change a choice
      page.all('button.wizard__option.summary')[2].click
      sleep 1
      click_button 'No, training will not be graded.'
      sleep 1
      click_button 'Summary'
      sleep 1
      click_button 'Generate Timeline'

      # Now we're back at the timeline, having completed the wizard.
      sleep 1
      expect(page).to have_content 'Week 1'
      expect(page).to have_content 'Week 2'

      # Edit course dates and save
      click_link 'Edit Course Dates'
      find('span[title="Thursday"]', match: :first).click
      click_link 'Done'
      sleep 1
      expect(Course.last.weekdays).to eq('0001100')

      within('.week-1 .week__week-add-delete') do
        accept_confirm do
          find('.week__delete-week').click
        end
      end

      # There should now be 4 weeks
      expect(page).not_to have_content 'Week 5'

      # Now check that the course form selections went through
      saved_course = Course.last
      expect(saved_course.level).to eq('Introductory')
      expect(saved_course.subject).to eq('Chemistry')
      expect(saved_course.format).to eq('In-person')
    end

    it 'does not allow a second course with the same slug' do
      create(:course,
             id: 10001,
             title: 'Course',
             school: 'University',
             term: 'Term',
             slug: 'University/Course_(Term)',
             submitted: false,
             passcode: 'passcode',
             start: '2015-08-24'.to_date,
             end: '2015-12-15'.to_date,
             timeline_start: '2015-08-31'.to_date,
             timeline_end: '2015-12-15'.to_date)

      click_link 'Create Course'
      expect(page).to have_content 'Create a New Course'
      find('#course_title').set('Course')
      find('#course_school').set('University')
      find('#course_term').set('Term')
      find('#course_subject').set('Advanced Studies')
      find('#course_expected_students').set('15')
      find('#course_description').set('My course')
      click_button 'Next'

      start_date = '2015-01-01'
      end_date = '2015-12-15'
      find('#course_start').set(start_date)
      find('#course_end').set(end_date)
      find('div.wizard__panel').click # click to escape the calendar popup

      # This click should not successfully create a course.
      click_button 'Create my Course!'
      expect(page).to have_content 'This course already exists'
      expect(Course.all.count).to eq(1)
    end

    it 'creates a full-length research-write assignment' do
      create(:course,
             id: 10001,
             title: 'Course',
             school: 'University',
             term: 'Term',
             slug: 'University/Course_(Term)',
             submitted: false,
             passcode: 'passcode',
             start: '2015-08-24'.to_date,
             end: '2015-12-15'.to_date,
             timeline_start: '2015-08-31'.to_date,
             timeline_end: '2015-12-15'.to_date)
      create(:courses_user,
             user_id: 1,
             course_id: 10001,
             role: 1)

      # Visit timline and open wizard
      visit "/courses/#{Course.first.slug}/timeline/wizard"
      sleep 1

      go_through_researchwrite_wizard

      sleep 1

      expect(page).to have_content 'Week 12'

      # Now submit the course
      accept_confirm do
        first('a.button').click
      end
      expect(page).to have_content 'Your course has been successfully submitted.'

      Course.last.weeks.each_with_index do |week, i|
        expect(week.order).to eq(i + 1)
      end
      expect(Course.first.blocks.count).to eq(expected_course_blocks)
    end

    it 'squeezes assignments into the course dates' do
      create(:course,
             id: 10001,
             title: 'Course',
             school: 'University',
             term: 'Term',
             slug: 'University/Course_(Term)',
             submitted: false,
             passcode: 'passcode',
             start: '2015-09-01'.to_date,
             end: '2015-10-09'.to_date,
             timeline_start: '2015-08-31'.to_date, # covers six calendar weeks
             timeline_end: '2015-10-09'.to_date)
      create(:courses_user,
             user_id: 1,
             course_id: 10001,
             role: 1)

      # Visit timline and open wizard
      visit "/courses/#{Course.first.slug}/timeline/wizard"
      sleep 1

      go_through_researchwrite_wizard

      expect(page).to have_content 'Week 6'
      expect(page).not_to have_content 'Week 7'
      expect(Course.first.blocks.count).to eq(expected_course_blocks)

      within '.week-1' do
        expect(page).to have_content module_name
      end
    end
  end
end

      # Finish the wizard
      click_button 'Generate Timeline'
      expect(page).to have_content 'Add Assignment'
      sleep 1

      # Add a week
        find('.week-nav__add-week').click
      end
      sleep 1
      page.save_screenshot
      within '.timeline__weeks' do
        expect(page).to have_content 'Week 1'
        find('.week__add-block').click

<MSG> Make sure no empty timeline courses are submitted

Resolves #1144

<DFF> @@ -381,7 +381,8 @@ describe 'New course creation and editing', type: :feature do
 
       # Finish the wizard
       click_button 'Generate Timeline'
-      expect(page).to have_content 'Add Assignment'
+      expect(page).to have_content 'Launch the Wizard' # 'no timeline' banner above the Timeline
+      expect(page).to have_content 'Add Assignment' # Button in the Timeline
       sleep 1
 
       # Add a week
@@ -389,7 +390,6 @@ describe 'New course creation and editing', type: :feature do
         find('.week-nav__add-week').click
       end
       sleep 1
-      page.save_screenshot
       within '.timeline__weeks' do
         expect(page).to have_content 'Week 1'
         find('.week__add-block').click

{'commit': 'diff --git a/app/assets/javascripts/components/course.jsx b/app/assets/javascripts/components/course.jsx\nindex 8c85d46d8..477264066 100644\n--- a/app/assets/javascripts/components/course.jsx\n+++ b/app/assets/javascripts/components/course.jsx\n@@ -6,6 +6,7 @@ import CourseActions from \'../actions/course_actions.js\';\n import CourseStore from \'../stores/course_store.js\';\n import UserStore from \'../stores/user_store.js\';\n import NotificationStore from \'../stores/notification_store.js\';\n+import WeekStore from \'../stores/week_store.js\';\n import Affix from \'./common/affix.jsx\';\n import CourseUtils from \'../utils/course_utils.js\';\n import GetHelpButton from \'../components/common/get_help_button.jsx\';\n@@ -16,7 +17,8 @@ const getState = function () {\n   const cu = UserStore.getFiltered({ id: current.id })[0];\n   return {\n     course: CourseStore.getCourse(),\n-    current_user: cu || current\n+    current_user: cu || current,\n+    weeks: WeekStore.getWeeks()\n   };\n };\n \n@@ -29,7 +31,7 @@ const Course = React.createClass({\n     children: React.PropTypes.node\n   },\n \n-  mixins: [CourseStore.mixin, UserStore.mixin, NotificationStore.mixin],\n+  mixins: [CourseStore.mixin, UserStore.mixin, NotificationStore.mixin, WeekStore.mixin],\n \n   getInitialState() {\n     return getState();\n@@ -115,20 +117,39 @@ const Course = React.createClass({\n     // //////////////////////////////////\n     // Admin / Instructor notifications /\n     // //////////////////////////////////\n+\n+    // For unpublished courses, when viewed by an instructor or admin\n     if ((userRole > 0 || this.state.current_user.admin) && !this.state.course.legacy && !this.state.course.published) {\n+      // If it\'s an unsubmitted ClassroomProgramCourse\n       if (CourseStore.isLoaded() && !(this.state.course.submitted || this.state.published) && this.state.course.type === \'ClassroomProgramCourse\') {\n-        alerts.push((\n-          <div className="notification" key="submit">\n-            <div className="container">\n-              <p>{I18n.t(\'courses.review_timeline\')}</p>\n-              <a href="#" onClick={this.submit} className="button">{I18n.t(\'application.submit\')}</a>\n+        // Show submit button if there is a timeline, or user is admin.\n+        if (this.state.weeks.length || this.state.current_user.admin) {\n+          alerts.push((\n+            <div className="notification" key="submit">\n+              <div className="container">\n+                <p>{I18n.t(\'courses.review_timeline\')}</p>\n+                <a href="#" onClick={this.submit} className="button">{I18n.t(\'application.submit\')}</a>\n+              </div>\n             </div>\n-          </div>\n-        )\n-        );\n+          )\n+          );\n+        // Show \'create a timeline\' message if there is no timeline.\n+        } else {\n+          alerts.push((\n+            <div className="notification" key="submit">\n+              <div className="container">\n+                <p>Please create a timeline for your course. You can build one from scratch from the Timeline tab, or use the Assignment Wizard to create a custom timeline based on Wiki Ed\'s best practices.</p>\n+                <a href={`${this._courseLinkParams()}/timeline`} className="button">Launch the Wizard</a>\n+              </div>\n+            </div>\n+          )\n+          );\n+        }\n       }\n \n+      // When the course has been submitted\n       if (this.state.course.submitted) {\n+        // Show instructors the \'submitted\' notice.\n         if (!this.state.current_user.admin) {\n           alerts.push((\n             <div className="notification" key="submit">\n@@ -138,6 +159,7 @@ const Course = React.createClass({\n             </div>\n           )\n           );\n+        // Instruct admins to approve the course by adding a campaign.\n         } else {\n           const homeLink = `${this._courseLinkParams()}/home`;\n           alerts.push((\n@@ -153,6 +175,7 @@ const Course = React.createClass({\n       }\n     }\n \n+    // For published courses with no students, highlight the enroll link\n     if ((userRole > 0 || this.state.current_user.admin) && this.state.course.published && UserStore.isLoaded() && UserStore.getFiltered({ role: 0 }).length === 0 && !this.state.course.legacy) {\n       const enrollEquals = \'?enroll=\';\n       const url = window.location.origin + this._courseLinkParams() + enrollEquals + this.state.course.passcode;\ndiff --git a/spec/features/course_creation_spec.rb b/spec/features/course_creation_spec.rb\nindex b865b80ef..e2339c284 100644\n--- a/spec/features/course_creation_spec.rb\n+++ b/spec/features/course_creation_spec.rb\n@@ -381,7 +381,8 @@ describe \'New course creation and editing\', type: :feature do\n \n       # Finish the wizard\n       click_button \'Generate Timeline\'\n-      expect(page).to have_content \'Add Assignment\'\n+      expect(page).to have_content \'Launch the Wizard\' # \'no timeline\' banner above the Timeline\n+      expect(page).to have_content \'Add Assignment\' # Button in the Timeline\n       sleep 1\n \n       # Add a week\n@@ -389,7 +390,6 @@ describe \'New course creation and editing\', type: :feature do\n         find(\'.week-nav__add-week\').click\n       end\n       sleep 1\n-      page.save_screenshot\n       within \'.timeline__weeks\' do\n         expect(page).to have_content \'Week 1\'\n         find(\'.week__add-block\').click\n', 'commit_subject': 'Make sure no empty timeline courses are submitted', 'repo_name': 'WikiEducationFoundation/WikiEduDashboard', 'committer': {'name': 'Sage Ross', 'email': '0bc9f67b2b08dbd979104ac630343507d3de0edf@gmail.com', 'time_sec': '1487282217', 'tz_offset': '-480', 'date': {'seconds': '1487282217'}}, 'commit_tree': '93613cd35eafa130965f06f61de4d3cd183685a9', 'commit_message': 'Make sure no empty timeline courses are submitted\n\nResolves #1144\n', 'language_name': 'HTML', 'license': 'mit', 'hunks': "@@ -381,7 +381,8 @@ describe 'New course creation and editing', type: :feature do\n \n       # Finish the wizard\n       click_button 'Generate Timeline'\n-      expect(page).to have_content 'Add Assignment'\n+      expect(page).to have_content 'Launch the Wizard' # 'no timeline' banner above the Timeline\n+      expect(page).to have_content 'Add Assignment' # Button in the Timeline\n       sleep 1\n \n       # Add a week\n@@ -389,7 +390,6 @@ describe 'New course creation and editing', type: :feature do\n         find('.week-nav__add-week').click\n       end\n       sleep 1\n-      page.save_screenshot\n       within '.timeline__weeks' do\n         expect(page).to have_content 'Week 1'\n         find('.week__add-block').click\n", 'addition_count': 2, 'deletion_count': 2, 'src_file': 'a/spec/features/course_creation_spec.rb', 'tgt_file': 'b/spec/features/course_creation_spec.rb', 'file_extension': '.rb', 'before_file': '# frozen_string_literal: true\n\nrequire \'rails_helper\'\n\ndef interact_with_clone_form\n  fill_in \'Course term:\', with: \'Spring 2016\'\n  fill_in \'Course description:\', with: \'A new course\'\n\n  find(\'.course_start-datetime-control input\').set(course.start)\n  find(\'.course_end-datetime-control input\').set(course.end)\n\n  within(\'.wizard__form\') { click_button \'Save New Course\' }\n\n  within(\'.sidebar\') { expect(page).to have_content(term) }\n  within(\'.primary\') { expect(page).to have_content(desc) }\n\n  click_button \'Save This Course\'\nend\n\ndef go_through_course_dates_and_timeline_dates\n  find(\'span[title="Wednesday"]\', match: :first).click\n  within(\'.wizard__panel.active\') do\n    expect(page).to have_css(\'button.dark[disabled=""]\')\n  end\n  find(\'.wizard__form.course-dates input[type=checkbox]\', match: :first).set(true)\n  within(\'.wizard__panel.active\') do\n    expect(page).not_to have_css(\'button.dark[disabled=disabled]\')\n  end\n\n  click_button \'Next\'\n  sleep 1\nend\n\ndef go_through_researchwrite_wizard\n  go_through_course_dates_and_timeline_dates\n\n  # Choose researchwrite option\n  find(\'.wizard__option\', match: :first).find(\'button\', match: :first).click\n  click_button \'Next\'\n  sleep 1\n\n  # Click through the offered choices\n  find(\'.wizard__option\', match: :first).find(\'button\', match: :first).click # Training not graded\n  click_button \'Next\'\n  sleep 1\n\n  click_button \'Next\' # Default getting started options\n  sleep 1\n\n  # Working in groups\n  find(\'.wizard__option\', match: :first).find(\'button\', match: :first).click\n  click_button \'Next\'\n  sleep 1\n\n  # Instructor prepares list\n  find(\'.wizard__option\', match: :first).find(\'button\', match: :first).click\n  click_button \'Next\'\n  sleep 1\n\n  find(\'.wizard__option\', match: :first).find(\'button\', match: :first).click # Yes, medical articles\n  click_button \'Next\'\n  sleep 1\n\n  # Choose the first handout\n  omniclick find(\'.wizard__option\', match: :first).find(\'button\', match: :first)\n  click_button \'Next\'\n  sleep 1\n\n  click_button \'Next\' # Default 2 peer reviews\n  sleep 1\n\n  click_button \'Next\' # Default 3 discussions\n  sleep 1\n\n  click_button \'Next\' # No supplementary assignments\n  sleep 1\n\n  # DYK/GA option removed for ~Spring 2021\n  # click_button \'Next\' # No DYK/GA\n  # sleep 1\n\n  ####################################\n  # Fall 2020 supplemental questions #\n  ####################################\n  # contribute substantially\n  omniclick find(\'.wizard__option\', match: :first).find(\'button\', match: :first)\n  click_button \'Next\'\n  sleep 1\n  # only assignment\n  omniclick find(\'.wizard__option\', match: :first).find(\'button\', match: :first)\n  click_button \'Next\'\n  sleep 1\n  # # sandboxes unacceptable\n  # omniclick find(\'.wizard__option\', match: :first).find(\'button\', match: :first)\n  # click_button \'Next\'\n  sleep 1\n\n  click_button \'Generate Timeline\'\n  sleep 1\nend\n\ndescribe \'New course creation and editing\', type: :feature do\n  before do\n    page.current_window.resize_to(1920, 1080)\n    TrainingModule.load_all\n    stub_oauth_edit\n\n    user = create(:user,\n                  id: 1,\n                  permissions: User::Permissions::INSTRUCTOR)\n    create(:training_modules_users, user_id: user.id,\n                                    training_module_id: 3,\n                                    completed_at: Time.zone.now)\n    login_as(user, scope: :user)\n\n    visit root_path\n  end\n\n  after do\n    logout\n  end\n\n  describe \'course workflow\', js: true do\n    let(:expected_course_blocks) { 21 }\n    let(:module_name) { \'Get started on Wikipedia\' }\n\n    it \'allows the user to create a course\' do\n      allow_any_instance_of(User).to receive(:returning_instructor?).and_return(true)\n      click_link \'Create Course\'\n\n      expect(page).to have_content \'Create a New Course\'\n      find(\'#course_title\').set(\'My awesome new course - Foo 101\')\n\n      click_button \'Next\'\n\n      # If we click before filling out all require fields, only the invalid\n      # fields get restyled to indicate the problem.\n      expect(find(\'#course_title\')[\'class\']).not_to include(\'invalid title\')\n      expect(find(\'#course_school\')[\'class\']).to include(\'invalid school\')\n      expect(find(\'#course_term\')[\'class\']).to include(\'invalid term\')\n\n      # Now we fill out all the fields and continue.\n      find(\'#course_school\').set(\'University of Wikipedia, East Campus\')\n      find(\'#course_term\').set(\'Fall 2015\')\n\n      find(\'#course_subject\').click\n      within \'#course_subject\' do\n        all(\'div\', text: \'Chemistry\')[2].click\n      end\n      find(\'#course_expected_students\').set(\'500\')\n      find(\'#course_level\').click\n      within \'#course_level\' do\n        all(\'div\', text: \'Introductory\')[2].click\n      end\n      find(\'#course_format\').click\n      within \'#course_format\' do\n        all(\'div\', text: \'In-person\')[2].click\n      end\n      find(\'#course_description\').set(\'In this course, we study things.\')\n      click_button \'Next\'\n\n      start_date = \'2015-01-01\'\n      end_date = \'2015-12-15\'\n      find(\'.course_start-datetime-control input\').set(start_date)\n      find(\'div.DayPicker-Day--selected\', text: \'1\').click\n      find(\'.course_end-datetime-control input\').set(\'2015-12-01\')\n      find(\'div.DayPicker-Day\', text: \'15\').click\n\n      sleep 1\n\n      # This click should create the course and start the wizard\n      click_button \'Create my Course!\'\n\n      # Go through the wizard, checking necessary options.\n\n      # This is the course dates screen\n      sleep 3\n      # validate either blackout date chosen\n      # or "no blackout dates" checkbox checked\n      expect(page).to have_css(\'button.dark[disabled=""]\')\n      start_input = find(\'input.start\', match: :first).value\n      sleep 1\n      expect(start_input.to_date).to be_within(1.day).of(start_date.to_date)\n      end_input = find(\'input.end\', match: :first).value\n      expect(end_input.to_date).to be_within(1.day).of(end_date.to_date)\n\n      # capybara doesn\'t like trying to click the calendar\n      # to set a blackout date\n      go_through_course_dates_and_timeline_dates\n\n      # This is the assignment type chooser\n      # Translation assignment\n      page.all(\'.wizard__option\')[2].first(\'button\').click\n      sleep 1\n      click_button \'Next\'\n      sleep 1\n      click_button \'Yes, training will be graded.\'\n      click_button \'Next\'\n\n      # Choosing articles\n      sleep 1\n      page.all(\'div.wizard__option\')[0].click # Instructor prepares list\n      click_button \'Next\'\n\n      # Optional assignment\n      sleep 1\n      click_button \'Do not include fact-checking assignment\'\n      click_button \'Next\'\n\n      # on the summary\n      sleep 1\n      # go back and change a choice\n      page.all(\'button.wizard__option.summary\')[2].click\n      sleep 1\n      click_button \'No, training will not be graded.\'\n      sleep 1\n      click_button \'Summary\'\n      sleep 1\n      click_button \'Generate Timeline\'\n\n      # Now we\'re back at the timeline, having completed the wizard.\n      sleep 1\n      expect(page).to have_content \'Week 1\'\n      expect(page).to have_content \'Week 2\'\n\n      # Edit course dates and save\n      click_link \'Edit Course Dates\'\n      find(\'span[title="Thursday"]\', match: :first).click\n      click_link \'Done\'\n      sleep 1\n      expect(Course.last.weekdays).to eq(\'0001100\')\n\n      within(\'.week-1 .week__week-add-delete\') do\n        accept_confirm do\n          find(\'.week__delete-week\').click\n        end\n      end\n\n      # There should now be 4 weeks\n      expect(page).not_to have_content \'Week 5\'\n\n      # Now check that the course form selections went through\n      saved_course = Course.last\n      expect(saved_course.level).to eq(\'Introductory\')\n      expect(saved_course.subject).to eq(\'Chemistry\')\n      expect(saved_course.format).to eq(\'In-person\')\n    end\n\n    it \'does not allow a second course with the same slug\' do\n      create(:course,\n             id: 10001,\n             title: \'Course\',\n             school: \'University\',\n             term: \'Term\',\n             slug: \'University/Course_(Term)\',\n             submitted: false,\n             passcode: \'passcode\',\n             start: \'2015-08-24\'.to_date,\n             end: \'2015-12-15\'.to_date,\n             timeline_start: \'2015-08-31\'.to_date,\n             timeline_end: \'2015-12-15\'.to_date)\n\n      click_link \'Create Course\'\n      expect(page).to have_content \'Create a New Course\'\n      find(\'#course_title\').set(\'Course\')\n      find(\'#course_school\').set(\'University\')\n      find(\'#course_term\').set(\'Term\')\n      find(\'#course_subject\').set(\'Advanced Studies\')\n      find(\'#course_expected_students\').set(\'15\')\n      find(\'#course_description\').set(\'My course\')\n      click_button \'Next\'\n\n      start_date = \'2015-01-01\'\n      end_date = \'2015-12-15\'\n      find(\'#course_start\').set(start_date)\n      find(\'#course_end\').set(end_date)\n      find(\'div.wizard__panel\').click # click to escape the calendar popup\n\n      # This click should not successfully create a course.\n      click_button \'Create my Course!\'\n      expect(page).to have_content \'This course already exists\'\n      expect(Course.all.count).to eq(1)\n    end\n\n    it \'creates a full-length research-write assignment\' do\n      create(:course,\n             id: 10001,\n             title: \'Course\',\n             school: \'University\',\n             term: \'Term\',\n             slug: \'University/Course_(Term)\',\n             submitted: false,\n             passcode: \'passcode\',\n             start: \'2015-08-24\'.to_date,\n             end: \'2015-12-15\'.to_date,\n             timeline_start: \'2015-08-31\'.to_date,\n             timeline_end: \'2015-12-15\'.to_date)\n      create(:courses_user,\n             user_id: 1,\n             course_id: 10001,\n             role: 1)\n\n      # Visit timline and open wizard\n      visit "/courses/#{Course.first.slug}/timeline/wizard"\n      sleep 1\n\n      go_through_researchwrite_wizard\n\n      sleep 1\n\n      expect(page).to have_content \'Week 12\'\n\n      # Now submit the course\n      accept_confirm do\n        first(\'a.button\').click\n      end\n      expect(page).to have_content \'Your course has been successfully submitted.\'\n\n      Course.last.weeks.each_with_index do |week, i|\n        expect(week.order).to eq(i + 1)\n      end\n      expect(Course.first.blocks.count).to eq(expected_course_blocks)\n    end\n\n    it \'squeezes assignments into the course dates\' do\n      create(:course,\n             id: 10001,\n             title: \'Course\',\n             school: \'University\',\n             term: \'Term\',\n             slug: \'University/Course_(Term)\',\n             submitted: false,\n             passcode: \'passcode\',\n             start: \'2015-09-01\'.to_date,\n             end: \'2015-10-09\'.to_date,\n             timeline_start: \'2015-08-31\'.to_date, # covers six calendar weeks\n             timeline_end: \'2015-10-09\'.to_date)\n      create(:courses_user,\n             user_id: 1,\n             course_id: 10001,\n             role: 1)\n\n      # Visit timline and open wizard\n      visit "/courses/#{Course.first.slug}/timeline/wizard"\n      sleep 1\n\n      go_through_researchwrite_wizard\n\n      expect(page).to have_content \'Week 6\'\n      expect(page).not_to have_content \'Week 7\'\n      expect(Course.first.blocks.count).to eq(expected_course_blocks)\n\n      within \'.week-1\' do\n        expect(page).to have_content module_name\n      end\n    end\n  end\nend\n\n      # Finish the wizard\n      click_button \'Generate Timeline\'\n      expect(page).to have_content \'Add Assignment\'\n      sleep 1\n\n      # Add a week\n        find(\'.week-nav__add-week\').click\n      end\n      sleep 1\n      page.save_screenshot\n      within \'.timeline__weeks\' do\n        expect(page).to have_content \'Week 1\'\n        find(\'.week__add-block\').click\n', 'message': 'Make sure no empty timeline courses are submitted\n\nResolves #1144\n', 'author_name': 'Sage Ross', 'lang': 'rb'}