Skip to content

Commit 2117c54

Browse files
authored
Chore: [AEA-5061] - Create test for redirection logic. Minor refactoring around that. (#266)
## Summary - Routine Change ### Details When the user does not have a selected role, the only page they should be able to go to is the select your role page, and the logout page.
1 parent fda9508 commit 2117c54

File tree

8 files changed

+66
-18
lines changed

8 files changed

+66
-18
lines changed

features/cpts_ui/change_role.feature

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Feature: Users are able to change their roles, if they have multiple roles with
99
@multiple_access
1010
Scenario: User can change their role
1111
Given I am logged in as a user with multiple access roles
12+
And I have selected a role
1213
And I am on the change your role page
1314
When I click a change role role card
1415
Then I am on the 'your selected role' page
@@ -17,6 +18,7 @@ Feature: Users are able to change their roles, if they have multiple roles with
1718
@multiple_access
1819
Scenario: User can see roles with access cards
1920
Given I am logged in as a user with multiple access roles
21+
And I have selected a role
2022
And I am on the change your role page
2123
Then I see the change role roles with access cards
2224
And I can see multiple change role roles with access cards
@@ -29,13 +31,15 @@ Feature: Users are able to change their roles, if they have multiple roles with
2931
@multiple_access
3032
Scenario: Change role roles without access table body is not visible by default
3133
Given I am logged in as a user with multiple access roles
34+
And I have selected a role
3235
And I am on the change your role page
3336
Then the change role roles without access table body is not visible
3437

3538
@allure.tms:https://nhsd-jira.digital.nhs.uk/browse/AEA-4653
3639
@multiple_access
3740
Scenario: User can expand the change role 'Roles without access' to see table contents
3841
Given I am logged in as a user with multiple access roles
42+
And I have selected a role
3943
And I am on the change your role page
4044
When I click on the change role summary expander
4145
Then I see the change role roles without access table
@@ -44,6 +48,7 @@ Feature: Users are able to change their roles, if they have multiple roles with
4448
@multiple_access
4549
Scenario: User can collapse the change role 'Roles without access' to hide table contents
4650
Given I am logged in as a user with multiple access roles
51+
And I have selected a role
4752
And I am on the change your role page
4853
And the summary table body is displayed
4954
When I click on the change role summary expander
@@ -59,6 +64,7 @@ Feature: Users are able to change their roles, if they have multiple roles with
5964

6065
Scenario: user can change their role, and see a confirmation page
6166
Given I am logged in as a user with multiple access roles
67+
And I have selected a role
6268
And I am on the change your role page
6369
When I click a change role role card
6470
Then I see the 'your selected role' page
@@ -71,6 +77,7 @@ Feature: Users are able to change their roles, if they have multiple roles with
7177
@allure.tms:https://nhsd-jira.digital.nhs.uk/browse/AEA-4974
7278
Scenario: User can change their role and see the correct message on the change role page
7379
Given I am logged in as a user with multiple access roles
80+
And I have selected a role
7481
And I have confirmed a role
7582
And I am on the change your role page
7683
And I click a change role role card

features/cpts_ui/header.feature

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,39 +37,36 @@ Feature: Header
3737
Then I see the "Logout" link
3838

3939
Scenario: Logout link is not shown if user is not logged in
40-
When I go to the homepage
40+
When I go to the home page
4141
Then I do not see the "Logout" link
4242

4343
############################################################################
4444
# SELECT YOUR ROLE
4545
############################################################################
46-
Scenario: Select Your Role link is shown on the homepage, if we dont select a role
47-
Given I am logged in as a user with multiple access roles
48-
When I go to the homepage
49-
Then I see the "Select Your Role" link
50-
5146
Scenario: Select Your Role link is not shown if I go to the select your role page
5247
Given I am logged in as a user with multiple access roles
53-
When I go to the homepage
54-
And I click the "Select Your Role" link
48+
When I go to the select your role page
5549
Then I do not see the "Select Your Role" link
5650

5751
Scenario: Select Your Role link is not shown if I already have a selected role
5852
Given I am logged in as a user with a pre selected role
59-
When I go to the homepage
53+
When I go to the home page
6054
Then I do not see the "Select Your Role" link
6155

6256
############################################################################
6357
# CHANGE ROLE
6458
############################################################################
6559
Scenario: Change Role link is shown if the user has a selected role
6660
Given I am logged in as a user with multiple access roles
67-
When I go to the homepage
61+
And I have selected a role
62+
And I have confirmed a role
63+
When I go to the home page
6864
Then I see the "Change Role" link
6965

7066
Scenario: Change Role link is not shown if the user has no selected role
7167
Given I am logged in as a user with multiple access roles
72-
When I go to the homepage
68+
And I have selected a role
69+
When I go to the home page
7370
Then I do not see the "Change Role" link
7471

7572
# FIXME: Address this when the SPA is fixed!
@@ -78,11 +75,12 @@ Feature: Header
7875
# @fixme
7976
# Scenario: Change Role link is not shown if I go to the select your role page
8077
# Given I am logged in
81-
# When I have a selected role
78+
# When I have selected a role
8279
# And I go to the select your role page
8380
# Then I do not see the "Change Role" link
8481

8582
Scenario: Change Role link is not shown if I am on the change role page
8683
Given I am logged in as a user with multiple access roles
84+
And I have selected a role
8785
When I go to change my role
8886
Then I do not see the "Change Role" link

features/cpts_ui/home.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Feature: I can visit the Clinical Prescription Tracker Service Website
66
@allure.tms:https://nhsd-jira.digital.nhs.uk/browse/AEA-4515
77
@allure.tms:https://nhsd-jira.digital.nhs.uk/browse/AEA-4513
88
Scenario: user can navigate to the Clinical Prescription Tracker Service Website homepage
9-
When I go to the homepage
9+
When I go to the home page
1010
Then I am on the homepage
1111
And I can see the header
1212
And I can see the footer

features/cpts_ui/notfound.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Feature: The site has a 404 not found page
88

99
Scenario: The user sees a "Page not found" error page when they navigate to an unknown page while logged in
1010
Given I am logged in as a user with multiple access roles
11+
And I have selected a role
1112
When I navigate to a non-existent page
1213
Then I am on the logged in Page Not Found page
1314

features/cpts_ui/select_your_role.feature

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ Feature: Role selection page renders roles properly when logged in
1212
And I can see the summary container
1313
And I cannot see the summary table body
1414

15+
@allure.tms:https://nhsd-jira.digital.nhs.uk/browse/AEA-5061
16+
Scenario: I am redirected to the select your role page if I have no role selected
17+
When I log in as a user with multiple access roles
18+
And the login has finished
19+
And I go to the search for a prescription page
20+
Then I can see the summary container
21+
1522
@allure.tms:https://nhsd-jira.digital.nhs.uk/browse/AEA-4653
1623
Scenario: I can show the available role information
1724
Given I am logged in as a user with multiple access roles

features/cpts_ui/your_selected_role.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Feature: When the user selects a role, they see a confirmation page
44

55
Background:
66
Given I am logged in as a user with multiple access roles
7+
And I have selected a role
78

89
Scenario: user is able to select a role, and see a confirmation page
910
When I click a change role role card

features/steps/cpts_ui/home_steps.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,24 @@
66
from pages.footer import Footer
77

88

9-
@when("I go to the homepage")
10-
def goto_page(context):
11-
context.page.goto(context.cpts_ui_base_url + "site/")
9+
@when("I go to the {page} page")
10+
def goto_page(context, page):
11+
target = ""
12+
13+
if page == "home":
14+
target = ""
15+
elif page == "search for a prescription":
16+
target = "searchforaprescription"
17+
elif page == "select your role":
18+
target = "selectyourrole"
19+
20+
url = f"{context.cpts_ui_base_url}site/{target}"
21+
context.page.goto(url)
1222

1323

1424
@given("I am on the homepage")
1525
def i_am_on_the_home_page(context):
16-
goto_page(context)
26+
goto_page(context, "home")
1727
header = Header(context.page)
1828
header.page.is_visible(header.header)
1929

features/steps/cpts_ui/login_steps.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ def login_single_role(context):
3232
@given("I am logged in as a user with multiple access roles")
3333
def login_multiple_access_roles(context):
3434
context.execute_steps("when I log in as a user with multiple access roles")
35-
context.execute_steps("When I select a role")
3635

3736

3837
@given("I am logged in as a user with only roles that do not have access")
@@ -65,6 +64,8 @@ def login_with_multiple_access_roles(context):
6564
context.page.get_by_label("Username").fill(MOCK_CIS2_LOGIN_ID_MULTIPLE_ACCESS_ROLES)
6665
context.page.get_by_role("button", name="Sign In").click()
6766

67+
context.execute_steps("When the login has finished")
68+
6869

6970
@when("I log in as a user with no roles")
7071
def login_with_no_roles(context):
@@ -74,6 +75,8 @@ def login_with_no_roles(context):
7475
context.page.get_by_label("Username").fill(MOCK_CIS2_LOGIN_ID_NO_ROLES)
7576
context.page.get_by_role("button", name="Sign In").click()
7677

78+
context.execute_steps("When the login has finished")
79+
7780

7881
@when("I log in as a user with only roles that do not have access")
7982
def login_with_without_access(context):
@@ -83,6 +86,8 @@ def login_with_without_access(context):
8386
context.page.get_by_label("Username").fill(MOCK_CIS2_LOGIN_ID_NO_ACCESS_ROLE)
8487
context.page.get_by_role("button", name="Sign In").click()
8588

89+
context.execute_steps("When the login has finished")
90+
8691

8792
@when("I log in with a single access role and multiple without access")
8893
def login_with_single_role_with_access_multiple_without(context):
@@ -94,6 +99,8 @@ def login_with_single_role_with_access_multiple_without(context):
9499
)
95100
context.page.get_by_role("button", name="Sign In").click()
96101

102+
context.execute_steps("When the login has finished")
103+
97104

98105
@when("I log in as a user with a pre selected role")
99106
def login_with_pre_role_selected(context):
@@ -104,6 +111,8 @@ def login_with_pre_role_selected(context):
104111
)
105112
context.page.get_by_role("button", name="Sign In").click()
106113

114+
context.execute_steps("When the login has finished")
115+
107116

108117
@when("I log in as a user with a single access role")
109118
def login_with_single_role(context):
@@ -113,6 +122,21 @@ def login_with_single_role(context):
113122
context.page.get_by_label("Username").fill(MOCK_CIS2_LOGIN_ID_SINGLE_ACCESS_ROLE)
114123
context.page.get_by_role("button", name="Sign In").click()
115124

125+
context.execute_steps("When the login has finished")
126+
127+
128+
@when("The login has finished")
129+
def the_login_is_finished(context):
130+
def logged_in_urls(url):
131+
valid_urls = [
132+
f"{context.cpts_ui_base_url}site/selectyourrole",
133+
f"{context.cpts_ui_base_url}site/selectyourrole/",
134+
]
135+
return url in valid_urls
136+
137+
context.page.wait_for_url(logged_in_urls)
138+
context.execute_steps("then I am logged in")
139+
116140

117141
###############################################################################
118142
# THEN STEPS

0 commit comments

Comments
 (0)