11import re
2+ from datetime import datetime
3+ from datetime import timezone as tz
24
35import pytest
46from django .urls import reverse
57from playwright .sync_api import expect
68
9+ from manage_breast_screening .clinics .tests .factories import ClinicSlotFactory
710from manage_breast_screening .core .system_test_setup import SystemTestCase
811from manage_breast_screening .participants .tests .factories import (
912 AppointmentFactory ,
1417
1518class TestParticipantRecord (SystemTestCase ):
1619 @pytest .fixture (autouse = True )
17- def before (self ):
20+ def before (self , time_machine ):
1821 self .participant = ParticipantFactory (first_name = "Janet" , last_name = "Williams" )
19- self . screening_episode = ScreeningEpisodeFactory ( participant = self . participant )
20- self . appointment = AppointmentFactory ( screening_episode = self . screening_episode )
22+
23+ time_machine . move_to ( datetime ( 2025 , 1 , 1 , 10 , tzinfo = tz . utc ) )
2124
2225 @pytest .mark .skip ("not implemented yet" )
2326 def test_viewing_participant_record_from_an_appointment (self ):
24- self .given_i_am_viewing_an_appointment ()
27+ self .given_the_participant_has_an_upcoming_appointment ()
28+ self .given_i_am_viewing_the_upcoming_appointment ()
2529 self .when_i_click_on_view_participant_record ()
2630 self .then_i_should_be_on_the_participant_record_page ()
2731 self .and_i_should_see_the_participant_record ()
@@ -32,12 +36,53 @@ def test_accessibility(self):
3236 self .given_i_am_on_the_participant_record_page ()
3337 self .then_the_accessibility_baseline_is_met ()
3438
35- def given_i_am_viewing_an_appointment (self ):
39+ def test_viewing_upcoming_appointments (self ):
40+ self .given_the_participant_has_an_upcoming_appointment ()
41+ self .and_i_am_on_the_participant_record_page ()
42+ self .then_i_should_see_the_upcoming_appointment ()
43+ self .when_i_click_on_the_upcoming_appointment ()
44+ self .then_i_should_be_on_the_upcoming_appointment_page ()
45+
46+ def test_viewing_past_appointments (self ):
47+ self .given_i_have_past_appointments ()
48+ self .and_i_am_on_the_participant_record_page ()
49+ self .then_i_should_see_the_past_appointments ()
50+ self .when_i_click_on_a_past_appointment ()
51+ self .then_i_should_be_on_the_past_appointment_page ()
52+
53+ def given_the_participant_has_an_upcoming_appointment (self ):
54+ clinic_slot = ClinicSlotFactory (
55+ starts_at = datetime (2025 , 1 , 2 , 11 , tzinfo = tz .utc )
56+ )
57+ screening_episode = ScreeningEpisodeFactory (participant = self .participant )
58+ self .upcoming_appointment = AppointmentFactory (
59+ clinic_slot = clinic_slot , screening_episode = screening_episode
60+ )
61+
62+ def given_i_have_past_appointments (self ):
63+ clinic_slot_2022 = ClinicSlotFactory (
64+ starts_at = datetime (2022 , 1 , 2 , 11 , tzinfo = tz .utc )
65+ )
66+ clinic_slot_2019 = ClinicSlotFactory (
67+ starts_at = datetime (2019 , 1 , 2 , 11 , tzinfo = tz .utc )
68+ )
69+ self .past_appointments = [
70+ AppointmentFactory (
71+ clinic_slot = clinic_slot_2022 ,
72+ screening_episode = ScreeningEpisodeFactory (participant = self .participant ),
73+ ),
74+ AppointmentFactory (
75+ clinic_slot = clinic_slot_2019 ,
76+ screening_episode = ScreeningEpisodeFactory (participant = self .participant ),
77+ ),
78+ ]
79+
80+ def given_i_am_viewing_the_upcoming_appointment (self ):
3681 self .page .goto (
3782 self .live_server_url
3883 + reverse (
3984 "mammograms:start_screening" ,
40- kwargs = {"id" : self .appointment .pk },
85+ kwargs = {"id" : self .upcoming_appointment .pk },
4186 )
4287 )
4388
@@ -50,6 +95,8 @@ def given_i_am_on_the_participant_record_page(self):
5095 )
5196 )
5297
98+ and_i_am_on_the_participant_record_page = given_i_am_on_the_participant_record_page
99+
53100 def when_i_click_on_view_participant_record (self ):
54101 self .page .get_by_text ("View participant record" ).click ()
55102
@@ -71,6 +118,44 @@ def when_i_click_on_the_back_link(self):
71118 def then_i_should_be_back_on_the_appointment (self ):
72119 path = reverse (
73120 "mammograms:start_screening" ,
74- kwargs = {"id" : self .appointment .pk },
121+ kwargs = {"id" : self .upcoming_appointment .pk },
122+ )
123+ expect (self .page ).to_have_url (re .compile (path ))
124+
125+ def then_i_should_see_the_upcoming_appointment (self ):
126+ upcoming = self .page .get_by_test_id ("upcoming-appointments-table" )
127+ expect (upcoming ).to_be_visible ()
128+ appointment = upcoming .get_by_test_id ("appointment-row" )
129+ expect (appointment ).to_be_visible ()
130+ expect (appointment ).to_contain_text ("2 January 2025" )
131+
132+ def then_i_should_see_the_past_appointments (self ):
133+ past = self .page .get_by_test_id ("past-appointments-table" )
134+ expect (past ).to_be_visible ()
135+ appointments = past .get_by_test_id ("appointment-row" ).all ()
136+ assert len (appointments ) == 2
137+
138+ expect (appointments [0 ]).to_contain_text ("2 January 2022" )
139+ expect (appointments [1 ]).to_contain_text ("2 January 2019" )
140+
141+ def when_i_click_on_the_upcoming_appointment (self ):
142+ past = self .page .get_by_test_id ("upcoming-appointments-table" )
143+ past .get_by_text ("View details" ).click ()
144+
145+ def when_i_click_on_a_past_appointment (self ):
146+ past = self .page .get_by_test_id ("past-appointments-table" )
147+ past .get_by_text ("View details" ).first .click ()
148+
149+ def then_i_should_be_on_the_past_appointment_page (self ):
150+ path = reverse (
151+ "mammograms:start_screening" ,
152+ kwargs = {"id" : self .past_appointments [0 ].pk },
153+ )
154+ expect (self .page ).to_have_url (re .compile (path ))
155+
156+ def then_i_should_be_on_the_upcoming_appointment_page (self ):
157+ path = reverse (
158+ "mammograms:start_screening" ,
159+ kwargs = {"id" : self .upcoming_appointment .pk },
75160 )
76161 expect (self .page ).to_have_url (re .compile (path ))
0 commit comments