Skip to content

Commit

Permalink
Add training partner tests
Browse files Browse the repository at this point in the history
  • Loading branch information
inulty-dfe committed Jan 23, 2025
1 parent d1b1ffe commit 484dc5a
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# frozen_string_literal: true

require 'rails_helper'

feature 'Viewing courses as an accredited provider', { can_edit_current_and_next_cycles: false } do
before do
allow(Settings.features).to receive(:provider_partnerships).and_return(true)
given_i_am_authenticated_as_an_accredited_provider_user
and_some_courses_exist_with_one_i_accredit
when_i_visit_the_publish_training_partner_index_page
end

scenario 'i can see who lists me as their accredited provider' do
then_i_should_see_a_list_of_training_partners
and_i_should_see_a_count_of_the_courses_i_accredit
end

scenario 'i can see which courses i am the accredited provider for' do
and_i_click_on_a_training_provider
then_i_see_the_courses_i_accredit_for
end

def given_i_am_authenticated_as_an_accredited_provider_user
given_i_am_authenticated(user: create(:user, providers: [create(:provider, :accredited_provider)]))
end

def and_some_courses_exist_with_one_i_accredit
create(:provider_partnership, training_provider:, accredited_provider: accrediting_provider)
given_a_course_exists(
enrichments: [build(:course_enrichment, :published)],
provider: training_provider,
accrediting_provider:
)

create(:course, enrichments: [build(:course_enrichment, :published)], provider: training_provider)
end

def when_i_visit_the_publish_training_partner_index_page
publish_training_partner_index_page.load(
provider_code: accrediting_provider.provider_code, recruitment_cycle_year: accrediting_provider.recruitment_cycle_year
)
end

def then_i_should_see_a_list_of_training_partners
expect(publish_training_partner_index_page.training_provider_rows.size).to eq(1)

expect(publish_training_partner_index_page.training_provider_rows.first.name).to have_text(training_provider.provider_name)
end

def and_i_should_see_a_count_of_the_courses_i_accredit
expect(publish_training_partner_index_page.training_provider_rows.first.course_count).to have_text('1')
end

def and_i_click_on_a_training_provider
publish_training_partner_index_page.training_provider_rows.first.name.click
end

def then_i_see_the_courses_i_accredit_for
expect(publish_training_partners_course_index_page).to be_displayed
expect(publish_training_partners_course_index_page.courses.size).to eq(1)
expect(publish_training_partners_course_index_page.courses.first.name).to have_text(course.name)
end

def accrediting_provider
@current_user.providers.first
end

def training_provider
@training_partner ||= create(:provider)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

feature 'Viewing courses as an accredited provider', { can_edit_current_and_next_cycles: false } do
before do
allow(Settings.features).to receive(:provider_partnerships).and_return(false)
given_i_am_authenticated_as_an_accredited_provider_user
and_some_courses_exist_with_one_i_accredit
when_i_visit_the_publish_training_provider_index_page
Expand Down
2 changes: 1 addition & 1 deletion spec/support/feature_helpers/course_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module CourseSteps
attr_reader :course

def given_a_course_exists(*traits, **overrides)
@course ||= create(:course, *traits, **overrides, provider: current_user.providers.first)
@course ||= create(:course, *traits, **overrides, provider: overrides.delete(:provider) || current_user.providers.first)
end

def given_a_site_exists(*traits, **overrides)
Expand Down
13 changes: 13 additions & 0 deletions spec/support/page_objects/publish/training_partner_index.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

require_relative '../sections/training_partner'

module PageObjects
module Publish
class TrainingPartnerIndex < PageObjects::Base
set_url '/publish/organisations/{provider_code}/{recruitment_cycle_year}/training-partners'

sections :training_provider_rows, Sections::TrainingPartner, '[data-qa="provider__training_partners_list"]'
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module PageObjects
module Publish
module TrainingPartners
class CourseIndex < PageObjects::Base
set_url '/publish/organisations/{provider_code}/{recruitment_cycle_year}/training-partners/{training_provider_code}/courses'

sections :courses, '[data-qa="courses__table-section"]' do
element :name, '[data-qa="courses-table__course-name"]'
end
end
end
end
end
12 changes: 12 additions & 0 deletions spec/support/page_objects/sections/training_partner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require_relative 'base'

module PageObjects
module Sections
class TrainingPartner < PageObjects::Sections::Base
element :name, '[data-qa="training_partner_name"]'
element :course_count, '[data-qa="course_count"]'
end
end
end

0 comments on commit 484dc5a

Please sign in to comment.