|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +describe AppPatientProgrammeSessionTableComponent do |
| 4 | + subject { render_inline(component) } |
| 5 | + |
| 6 | + let(:component) do |
| 7 | + described_class.new(patient, current_team: team, programme_type:) |
| 8 | + end |
| 9 | + let(:programme_type) { :hpv } |
| 10 | + let(:team) { create(:team) } |
| 11 | + |
| 12 | + context "without a session" do |
| 13 | + let(:patient) { create(:patient) } |
| 14 | + |
| 15 | + it { should have_content("No sessions") } |
| 16 | + end |
| 17 | + |
| 18 | + context "with one session" do |
| 19 | + let(:programmes) { [Programme.hpv, Programme.mmr] } |
| 20 | + |
| 21 | + let(:location) do |
| 22 | + create(:school, name: "Waterloo Road", programmes:, academic_year: 2024) |
| 23 | + end |
| 24 | + let(:session) do |
| 25 | + create( |
| 26 | + :session, |
| 27 | + team:, |
| 28 | + location:, |
| 29 | + programmes:, |
| 30 | + date: Date.new(2025, 1, 1) |
| 31 | + ) |
| 32 | + end |
| 33 | + |
| 34 | + # Can't use year_group here because we need an absolute date, not one |
| 35 | + # relative to the current academic year. |
| 36 | + let(:patient) { create(:patient, date_of_birth: Date.new(2011, 9, 1)) } |
| 37 | + |
| 38 | + before { create_list(:patient_location, 1, patient:, session:) } |
| 39 | + |
| 40 | + it { should have_link("Waterloo Road") } |
| 41 | + it { should have_content("1 January 2025") } |
| 42 | + |
| 43 | + context "with multiple sessions" do |
| 44 | + let(:other_location) do |
| 45 | + create( |
| 46 | + :school, |
| 47 | + name: "Paddington Road", |
| 48 | + programmes: other_programmes, |
| 49 | + academic_year: 2024 |
| 50 | + ) |
| 51 | + end |
| 52 | + let(:other_session) do |
| 53 | + create( |
| 54 | + :session, |
| 55 | + team:, |
| 56 | + location: other_location, |
| 57 | + programmes: other_programmes, |
| 58 | + date: Date.new(2025, 2, 1) |
| 59 | + ) |
| 60 | + end |
| 61 | + let(:other_programmes) { [Programme.hpv, Programme.menacwy] } |
| 62 | + |
| 63 | + before do |
| 64 | + create(:patient_location, patient:, session: other_session) |
| 65 | + create( |
| 66 | + :vaccination_record, |
| 67 | + patient:, |
| 68 | + session:, |
| 69 | + outcome: :administered, |
| 70 | + performed_at_date: 1.month.ago, |
| 71 | + programme_type: |
| 72 | + ) |
| 73 | + create( |
| 74 | + :vaccination_record, |
| 75 | + patient:, |
| 76 | + session:, |
| 77 | + outcome: :refused, |
| 78 | + performed_at_date: 1.year.ago, |
| 79 | + programme_type: |
| 80 | + ) |
| 81 | + end |
| 82 | + |
| 83 | + it { should have_link("Waterloo Road") } |
| 84 | + it { should have_content("1 January 2025") } |
| 85 | + it { should have_content("Vaccinated") } |
| 86 | + |
| 87 | + it { should have_link("Paddington Road") } |
| 88 | + it { should have_content("1 February 2025") } |
| 89 | + it { should have_content("No outcome") } |
| 90 | + |
| 91 | + context "with a programme type filter that matches only one session" do |
| 92 | + let(:component) do |
| 93 | + described_class.new( |
| 94 | + patient, |
| 95 | + current_team: team, |
| 96 | + programme_type: :menacwy |
| 97 | + ) |
| 98 | + end |
| 99 | + |
| 100 | + it { should_not have_link("Waterloo Road") } |
| 101 | + it { should have_link("Paddington Road") } |
| 102 | + end |
| 103 | + end |
| 104 | + end |
| 105 | +end |
0 commit comments