Skip to content

Commit 1d09920

Browse files
committed
Add tests for PDS lookup history
Adds tests for PDS lookup history methods and the new timeline component.
1 parent 2bcc020 commit 1d09920

File tree

6 files changed

+348
-9
lines changed

6 files changed

+348
-9
lines changed

app/models/pds_search_result.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def timeline_item
8888
description:
8989
I18n.t(
9090
"activerecord.attributes.#{self.class.model_name.i18n_key}.results.#{result}",
91-
nhs_number: pds_nhs_number || nhs_number
91+
nhs_number: nhs_number
9292
)
9393
}
9494
end

spec/components/app_child_summary_component_spec.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,44 @@
124124
it { should have_text("Archive reason") }
125125
it { should have_text("Other: Some details.") }
126126
end
127+
128+
context "with a PDS lookup match" do
129+
let(:patient) { create(:patient) }
130+
131+
before { allow(patient).to receive(:pds_lookup_match?).and_return(true) }
132+
133+
it "shows a PDS history action link" do
134+
render_inline(described_class.new(patient))
135+
136+
expect(page).to have_link(
137+
"PDS history",
138+
href:
139+
Rails.application.routes.url_helpers.pds_search_history_patient_path(
140+
patient
141+
)
142+
)
143+
end
144+
end
145+
146+
context "without a PDS lookup match" do
147+
let(:patient) { create(:patient) }
148+
149+
before { allow(patient).to receive(:pds_lookup_match?).and_return(false) }
150+
151+
it "does not show a PDS history link" do
152+
render_inline(described_class.new(patient))
153+
154+
expect(page).not_to have_link("PDS history")
155+
end
156+
157+
context "when the record is not a Patient" do
158+
let(:consent_form) { create(:consent_form) }
159+
160+
it "does not show a PDS history link" do
161+
render_inline(described_class.new(consent_form))
162+
163+
expect(page).not_to have_link("PDS history")
164+
end
165+
end
166+
end
127167
end
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# frozen_string_literal: true
2+
3+
describe AppTimelineComponent, type: :component do
4+
subject(:rendered) { render_inline(described_class.new(items: items)) }
5+
6+
context "when there are no items" do
7+
let(:items) { [] }
8+
9+
it "does not render" do
10+
expect(rendered.to_html).to be_blank
11+
end
12+
end
13+
14+
context "when items are present" do
15+
let(:items) do
16+
[
17+
{ heading_text: "Step 1", description: "First step", active: true },
18+
{
19+
heading_text: "Step 2",
20+
description: "Past step",
21+
is_past_item: true
22+
},
23+
{ heading_text: "Step 3", description: "Future step" }
24+
]
25+
end
26+
27+
it "renders a list of timeline items" do
28+
expect(rendered.css("ul.app-timeline li.app-timeline__item").count).to eq(
29+
3
30+
)
31+
end
32+
33+
it "renders the heading text" do
34+
expect(rendered).to have_text("Step 1")
35+
expect(rendered).to have_text("Step 2")
36+
expect(rendered).to have_text("Step 3")
37+
end
38+
39+
it "renders the description text" do
40+
expect(rendered).to have_text("First step")
41+
expect(rendered).to have_text("Past step")
42+
expect(rendered).to have_text("Future step")
43+
end
44+
45+
it "renders a bold header for active items" do
46+
expect(rendered.css("h3.nhsuk-u-font-weight-bold")).to have_text("Step 1")
47+
end
48+
49+
it "renders a large badge for active and past items" do
50+
expect(rendered.css("svg.app-timeline__badge")).to be_present
51+
end
52+
53+
it "renders a small badge for future items" do
54+
expect(rendered.css("svg.app-timeline__badge--small")).to be_present
55+
end
56+
end
57+
58+
context "when an item is blank" do
59+
let(:items) { [nil, { heading_text: "Step X", description: "Valid" }] }
60+
61+
it "skips rendering blank items" do
62+
expect(rendered.css("li.app-timeline__item").count).to eq(1)
63+
expect(rendered).to have_text("Step X")
64+
end
65+
end
66+
end

spec/features/import_child_pds_lookup_extravaganza_spec.rb

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
# Case 1: Patient with existing NHS number (Albert) - nothing should happen
2020
and_i_see_the_patient_uploaded_with_nhs_number
2121
and_parents_are_created_for_albert
22+
when_i_click_on_alberts_pds_history
23+
then_i_see_the_pds_lookup_history
2224

2325
# Case 2: Existing patient without NHS number (Betty) - should not show duplicate review
24-
and_i_do_not_see_an_import_review_for_the_first_patient_uploaded_without_nhs_number
26+
when_i_go_back_to_the_import_page
27+
then_i_do_not_see_an_import_review_for_the_first_patient_uploaded_without_nhs_number
2528
when_i_click_on_the_patient_without_review
2629
then_i_see_the_new_patient_has_an_nhs_number
2730
and_betty_has_correct_parent_relationships
@@ -272,12 +275,14 @@ def and_an_existing_patient_record_exists
272275
def and_pds_lookup_during_import_is_enabled
273276
Flipper.enable(:pds_lookup_during_import)
274277

275-
stub_pds_search_to_return_a_patient(
276-
"9999075320",
277-
"family" => "Tweedle",
278-
"given" => "Albert",
279-
"birthdate" => "eq2009-12-29",
280-
"address-postalcode" => "SW11 1EH"
278+
stub_pds_cascading_search(
279+
family_name: "Tweedle",
280+
given_name: "Albert",
281+
birthdate: "eq2009-12-29",
282+
address_postcode: "SW11 1EH",
283+
steps: {
284+
wildcard_family_name: "9999075320"
285+
}
281286
)
282287

283288
stub_pds_search_to_return_a_patient(
@@ -416,6 +421,11 @@ def when_i_click_review_for(name)
416421
end
417422
end
418423

424+
def when_i_click_on_alberts_pds_history
425+
click_on "TWEEDLE, Albert"
426+
click_link "PDS history"
427+
end
428+
419429
def and_i_upload_import_file(filename)
420430
click_button "Import records"
421431
choose "Child records"
@@ -447,6 +457,10 @@ def then_i_should_see_the_import_page
447457
expect(page).to have_content("Import class list")
448458
end
449459

460+
def then_i_see_the_pds_lookup_history
461+
expect(page).to have_content("NHS number lookup history")
462+
end
463+
450464
def when_i_upload_a_valid_file
451465
attach_file(
452466
"class_import[csv]",
@@ -526,7 +540,7 @@ def and_an_existing_patient_records_exist_in_school
526540
)
527541
end
528542

529-
def and_i_do_not_see_an_import_review_for_the_first_patient_uploaded_without_nhs_number
543+
def then_i_do_not_see_an_import_review_for_the_first_patient_uploaded_without_nhs_number
530544
expect(page).not_to have_content("Actions Review SAMSON, Betty")
531545
end
532546

spec/models/patient_spec.rb

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,4 +1082,86 @@
10821082
end
10831083
end
10841084
end
1085+
1086+
describe "#latest_pds_search_result" do
1087+
subject(:latest_pds_search_result) { patient.latest_pds_search_result }
1088+
1089+
let(:patient) { create(:patient) }
1090+
1091+
context "with no PDS search results" do
1092+
it { should be_nil }
1093+
end
1094+
1095+
context "with PDS search results but no changeset" do
1096+
let(:import) { create(:class_import) }
1097+
1098+
before { create(:pds_search_result, patient:, import:) }
1099+
1100+
it { should be_nil }
1101+
end
1102+
1103+
context "with PDS search results and changeset" do
1104+
let(:import) { create(:class_import) }
1105+
1106+
before do
1107+
create(
1108+
:patient_changeset,
1109+
patient:,
1110+
import:,
1111+
pds_nhs_number: "9449304130"
1112+
)
1113+
create(:pds_search_result, patient:, import:)
1114+
end
1115+
1116+
it { should eq("9449304130") }
1117+
end
1118+
end
1119+
1120+
describe "#pds_lookup_match?" do
1121+
subject(:pds_lookup_match?) { patient.pds_lookup_match? }
1122+
1123+
let(:patient) { create(:patient, nhs_number: "9449304130") }
1124+
1125+
context "when patient has no NHS number" do
1126+
let(:patient) { create(:patient, nhs_number: nil) }
1127+
1128+
it { should be(false) }
1129+
end
1130+
1131+
context "with no PDS search results" do
1132+
it { should be(false) }
1133+
end
1134+
1135+
context "with matching PDS search result" do
1136+
let(:import) { create(:class_import) }
1137+
1138+
before do
1139+
create(
1140+
:patient_changeset,
1141+
patient:,
1142+
import:,
1143+
pds_nhs_number: "9449304130"
1144+
)
1145+
create(:pds_search_result, patient:, import:)
1146+
end
1147+
1148+
it { should be(true) }
1149+
end
1150+
1151+
context "with non-matching PDS search result" do
1152+
let(:import) { create(:class_import) }
1153+
1154+
before do
1155+
create(
1156+
:patient_changeset,
1157+
patient:,
1158+
import:,
1159+
pds_nhs_number: "9449310475"
1160+
)
1161+
create(:pds_search_result, patient:, import:)
1162+
end
1163+
1164+
it { should be(false) }
1165+
end
1166+
end
10851167
end

0 commit comments

Comments
 (0)