Skip to content

Commit

Permalink
Create multi-tab system spec for add placement wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
Kizr committed Oct 3, 2024
1 parent 8455f5f commit 0f09b7e
Showing 1 changed file with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,61 @@
end
end
end

context "when I use multiple tabs to create placements", :js do
let!(:subject_4) { create(:subject, name: "Primary subject 2", subject_area: :primary) }
let(:windows) do
{
open_new_window => { subject: subject_1.name, mentor: mentor_1, term: summer_term.name },
open_new_window => { subject: subject_4.name, mentor: mentor_2, term: spring_term.name },
}
end

before do
create(:placements_mentor_membership, mentor: mentor_1, school:)
create(:placements_mentor_membership, mentor: mentor_2, school:)
end

it "persists the placement details for each tab upon refresh" do
windows.each do |window, details|
within_window window do
when_i_visit_the_placements_page
and_i_click_on("Add placement")
then_i_see_the_add_a_placement_subject_page(school.phase)
when_i_choose_a_subject(details[:subject])
and_i_click_on("Continue")
then_i_see_the_add_year_group_page("Year 1")
when_i_choose_a_year_group("Year 1")
and_i_click_on("Continue")
then_i_see_the_academic_year_page
when_i_choose_an_academic_year(current_academic_year.name)
and_i_click_on("Continue")
then_i_see_the_add_a_term_page
when_i_check_a_term(details[:term])
and_i_click_on("Continue")
then_i_see_the_add_a_placement_mentor_page
when_i_check_a_mentor(details[:mentor].full_name)
and_i_click_on("Continue")
then_i_see_the_check_your_answers_page(school.phase, details[:mentor], details[:term])
end
end

# We need this test to be A -> B -> A -> B, so we can't combine the loops.
# rubocop:disable Style/CombinableLoops
windows.each do |window, details|
within_window window do
when_i_refresh_the_page
then_the_placement_details_have_not_changed(school.phase, details[:mentor], details[:term])
when_i_click_on("Publish placement")
then_i_see_success_message("Placement published")
end
end
# rubocop:enable Style/CombinableLoops

when_i_refresh_the_page
and_i_see_my_placements(windows.values)
end
end
end

private
Expand Down Expand Up @@ -930,11 +985,25 @@ def then_my_chosen_academic_year_is_selected(academic_year_name)
expect(page).to have_checked_field("This academic year (#{academic_year_name})")
end

def when_i_refresh_the_page
visit current_path
end

def and_i_see_my_placements(placements)
placements.each do |placement|
expect(page).to have_content(placement[:subject])
expect(page).to have_content(placement[:mentor].full_name)
expect(page).to have_content(placement[:term])
end
end

alias_method :and_i_click_on, :when_i_click_on
alias_method :and_i_choose_the_subject, :when_i_choose_a_subject
alias_method :and_i_check_the_subject, :when_i_check_a_subject
alias_method :then_my_chosen_subject_is_selected, :and_my_chosen_subject_is_selected
alias_method :then_my_chosen_mentor_is_checked, :and_my_chosen_mentor_is_checked
alias_method :then_my_chosen_year_group_is_selected, :and_my_chosen_year_group_is_selected
alias_method :then_my_chosen_term_is_checked, :and_my_chosen_term_is_checked
alias_method :then_the_placement_details_have_not_changed, :then_i_see_the_check_your_answers_page
alias_method :then_i_see_success_message, :and_i_see_success_message
end

0 comments on commit 0f09b7e

Please sign in to comment.