Skip to content

Commit f34ca32

Browse files
committed
Refactor to include card title in component
Renames `AppPatientProgrammeVaccinationTableComponent` to `AppPatientProgrammeVaccinationCardComponent` and includes the card title within the new component because it depends on the presence of vaccination records. Jira-Issue: MAV-3837
1 parent e311a8e commit f34ca32

6 files changed

Lines changed: 78 additions & 65 deletions
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<%= render AppCardComponent.new(section: true) do |card| %>
2+
<% card.with_heading { vaccination_records.present? ? "Vaccination record" : "No vaccination record" } %>
3+
4+
<%= render programme_status_tag %>
5+
6+
<% if vaccination_records.present? %>
7+
<%= govuk_table(html_attributes: { class: "nhsuk-table-responsive" }) do |table| %>
8+
<% table.with_caption(text: "Vaccination records", size: "s") if show_caption %>
9+
10+
<% table.with_head do |head| %>
11+
<% head.with_row do |row| %>
12+
<% row.with_cell(text: "Vaccination date") %>
13+
<% row.with_cell(text: "Age") %>
14+
<% row.with_cell(text: "Programme") %>
15+
<% row.with_cell(text: "Source") %>
16+
<% end %>
17+
<% end %>
18+
19+
<% table.with_body do |body| %>
20+
<% vaccination_records.each do |vaccination_record| %>
21+
<% body.with_row do |row| %>
22+
<% row.with_cell do %>
23+
<span class="nhsuk-table-responsive__heading">Vaccination date</span>
24+
<%= link_to vaccination_record.performed_at.to_date.to_fs(:long),
25+
vaccination_record_path(vaccination_record) %>
26+
<% end %>
27+
28+
<% row.with_cell do %>
29+
<span class="nhsuk-table-responsive__heading">Age</span>
30+
<%= formatted_age_when(vaccination_record) %>
31+
<% end %>
32+
33+
<% row.with_cell do %>
34+
<span class="nhsuk-table-responsive__heading">Programme</span>
35+
<%= render AppProgrammeTagsComponent.new([vaccination_record.programme]) %>
36+
<% end %>
37+
38+
<% row.with_cell do %>
39+
<span class="nhsuk-table-responsive__heading">Source</span>
40+
<%= vaccination_record_source(vaccination_record) %>
41+
<% end %>
42+
<% end %>
43+
<% end %>
44+
<% end %>
45+
<% end %>
46+
<% end %>
47+
<% end %>

app/components/app_patient_programme_vaccination_table_component.rb renamed to app/components/app_patient_programme_vaccination_card_component.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
class AppPatientProgrammeVaccinationTableComponent < ViewComponent::Base
3+
class AppPatientProgrammeVaccinationCardComponent < ViewComponent::Base
44
def initialize(patient, academic_year:, programme: nil, show_caption: false)
55
@patient = patient
66
@academic_year = academic_year

app/components/app_patient_programme_vaccination_table_component.html.erb

Lines changed: 0 additions & 43 deletions
This file was deleted.

app/views/patients/programmes/show.html.erb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99

1010
<%= render AppPatientNavigationComponent.new(@patient, current_user.programmes, active: @programme.type.to_sym) %>
1111

12-
<%= render AppCardComponent.new(section: true) do |card| %>
13-
<% card.with_heading { "Vaccination record" } %>
14-
<%= render AppPatientProgrammeVaccinationTableComponent.new(
15-
@patient, academic_year: AcademicYear.current, show_caption: false, programme: @programme,
16-
) %>
17-
<% end %>
12+
<%= render AppPatientProgrammeVaccinationCardComponent.new(
13+
@patient,
14+
academic_year: AcademicYear.current,
15+
show_caption: false,
16+
programme: @programme,
17+
) %>
1818

1919
<%= render AppCardComponent.new(section: true) do |card| %>
2020
<% card.with_heading { "Sessions" } %>

spec/components/app_patient_programme_vaccination_table_component_spec.rb renamed to spec/components/app_patient_programme_vaccination_card_component_spec.rb

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

3-
describe AppPatientProgrammeVaccinationTableComponent do
4-
subject { render_inline(component) }
3+
describe AppPatientProgrammeVaccinationCardComponent do
4+
subject(:rendered) { render_inline(component) }
55

66
let(:component) do
77
described_class.new(patient, academic_year:, programme:, show_caption:)
@@ -12,6 +12,7 @@
1212
let(:programme) { Programme.hpv }
1313
let(:show_caption) { false }
1414

15+
it { should have_css(".nhsuk-card__heading", text: "No vaccination record") }
1516
it { should_not have_css(".nhsuk-table") }
1617

1718
context "with a vaccination record" do
@@ -43,19 +44,23 @@
4344
)
4445
end
4546

47+
it { should have_css(".nhsuk-card__heading", text: "Vaccination record") }
48+
4649
it { should have_css(".nhsuk-tag", text: "Not eligible") }
4750
it { should have_css(".nhsuk-table__header", text: "Vaccination date") }
4851
it { should have_css(".nhsuk-table__header", text: "Age") }
4952
it { should have_css(".nhsuk-table__header", text: "Programme") }
5053
it { should have_css(".nhsuk-table__header", text: "Source") }
5154

5255
it { should have_link("1 January 2024") }
56+
5357
it do
54-
should have_css(
55-
".nhsuk-table",
56-
text: "#{patient.age_years(now: performed_at)} years"
57-
)
58+
expect(rendered).to have_css(
59+
".nhsuk-table",
60+
text: "#{patient.age_years(now: performed_at)} years"
61+
)
5862
end
63+
5964
it { should have_css(".nhsuk-table", text: "HPV") }
6065
it { should have_css(".nhsuk-table", text: "Recorded in Mavis") }
6166

@@ -64,12 +69,14 @@
6469
let(:vaccination_record_programme) { Programme.flu }
6570

6671
it { should_not have_link("1 January 2024") }
72+
6773
it do
68-
should_not have_css(
69-
".nhsuk-table",
70-
text: "#{patient.age_years(now: performed_at)} years"
71-
)
74+
expect(rendered).not_to have_css(
75+
".nhsuk-table",
76+
text: "#{patient.age_years(now: performed_at)} years"
77+
)
7278
end
79+
7380
it { should_not have_css(".nhsuk-table", text: "HPV") }
7481
it { should_not have_css(".nhsuk-table", text: "Recorded in Mavis") }
7582
end
@@ -80,12 +87,14 @@
8087
let(:performed_at) { Time.zone.local(2022, 1, 1) }
8188

8289
it { should_not have_link("1 January 2022") }
90+
8391
it do
84-
should_not have_css(
85-
".nhsuk-table",
86-
text: "#{patient.age_years(now: performed_at)} years"
87-
)
92+
expect(rendered).not_to have_css(
93+
".nhsuk-table",
94+
text: "#{patient.age_years(now: performed_at)} years"
95+
)
8896
end
97+
8998
it { should_not have_css(".nhsuk-table", text: "Flu") }
9099
it { should_not have_css(".nhsuk-table", text: "Recorded in Mavis") }
91100
end

spec/features/viewing_child_records_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def then_i_see_the_childs_flu_vaccinations
141141
expect(page).to have_current_path(patient_programme_path(@patient, "flu"))
142142
expect(page).to have_css(
143143
"h3.nhsuk-card__heading",
144-
text: "Vaccination record"
144+
text: "No vaccination record"
145145
)
146146
end
147147

0 commit comments

Comments
 (0)