|
| 1 | +from behave import when, then # pyright: ignore [reportAttributeAccessIssue] |
| 2 | +from playwright.sync_api import expect |
| 3 | + |
| 4 | +from pages.prescription_details import PrescriptionDetailsPage |
| 5 | + |
| 6 | +# FIXME: Remove references to the dev link when we can navigate properly to the prescription details |
| 7 | +from pages.prescription_list_page import PrescriptionListPage |
| 8 | + |
| 9 | + |
| 10 | +@when('I go to the prescription details for prescription ID "{prescription_id}"') |
| 11 | +def i_go_to_prescription_details_for_prescription_id(context, prescription_id): |
| 12 | + context.execute_steps( |
| 13 | + f""" |
| 14 | + When I search for a prescription using a valid prescription ID "{prescription_id}" |
| 15 | + And I click through to the prescription details page |
| 16 | + """ |
| 17 | + ) |
| 18 | + |
| 19 | + |
| 20 | +# FIXME: THIS IS FOR DEVELOPMENT ONLY - DELETE IT WHEN WE HAVE A PROPER USER FLOW!!! |
| 21 | +@when("I click through to the prescription details page") |
| 22 | +def i_click_to_prescription_details_page(context): |
| 23 | + page = PrescriptionListPage(context.page) |
| 24 | + page.dev_link.click() |
| 25 | + |
| 26 | + context.page.wait_for_load_state() |
| 27 | + |
| 28 | + |
| 29 | +@then("The {org} site card is {visibility}") |
| 30 | +def site_card_visibility_check(context, org, visibility): |
| 31 | + page = PrescriptionDetailsPage(context.page) |
| 32 | + |
| 33 | + expect_prescribed_from_field = False |
| 34 | + match org: |
| 35 | + case "prescriber": |
| 36 | + card = page.prescriber_card |
| 37 | + expect_prescribed_from_field = True |
| 38 | + case "dispenser": |
| 39 | + card = page.dispenser_card |
| 40 | + case "nominated dispenser": |
| 41 | + card = page.nominated_dispenser_card |
| 42 | + case _: |
| 43 | + raise ValueError(f"Unrecognised site definition: {org}") |
| 44 | + |
| 45 | + if visibility == "visible": |
| 46 | + expect(card).to_be_visible() |
| 47 | + if expect_prescribed_from_field: |
| 48 | + expect(page.prescribed_from_field) |
| 49 | + |
| 50 | + elif visibility == "not visible": |
| 51 | + expect(card).not_to_be_visible() |
| 52 | + if expect_prescribed_from_field: |
| 53 | + expect(page.prescribed_from_field) |
| 54 | + |
| 55 | + else: |
| 56 | + raise ValueError(f"Unrecognised visibility definition: {visibility}") |
0 commit comments