Skip to content

Commit

Permalink
Add specs
Browse files Browse the repository at this point in the history
  • Loading branch information
inulty-dfe committed May 29, 2024
1 parent ebfd3af commit c4851a8
Show file tree
Hide file tree
Showing 9 changed files with 385 additions and 123 deletions.
72 changes: 65 additions & 7 deletions spec/features/publish/courses/editing_subject_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,59 @@
when_i_select_a_primary_subject('Primary with English')
and_i_click_continue
then_i_am_met_with_course_details_page
and_i_should_see_a_success_message
and_i_should_see_subject_updated_success_message
end

scenario 'updating secondary subject' do
and_there_is_a_secondary_course_i_want_to_edit
when_i_visit_the_edit_course_subject_page
when_i_select_a_subject(:business_studies)
when_i_select_a_master_subject(:business_studies)
and_i_click_continue
then_i_am_met_with_course_details_page
and_i_should_see_a_success_message
and_i_should_see_subject_updated_success_message
end

scenario 'updating a course with two secondary subjects' do
and_there_is_a_secondary_course_i_want_to_edit
and_the_course_has_two_subjects
when_i_visit_the_edit_course_subject_page
then_i_should_see_populated_selects
when_i_select_a_master_subject(:latin)
when_i_select_a_subordinate_subject(:business_studies)
and_i_click_continue
then_i_am_met_with_course_details_page
and_i_should_see_subjects_updated_success_message
and_i_see_the_subjects_on_the_details_page
end

scenario 'updating secondary subject modern languages' do
and_there_is_a_secondary_course_i_want_to_edit
when_i_visit_the_edit_course_subject_page
when_i_select_a_subject(:modern_languages)
when_i_select_a_master_subject(:modern_languages)
and_i_click_continue
then_i_am_met_with_the_modern_languages_page
end

scenario 'updating to no subjects' do
and_there_is_a_secondary_course_i_want_to_edit
when_i_visit_the_edit_course_subject_page
when_i_select_a_blank_subject
and_i_click_continue
then_i_am_met_with_an_error
end

private

def and_i_should_see_a_success_message
expect(page).to have_content(I18n.t('success.saved', value: 'Subject'))
def and_i_should_see_subjects_updated_success_message
within '.govuk-notification-banner' do
expect(page).to have_content(I18n.t('success.saved', value: 'Subjects'))
end
end

def and_i_should_see_subject_updated_success_message
within '.govuk-notification-banner' do
expect(page).to have_content(I18n.t('success.saved', value: 'Subject'))
end
end

def given_i_am_authenticated_as_a_provider_user
Expand All @@ -48,6 +77,15 @@ def and_there_is_a_secondary_course_i_want_to_edit
given_a_course_exists(:secondary)
end

def and_the_course_has_two_subjects
@course.subjects << find_or_create(:secondary_subject, :latin)
end

def then_i_should_see_populated_selects
expect(publish_courses_subjects_edit_page.master_subject_fields.find('option[selected]')).to have_text('Drama')
expect(publish_courses_subjects_edit_page.subordinate_subjects_fields.find('option[selected]')).to have_text('Latin')
end

def and_there_is_a_primary_course_i_want_to_edit
given_a_course_exists(:primary)
end
Expand All @@ -60,14 +98,26 @@ def when_i_select_a_primary_subject(subject_type)
publish_courses_new_subjects_page.choose(subject_type)
end

def when_i_select_a_subject(subject_type)
def when_i_select_a_master_subject(subject_type)
publish_courses_new_subjects_page.master_subject_fields.select(course_subject(subject_type).subject_name).click
end

def when_i_select_a_subordinate_subject(subject_type)
publish_courses_new_subjects_page.subordinate_subjects_fields.select(course_subject(subject_type).subject_name).click
end

def when_i_select_a_blank_subject
publish_courses_new_subjects_page.master_subject_fields.select('').click
end

def and_i_click_continue
publish_courses_new_subjects_page.continue.click
end

def and_i_see_the_subjects_on_the_details_page
expect(page.find('[data-qa="course__subjects"]')).to have_content('LatinBusiness studies')
end

def provider
@provider ||= @user.providers.first
end
Expand All @@ -85,12 +135,20 @@ def then_i_am_met_with_the_modern_languages_page
expect(page).to have_content('Languages')
end

def then_i_am_met_with_an_error
within('.govuk-error-summary') do
expect(page).to have_content('Select a subject')
end
end

def course_subject(subject_type)
case subject_type
when :primary_with_english
find_or_create(:primary_subject, :primary_with_english)
when :business_studies
find_or_create(:secondary_subject, :business_studies)
when :latin
find_or_create(:secondary_subject, :latin)
when :modern_languages
find_or_create(:secondary_subject, :modern_languages)
end
Expand Down
54 changes: 48 additions & 6 deletions spec/features/publish/courses/new_engineers_teach_physics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,33 +155,75 @@ def course_subject(subject_type)

def params_with_subject(level, subject_type)
course_subject = course_subject(subject_type)
"course%5Bis_send%5D=0&course%5Blevel%5D=#{level}&course%5Bmaster_subject_id%5D=#{course_subject.id}&course%5Bsubjects_ids%5D%5B%5D=#{course_subject.id}"
[
'course%5Bis_send%5D=0',
"course%5Blevel%5D=#{level}",
"course%5Bmaster_subject_id%5D=#{course_subject.id}",
"course%5Bsubjects_ids%5D%5B%5D=#{course_subject.id}",
'course%5Bsubordinate_subject_id%5D='
].join('&')
end

def params_with_etp(level, subject_type)
course_subject = course_subject(subject_type)
"course%5Bcampaign_name%5D=engineers_teach_physics&course%5Bis_send%5D=0&course%5Blevel%5D=#{level}&course%5Bmaster_subject_id%5D=#{course_subject.id}&course%5Bsubjects_ids%5D%5B%5D=#{course_subject.id}"
[
'course%5Bcampaign_name%5D=engineers_teach_physics',
'course%5Bis_send%5D=0',
"course%5Blevel%5D=#{level}",
"course%5Bmaster_subject_id%5D=#{course_subject.id}",
"course%5Bsubjects_ids%5D%5B%5D=#{course_subject.id}",
'course%5Bsubordinate_subject_id%5D='
].join('&')
end

def params_with_no_etp(level, subject_type)
course_subject = course_subject(subject_type)
"course%5Bcampaign_name%5D=&course%5Bis_send%5D=0&course%5Blevel%5D=#{level}&course%5Bmaster_subject_id%5D=#{course_subject.id}&course%5Bsubjects_ids%5D%5B%5D=#{course_subject.id}"
[
'course%5Bcampaign_name%5D=',
'course%5Bis_send%5D=0',
"course%5Blevel%5D=#{level}",
"course%5Bmaster_subject_id%5D=#{course_subject.id}",
"course%5Bsubjects_ids%5D%5B%5D=#{course_subject.id}",
'course%5Bsubordinate_subject_id%5D='
].join('&')
end

def modern_language_params_with_subject(level, subject_type)
subordinate_subject = course_subject(:modern_languages)
course_subject = course_subject(subject_type)
"course%5Bis_send%5D=0&course%5Blevel%5D=#{level}&course%5Bmaster_subject_id%5D=#{course_subject.id}&course%5Bsubjects_ids%5D%5B%5D=#{course_subject.id}&course%5Bsubjects_ids%5D%5B%5D=#{subordinate_subject.id}"
[
'course%5Bis_send%5D=0',
"course%5Blevel%5D=#{level}",
"course%5Bmaster_subject_id%5D=#{course_subject.id}",
"course%5Bsubjects_ids%5D%5B%5D=#{course_subject.id}",
"course%5Bsubjects_ids%5D%5B%5D=#{subordinate_subject.id}",
"course%5Bsubordinate_subject_id%5D=#{subordinate_subject.id}"
].join('&')
end

def form_params_with_latin(level, subject_type)
course_subject = course_subject(subject_type)
"course%5Bcampaign_name%5D=&course%5Bis_send%5D=0&course%5Blevel%5D=#{level}&course%5Bmaster_subject_id%5D=#{course_subject.id}&course%5Bsubjects_ids%5D%5B%5D=#{course_subject.id}"
[
'course%5Bcampaign_name%5D=',
'course%5Bis_send%5D=0',
"course%5Blevel%5D=#{level}",
"course%5Bmaster_subject_id%5D=#{course_subject.id}",
"course%5Bsubjects_ids%5D%5B%5D=#{course_subject.id}",
'course%5Bsubordinate_subject_id%5D='
].join('&')
end

def modern_languages_with_form_params(level, subject_type)
subordinate_subject = course_subject(:modern_languages)
course_subject = course_subject(subject_type)
"course%5Bcampaign_name%5D=engineers_teach_physics&course%5Bis_send%5D=0&course%5Blevel%5D=#{level}&course%5Bmaster_subject_id%5D=#{course_subject.id}&course%5Bsubjects_ids%5D%5B%5D=#{course_subject.id}&course%5Bsubjects_ids%5D%5B%5D=#{subordinate_subject.id}"
[
'course%5Bcampaign_name%5D=engineers_teach_physics',
'course%5Bis_send%5D=0',
"course%5Blevel%5D=#{level}",
"course%5Bmaster_subject_id%5D=#{course_subject.id}",
"course%5Bsubjects_ids%5D%5B%5D=#{course_subject.id}",
"course%5Bsubjects_ids%5D%5B%5D=#{subordinate_subject.id}",
"course%5Bsubordinate_subject_id%5D=#{subordinate_subject.id}"
].join('&')
end
end
63 changes: 63 additions & 0 deletions spec/features/publish/courses/new_primary_subject_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# frozen_string_literal: true

require 'rails_helper'

feature 'selecting a subject', { can_edit_current_and_next_cycles: false } do
before do
given_i_am_authenticated_as_a_provider_user
end

scenario 'selecting a subject' do
when_i_visit_the_new_primary_course_subject_page
when_i_select_a_primary_subject('Primary with English')
and_i_click_continue
then_i_am_met_with_the_age_range_page
end

scenario 'invalid entries' do
when_i_visit_the_new_primary_course_subject_page
and_i_click_continue
then_i_am_met_with_errors
end

private

def given_i_am_authenticated_as_a_provider_user
@user = create(:user, :with_provider)
given_i_am_authenticated(user: @user)
end

def when_i_visit_the_new_primary_course_subject_page
publish_courses_new_subjects_page.load(provider_code: provider.provider_code, recruitment_cycle_year: Settings.current_recruitment_cycle_year, query: primary_subject_params)
end

def when_i_select_a_primary_subject(subject_type)
publish_courses_new_subjects_page.choose(subject_type)
end

def and_i_click_continue
publish_courses_new_subjects_page.continue.click
end

def provider
@provider ||= @user.providers.first
end

def then_i_am_met_with_the_age_range_page
expect(page).to have_current_path("/publish/organisations/#{provider.provider_code}/#{Settings.current_recruitment_cycle_year}/courses/age-range/new?#{params_with_subject}")
expect(page).to have_content('Age range')
end

def then_i_am_met_with_errors
expect(page).to have_content('There is a problem')
expect(page).to have_content('Select a subject')
end

def primary_subject
find_or_create(:primary_subject, :primary_with_english)
end

def params_with_subject
"course%5Bcampaign_name%5D=&course%5Bis_send%5D=0&course%5Blevel%5D=primary&course%5Bmaster_subject_id%5D=#{primary_subject.id}&course%5Bsubjects_ids%5D%5B%5D=#{primary_subject.id}"
end
end
Loading

0 comments on commit c4851a8

Please sign in to comment.