|
| 1 | +# pylint: disable=no-name-in-module |
| 2 | +import re |
| 3 | +from behave import given, when, then # pyright: ignore [reportAttributeAccessIssue] |
| 4 | +from playwright.sync_api import expect |
| 5 | + |
| 6 | +from pages.change_role import ChangeRole |
| 7 | + |
| 8 | + |
| 9 | +selected_role_url_pattern = re.compile(r".*/yourselectedrole(?:/|\.html)?$") |
| 10 | +change_role_url_pattern = re.compile(r".*/changerole(?:/|\.html)?$") |
| 11 | + |
| 12 | + |
| 13 | +############################################################################ |
| 14 | +# GIVEN STEPS |
| 15 | +############################################################################ |
| 16 | + |
| 17 | + |
| 18 | +@given("I am on the change your role page") |
| 19 | +def given_i_am_on_the_change_role_page(context): |
| 20 | + context.execute_steps("when I navigate to the change your role page") |
| 21 | + change_role_page = ChangeRole(context.page) |
| 22 | + |
| 23 | + change_role_page.page.wait_for_url(change_role_url_pattern) |
| 24 | + |
| 25 | + |
| 26 | +@given("the summary table body is displayed") |
| 27 | +def given_the_summary_table_body_is_displayed(context): |
| 28 | + change_role_page = ChangeRole(context.page) |
| 29 | + |
| 30 | + # Expand the summary if it's not visible yet |
| 31 | + if not change_role_page.roles_without_access_table_body.is_visible(): |
| 32 | + change_role_page.roles_without_access_table.click() |
| 33 | + expect(change_role_page.roles_without_access_table_body).to_be_visible() |
| 34 | + |
| 35 | + |
| 36 | +@given("I am on the 'your selected role' page") |
| 37 | +def given_i_am_on_your_selected_role_page(context): |
| 38 | + change_role_page = ChangeRole(context.page) |
| 39 | + context.execute_steps("given I am on the change your role page") |
| 40 | + context.execute_steps("when I click a role card") |
| 41 | + expect(change_role_page.select_role_header).to_be_visible() |
| 42 | + |
| 43 | + |
| 44 | +############################################################################ |
| 45 | +# WHEN STEPS |
| 46 | +############################################################################ |
| 47 | + |
| 48 | + |
| 49 | +@when("I click on the change role summary expander") |
| 50 | +def when_i_click_on_the_summary_expander(context): |
| 51 | + change_role_page = ChangeRole(context.page) |
| 52 | + change_role_page.roles_without_access_table.click() |
| 53 | + |
| 54 | + |
| 55 | +@when("I click a change role role card") |
| 56 | +def when_i_click_a_role_card(context): |
| 57 | + change_role_page = ChangeRole(context.page) |
| 58 | + expect(change_role_page.first_role_card).to_be_visible() |
| 59 | + change_role_page.first_role_card.click() |
| 60 | + |
| 61 | + # Wait for the page or route change |
| 62 | + context.page.wait_for_url(selected_role_url_pattern) |
| 63 | + |
| 64 | + |
| 65 | +@when("I click the change role header link") |
| 66 | +def when_i_click_change_role_header_link(context): |
| 67 | + change_role_page = ChangeRole(context.page) |
| 68 | + change_role_page.page.get_by_test_id("eps_header_changeRoleLink").click() |
| 69 | + |
| 70 | + |
| 71 | +@when("I navigate to the change your role page") |
| 72 | +def when_i_navigate_to_the_change_your_role_page(context): |
| 73 | + change_role_page = ChangeRole(context.page) |
| 74 | + |
| 75 | + change_role_page.page.goto(context.cpts_ui_base_url + "site") |
| 76 | + change_role_page.change_role_header.click() |
| 77 | + change_role_page.page.wait_for_url(change_role_url_pattern, timeout=5000) |
| 78 | + |
| 79 | + |
| 80 | +############################################################################ |
| 81 | +# THEN STEPS |
| 82 | +############################################################################ |
| 83 | + |
| 84 | + |
| 85 | +@then("I see the change role roles without access table") |
| 86 | +def then_i_see_the_roles_without_access_table(context): |
| 87 | + change_role_page = ChangeRole(context.page) |
| 88 | + expect(change_role_page.roles_without_access_table).to_be_visible() |
| 89 | + |
| 90 | + # Check header row |
| 91 | + expect( |
| 92 | + change_role_page.roles_without_access_organisation_column_header |
| 93 | + ).to_be_visible() |
| 94 | + expect(change_role_page.roles_without_access_role_column_header).to_be_visible() |
| 95 | + |
| 96 | + # Check data |
| 97 | + expect(change_role_page.first_row_org_name).to_be_visible() |
| 98 | + expect(change_role_page.first_row_role_name).to_be_visible() |
| 99 | + |
| 100 | + |
| 101 | +@then("the change role roles without access table body is not visible") |
| 102 | +def then_roles_without_access_table_body_is_not_visible(context): |
| 103 | + change_role_page = ChangeRole(context.page) |
| 104 | + expect(change_role_page.roles_without_access_table_body).not_to_be_visible() |
| 105 | + |
| 106 | + |
| 107 | +@then("I see the change role roles with access cards") |
| 108 | +def then_i_see_the_roles_with_access_cards(context): |
| 109 | + change_role_page = ChangeRole(context.page) |
| 110 | + expect(change_role_page.first_role_card).to_be_visible() |
| 111 | + |
| 112 | + |
| 113 | +@then("I can see multiple change role roles with access cards") |
| 114 | +def then_i_see_multiple_change_role_roles_with_access_cards(context): |
| 115 | + change_role_page = ChangeRole(context.page) |
| 116 | + assert change_role_page.roles_with_access_cards.count() > 1 |
| 117 | + |
| 118 | + |
| 119 | +@then("I can see one change role roles with access cards") |
| 120 | +def then_i_see_one_change_role_roles_with_access_cards(context): |
| 121 | + change_role_page = ChangeRole(context.page) |
| 122 | + assert change_role_page.roles_with_access_cards.count() == 1 |
| 123 | + |
| 124 | + |
| 125 | +@then("I cannot see any change role roles with access cards") |
| 126 | +def then_i_cant_see_roles_with_access_cards(context): |
| 127 | + change_role_page = ChangeRole(context.page) |
| 128 | + expect(change_role_page.first_role_card).not_to_be_visible() |
| 129 | + |
| 130 | + |
| 131 | +@then("I am on the 'your selected role' page") |
| 132 | +def then_i_am_on_your_selected_role_page(context): |
| 133 | + context.page.wait_for_url(selected_role_url_pattern) |
| 134 | + |
| 135 | + |
| 136 | +@then("I do not see the change role page header link") |
| 137 | +def then_i_can_not_see_the_change_your_role_page_header_link(context): |
| 138 | + change_role_page = ChangeRole(context.page) |
| 139 | + expect(change_role_page.change_role_header).not_to_be_visible() |
| 140 | + |
| 141 | + |
| 142 | +@then("I see the change role page 'no role with access' warning message") |
| 143 | +def i_see_the_change_role_page_no_role_with_access_warning_message(context): |
| 144 | + change_role_page = ChangeRole(context.page) |
| 145 | + expect(change_role_page.no_access_title).to_be_visible() |
| 146 | + expect(change_role_page.no_access_content).to_be_visible() |
0 commit comments