From 103cb24a65c8b5262b82e7bfb2dd9a832f21efec Mon Sep 17 00:00:00 2001 From: Ed Schiebel Date: Mon, 19 Jun 2017 14:50:41 -0400 Subject: [PATCH] Automate course searching test the user enters text in the Associations modal search text box, and the UI shows the courses that match on name, short name or sis id closes MC-264 Test plan: - run the test and it passes Change-Id: I859abca242a7fbf396c13bb5c3a28443da3e74c7 Reviewed-on: https://gerrit.instructure.com/116107 Tested-by: Jenkins Reviewed-by: Robert Lamb Product-Review: Robert Lamb QA-Review: Robert Lamb --- spec/selenium/helpers/blueprint_common.rb | 80 ++++++++++++++ .../master_courses/course_picker_spec.rb | 101 ++++++++++++++++++ 2 files changed, 181 insertions(+) create mode 100644 spec/selenium/master_courses/course_picker_spec.rb diff --git a/spec/selenium/helpers/blueprint_common.rb b/spec/selenium/helpers/blueprint_common.rb index 9dfdefb1d09..68356d15989 100644 --- a/spec/selenium/helpers/blueprint_common.rb +++ b/spec/selenium/helpers/blueprint_common.rb @@ -119,4 +119,84 @@ module BlueprintCourseCommon @quiz2.update(due_at: Time.zone.now + 3.days) run_master_course_migration(master) end + + ##### sidebar and associated modal helpers ##### + # open the blueprint sidebar + def open_blueprint_sidebar + f('.blueprint__root .bcs__wrapper .bcs__trigger').click + end + + # open the associations modal + def open_associations + open_blueprint_sidebar + f('#mcSidebarAsscBtn').click # open the associations modal + expect(f('.bcs__modal-content-wrapper')).to be_displayed # the modal is open + end + + # open the course list behind the toggle on the associations modal + # and make sure the data has arrived + # this turned out to be messier than one would think + def open_courses_list + keep_trying = true + try = 0 + while keep_trying && try < 4 # keep clicking the courses button until it opens + try += 1 + begin + f('.bca-course-details__wrapper button').click + f('.bca-table__course-row') + keep_trying = false + rescue + keep_trying = true + end + end + end + + # reutrn the holding the list of avaiable courses + def available_courses_table + f('.bca-table__content-wrapper tbody') + end + + # return the s holding with the current list of available courses + def available_courses + ff('.bca-table__content-wrapper tbody tr.bca-table__course-row') + end + + # return the holding the current associations + def current_associations_table + ff('.bca-associations-table table tbody')[0] + end + + # return the s holding the list of associated courses + def current_associations + current_tbody = current_associations_table + current_courses = ff('tr', current_tbody) + current_courses.shift # shift removes the row with the "current" sub-heading + current_courses + end + + # return the tbody holding the to be added courses + def to_be_added_table + ff('.bca-associations-table table tbody')[1] + end + + # return the s holding the current list of courses to be added as + # children of the current master course + def to_be_added + to_be_tbody = to_be_added_table + to_be_courses = ff('tr', to_be_tbody) + to_be_courses.shift # shift removes the row with the sub-heading + to_be_courses + end + + # return the Done/Save button (which is the last button on the page) + def save_button + buttons = ff('button') + buttons[buttons.length - 1] # last button on the page + end + + # click the Save button and wait for it to complete + def do_save + save_button().click + expect(f('#flash_message_holder')).to contain_css('div') # the alert saying the save completed + end end diff --git a/spec/selenium/master_courses/course_picker_spec.rb b/spec/selenium/master_courses/course_picker_spec.rb new file mode 100644 index 00000000000..8d6686eff0d --- /dev/null +++ b/spec/selenium/master_courses/course_picker_spec.rb @@ -0,0 +1,101 @@ +# +# Copyright (C) 2017 - present Instructure, Inc. +# +# This file is part of Canvas. +# +# Canvas is free software: you can redistribute it and/or modify it under +# the terms of the GNU Affero General Public License as published by the Free +# Software Foundation, version 3 of the License. +# +# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more +# details. +# +# You should have received a copy of the GNU Affero General Public License along +# with this program. If not, see . + +require_relative '../common' +require_relative '../helpers/blueprint_common' + +describe "master courses - course picker" do + include_context "in-process server selenium tests" + include BlueprintCourseCommon + + before :once do + # create the master course + Account.default.enable_feature!(:master_courses) + @master = course_factory(active_all: true) + @template = MasterCourses::MasterTemplate.set_as_master_course(@master) + + # create some courses + c = Course.create!( + :account => @account, :name => "AlphaDog", :course_code => "CCC1", :sis_source_id => "SIS_A1" + ) + c.offer! + c = Course.create!( + :account => @account, :name => "AlphaMale", :course_code => "CCC2", :sis_source_id => "SIS_A2" + ) + c.offer! + c = Course.create!( + :account => @account, :name => "Alphabet", :course_code => "CCC3", :sis_source_id => "SIS_A3" + ) + c.offer! + c = Course.create!( + :account => @account, :name => "BetaCarotine", :course_code => "DDD4", :sis_source_id => "SIS_B4" + ) + c.offer! + c = Course.create!( + :account => @account, :name => "BetaGetOuttaHere", :course_code => "DDD5", :sis_source_id => "SIS_B5" + ) + c.offer! + account_admin_user(active_all: true) + end + + before :each do + user_session(@admin) + end + + let(:course_search_input) {'.bca-course-filter input[type="search"]'} + let(:filter_output) {'.bca-course-details__wrapper'} + let(:loading) {'.bca-course-picker__loading'} + + # enter search term into the filter text box and wait for the response + # this is complicated b the fact that the search api query doesn't happen until + # after the user enters at least 3 chars and stops typing for 200ms, + # then we have to wait for the api response + def test_filter(search_term) + get "/courses/#{@master.id}" + open_associations + open_courses_list + filter = f(course_search_input) + filter.click + filter.send_keys(search_term) # type into the filter text box + expect(f(filter_output)).to contain_css(loading) # the loading spinner appears + expect(f(filter_output)).not_to contain_css(loading) # and disappears + available_courses + end + + it "should show all courses by default", priority: "1", test_id: "3072438" do + get "/courses/#{@master.id}" + open_associations + open_courses_list + expect(available_courses_table).to be_displayed + expect(available_courses().length).to eq(5) + end + + it "should filter the course list by name", priority: "1", test_id: "3072438" do + matches = test_filter('Alpha') + expect(matches.length).to eq(3) + end + + it "should filter the course list by short name", priority: "1", test_id: "3072438" do + matches = test_filter('CCC') + expect(matches.length).to eq(3) + end + + it "should filter the course list by SIS ID", priority: "1", test_id: "3072438" do + matches = test_filter('SIS_B') + expect(matches.length).to eq(2) + end +end