From 8a3db8fd48b30fd14aceb3998900b0e82a26d48a Mon Sep 17 00:00:00 2001 From: Maya Tyner Date: Wed, 10 Jul 2024 16:00:18 -0600 Subject: [PATCH] spec: add selenium testing for temporary enrollments temporary enrollments has lots of nested components/api calls that make thorough unit testing difficult. replacing some unit tests with selenium should make testing more comprehensive. also added temporary enrollment columns to enrollment factory to make future testing easier closes FOO-3992 flag=none test-plan: - pass new and current tests Change-Id: I44023681a1201865d0039bb2441922a4bc657fd7 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/352420 Tested-by: Service Cloud Jenkins Reviewed-by: August Thornton QA-Review: Maya Tyner Product-Review: Maya Tyner --- spec/factories/enrollment_factory.rb | 12 +- .../enrollment/temporary_enrollment_spec.rb | 131 ++++++++++++++++++ 2 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 spec/selenium/enrollment/temporary_enrollment_spec.rb diff --git a/spec/factories/enrollment_factory.rb b/spec/factories/enrollment_factory.rb index a414256026d..c2f2f877ebc 100644 --- a/spec/factories/enrollment_factory.rb +++ b/spec/factories/enrollment_factory.rb @@ -67,6 +67,14 @@ module Factories section_id = options[:section_id] || options[:section].try(:id) || course.default_section.id type = options[:enrollment_type] || "StudentEnrollment" role_id = options[:role].try(:id) || Role.get_built_in_role(type, root_account_id: course.root_account_id).id + + source_user_id = options[:temporary_enrollment_source_user_id] || nil + pairing_hash = {} + if source_user_id + pairing = create_records(TemporaryEnrollmentPairing, user_ids.map { { root_account_id: course.account_id, ending_enrollment_state: "deleted", created_at: now, updated_at: now } }) + user_ids.each_with_index { |id, index| pairing_hash[id] = pairing[index] } + end + result = create_records(Enrollment, user_ids.map do |id| { @@ -81,7 +89,9 @@ module Factories associated_user_id:, limit_privileges_to_course_section:, created_at: now, - updated_at: now + updated_at: now, + temporary_enrollment_source_user_id: source_user_id, + temporary_enrollment_pairing_id: pairing_hash[id] } end, options[:return_type]) diff --git a/spec/selenium/enrollment/temporary_enrollment_spec.rb b/spec/selenium/enrollment/temporary_enrollment_spec.rb new file mode 100644 index 00000000000..91bd9949a6e --- /dev/null +++ b/spec/selenium/enrollment/temporary_enrollment_spec.rb @@ -0,0 +1,131 @@ +# frozen_string_literal: true + +# +# Copyright (C) 2024 - 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" + +describe "temporary enrollment" do + include_context "in-process server selenium tests" + + before do + Account.default.enable_feature!(:temporary_enrollments) + @teacher = user_factory(name: "teacher") + @teacher.register! + @course = course_with_teacher({ user: @teacher, active_course: true, active_enrollment: true }).course + + user_with_pseudonym(name: "temp_teacher", active_user: true, username: "tempTeacher", account: Account.default) + @temp_teacher = User.find_by(name: "temp_teacher") + + admin_logged_in + end + + def can_provide + f("button[data-analytics='TempEnrollIconCalendarClockLine']") + end + + def is_provider + f("button[data-analytics='TempEnrollIconCalendarClockSolid']") + end + + def is_recipient + f("button[data-analytics='TempEnrollIconCalendarReservedSolid']") + end + + def load_people_page + get "/accounts/#{Account.default.id}/users" + end + + # nearly every page of the modal requires an api call, so we wait before interacting with each + it "creates pairing" do + # open modal + load_people_page + wait_for_ajax_requests + can_provide.click + + # search for user + f("[for='peoplesearch_radio_unique_id']").click + f("input[data-analytics='TempEnrollTextInput']").send_keys("tempTeacher") + f("button[data-analytics='TempEnrollNext']").click + + # successfully got user + expect(f("body")).not_to contain_css("svg[role='img'] circle") + expect(f("svg[name='IconCheckMark']")).to be_displayed + expect(f("span[alt='Avatar for #{@temp_teacher.name}']")).to be_displayed + f("button[data-analytics='TempEnrollNext']").click + + # create user + f("button[data-analytics='TempEnrollSubmit']").click + + # expect icons to reflect temp enrollment + load_people_page + wait_for_ajax_requests + expect(is_recipient).to be_displayed + # displayed in the recipient's row since temp enrolls can chain + expect(can_provide).to be_displayed + end + + context "modify" do + before do + @temp_enrollment = create_enrollment(@course, @temp_teacher, temporary_enrollment_source_user_id: @teacher.id) + end + + it "deletes existing pairing from provider view" do + load_people_page + + # open modal + wait_for_ajax_requests + is_provider.click + + # delete enrollment + expect(f("body")).not_to contain_css("svg[role='img'] circle") + f("button[data-analytics='TempEnrollDelete']").click + accept_alert + + # expect no recipient/provider icons + load_people_page + wait_for_ajax_requests + expect(can_provide).to be_displayed + expect(f("body")).not_to contain_css("button[data-analytics='TempEnrollIconCalendarClockSolid']") + expect(f("body")).not_to contain_css("button[data-analytics='TempEnrollIconCalendarReservedSolid']") + end + + it "edits existing pairing from recipient view" do + load_people_page + + # open modal + wait_for_ajax_requests + is_recipient.click + + # edit enrollment + expect(f("body")).not_to contain_css("svg[role='img'] circle") + f("button[data-analytics='TempEnrollEdit']").click + + # change role to Designer and save + f("input[data-analytics='TempEnrollRole']").click + f("span[label='Designer']").click + f("button[data-analytics='TempEnrollSubmit']").click + + # reopen modal to confirm change + load_people_page + wait_for_ajax_requests + is_recipient.click + expect(f("body")).not_to contain_css("svg[role='img'] circle") + expect(fj("span[role='dialog']:contains('DesignerEnrollment')")).to be_displayed + end + end +end