|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +describe AppPatientProgrammeVaccinationCardComponent do |
| 4 | + subject(:rendered) { render_inline(component) } |
| 5 | + |
| 6 | + let(:component) do |
| 7 | + described_class.new(patient, academic_year:, programme:, show_caption:) |
| 8 | + end |
| 9 | + |
| 10 | + let(:patient) { create(:patient) } |
| 11 | + let(:academic_year) { 2023 } |
| 12 | + let(:programme) { Programme.hpv } |
| 13 | + let(:show_caption) { false } |
| 14 | + |
| 15 | + it { should have_css(".nhsuk-card__heading", text: "No vaccination record") } |
| 16 | + it { should_not have_css(".nhsuk-table") } |
| 17 | + |
| 18 | + context "with a vaccination record" do |
| 19 | + let(:location) do |
| 20 | + create( |
| 21 | + :school, |
| 22 | + name: "Test School", |
| 23 | + address_line_1: "Waterloo Road", |
| 24 | + address_town: "London", |
| 25 | + address_postcode: "SE1 8TY" |
| 26 | + ) |
| 27 | + end |
| 28 | + |
| 29 | + let(:vaccination_record_programme) { Programme.hpv } |
| 30 | + let(:performed_at) { Time.zone.local(2024, 1, 1) } |
| 31 | + |
| 32 | + before do |
| 33 | + create( |
| 34 | + :vaccination_record, |
| 35 | + patient:, |
| 36 | + session: |
| 37 | + create( |
| 38 | + :session, |
| 39 | + location:, |
| 40 | + programmes: [vaccination_record_programme] |
| 41 | + ), |
| 42 | + programme: vaccination_record_programme, |
| 43 | + performed_at: |
| 44 | + ) |
| 45 | + end |
| 46 | + |
| 47 | + it { should have_css(".nhsuk-card__heading", text: "Vaccination record") } |
| 48 | + |
| 49 | + it { should have_css(".nhsuk-tag", text: "Not eligible") } |
| 50 | + it { should have_css(".nhsuk-table__header", text: "Vaccination date") } |
| 51 | + it { should have_css(".nhsuk-table__header", text: "Age") } |
| 52 | + it { should have_css(".nhsuk-table__header", text: "Programme") } |
| 53 | + it { should have_css(".nhsuk-table__header", text: "Source") } |
| 54 | + |
| 55 | + it { should have_link("1 January 2024") } |
| 56 | + |
| 57 | + it do |
| 58 | + expect(rendered).to have_css( |
| 59 | + ".nhsuk-table", |
| 60 | + text: "#{patient.age_years(now: performed_at)} years" |
| 61 | + ) |
| 62 | + end |
| 63 | + |
| 64 | + it { should have_css(".nhsuk-table", text: "HPV") } |
| 65 | + it { should have_css(".nhsuk-table", text: "Recorded in Mavis") } |
| 66 | + |
| 67 | + context "with a vaccination record from a different programme" do |
| 68 | + let(:programme) { Programme.hpv } |
| 69 | + let(:vaccination_record_programme) { Programme.flu } |
| 70 | + |
| 71 | + it { should_not have_link("1 January 2024") } |
| 72 | + |
| 73 | + it do |
| 74 | + expect(rendered).not_to have_css( |
| 75 | + ".nhsuk-table", |
| 76 | + text: "#{patient.age_years(now: performed_at)} years" |
| 77 | + ) |
| 78 | + end |
| 79 | + |
| 80 | + it { should_not have_css(".nhsuk-table", text: "HPV") } |
| 81 | + it { should_not have_css(".nhsuk-table", text: "Recorded in Mavis") } |
| 82 | + end |
| 83 | + |
| 84 | + context "with a Flu vaccination record from a previous year" do |
| 85 | + let(:vaccination_record_programme) { Programme.flu } |
| 86 | + let(:programme) { vaccination_record_programme } |
| 87 | + let(:performed_at) { Time.zone.local(2022, 1, 1) } |
| 88 | + |
| 89 | + it { should_not have_link("1 January 2022") } |
| 90 | + |
| 91 | + it do |
| 92 | + expect(rendered).not_to have_css( |
| 93 | + ".nhsuk-table", |
| 94 | + text: "#{patient.age_years(now: performed_at)} years" |
| 95 | + ) |
| 96 | + end |
| 97 | + |
| 98 | + it { should_not have_css(".nhsuk-table", text: "Flu") } |
| 99 | + it { should_not have_css(".nhsuk-table", text: "Recorded in Mavis") } |
| 100 | + end |
| 101 | + end |
| 102 | +end |
0 commit comments