Skip to content

Commit

Permalink
Journey tests working with my details page, locally at least.
Browse files Browse the repository at this point in the history
  • Loading branch information
brunns committed Jun 14, 2024
1 parent 9cd3d4f commit 59e4d4b
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 10 deletions.
2 changes: 1 addition & 1 deletion django_app/redbox_app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ <h2 class="govuk-visually-hidden">Support links</h2>
</li>
<li class="govuk-footer__inline-list-item">
<a class="govuk-footer__link" href="{{ url('demographics') }}">
My Details
My details
</a>
</li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion django_app/redbox_app/templates/demographics.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% set pageTitle = "My Details" %}
{% set pageTitle = "My details" %}
{% extends "base.html" %}
{% from "macros/govuk-button.html" import govukButton %}
{% from "macros/govuk-notification-banner.html" import govukNotificationBanner %}
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ exclude = ["django_app/redbox_app/redbox_core/migrations/*.py", "out/*"]
ignore = ["COM812", "DJ001", "RET505", "RET508"]

[tool.ruff.lint.per-file-ignores]
"tests/*" = ["S101", "S106", "PLR0913", "PLR2004", "TD003"]
"tests/*" = ["S101", "S106", "PLR0913", "PLR2004", "TD003", "S311"]
"*/tests/*" = ["S101", "S106", "PLR0913", "PLR2004", "TD003"]
"django_app/tests_playwright/*" = ["S101", "S106", "PLR0913", "PLR2004", "TD003"]
"worker/*" = ["B008"]
Expand Down
1 change: 0 additions & 1 deletion tests/data/csv/profession.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ Full Stack Developer
QA
Devops Engineer
Policy
1:09
Could commercial
44 changes: 41 additions & 3 deletions tests/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from itertools import islice
from pathlib import Path
from time import sleep, strptime
from typing import Any, ClassVar, NamedTuple
from typing import Any, ClassVar, NamedTuple, Union

from axe_playwright_python.sync_playwright import Axe
from playwright.sync_api import Locator, Page, expect
Expand Down Expand Up @@ -97,6 +97,10 @@ def navigate_to_chats(self) -> "ChatsPage":
self.page.get_by_role("link", name="Chats", exact=True).click()
return ChatsPage(self.page)

def navigate_my_details(self) -> "MyDetailsPage":
self.page.get_by_role("link", name="My details", exact=True).click()
return MyDetailsPage(self.page)

def sign_out(self) -> "LandingPage":
self.page.get_by_role("link", name="Chats", exact=True).click()
return LandingPage(self.page)
Expand Down Expand Up @@ -149,9 +153,9 @@ def __init__(self, page, magic_link: URL):
def expected_page_title(self) -> str:
return "Sign in - confirmation - Redbox Copilot"

def navigate_to_documents_page(self) -> "DocumentsPage":
def start(self) -> Union["DocumentsPage", "MyDetailsPage"]:
self.page.get_by_role("button", name="Start", exact=True).click()
return DocumentsPage(self.page)
return MyDetailsPage(self.page) if self.page.title().startswith("My Details") else DocumentsPage(self.page)


class HomePage(SignedInBasePage):
Expand All @@ -160,6 +164,40 @@ def expected_page_title(self) -> str:
return "Redbox Copilot"


class MyDetailsPage(SignedInBasePage):
@property
def expected_page_title(self) -> str:
return "My Details - Redbox Copilot"

@property
def grade(self) -> str:
return self.page.get_by_label("Grade").get_by_role(role="option", selected=True).inner_text()

@grade.setter
def grade(self, grade: str):
self.page.get_by_label("Grade").select_option(grade)

@property
def business_unit(self) -> str:
return self.page.get_by_label("Business unit").get_by_role(role="option", selected=True).inner_text()

@business_unit.setter
def business_unit(self, grade: str):
self.page.get_by_label("Business unit").select_option(grade)

@property
def profession(self) -> str:
return self.page.get_by_label("Profession").get_by_role(role="option", selected=True).inner_text()

@profession.setter
def profession(self, grade: str):
self.page.get_by_label("Profession").select_option(grade)

def update(self) -> "DocumentsPage":
self.page.get_by_text("Update").click()
return DocumentsPage(self.page)


class DocumentRow(NamedTuple):
filename: str
uploaded_at: datetime
Expand Down
35 changes: 32 additions & 3 deletions tests/test_journey.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
TEST_ROOT = Path(__file__).parent


def test_user_journey(page: Page, email_address: str):
def test_user_journey(page: Page, email_address: str): # noqa: PLR0915
"""End to end user journey test.
Simulates a single user journey through the application, running against the full suite of microservices.
Expand All @@ -42,8 +42,15 @@ def test_user_journey(page: Page, email_address: str):
logger.debug("magic_link: %s", magic_link)
sign_in_confirmation_page = SignInConfirmationPage(page, magic_link)

# My details page
my_details_page = sign_in_confirmation_page.start()
grade, business_unit, profession = create_demographic_reference_data(page)
my_details_page.grade = grade
my_details_page.business_unit = business_unit
my_details_page.profession = profession

# Documents page
documents_page = sign_in_confirmation_page.navigate_to_documents_page()
documents_page = my_details_page.update()
original_doc_count = documents_page.document_count()

# Upload files
Expand Down Expand Up @@ -140,5 +147,27 @@ def get_magic_link(email_address: str) -> URL:

@pytest.fixture()
def email_address() -> str:
username = "".join(choice(string.ascii_lowercase) for _ in range(20)) # noqa: S311
username = "".join(choice(string.ascii_lowercase) for _ in range(20))
return f"{username}@cabinetoffice.gov.uk"


def create_demographic_reference_data(page: Page) -> tuple[str, str, str]:
"""I am not proud of this."""
grade, business_unit, profession = tuple(
"".join(choice(string.ascii_lowercase) for _ in range(20)) for _ in range(3)
)
admin_url = BASE_URL / "admin" / "redbox_core"
placeholder = page.url

add_via_admin(admin_url / "usergrade" / "add", grade, page)
add_via_admin(admin_url / "businessunit" / "add", business_unit, page)
add_via_admin(admin_url / "profession" / "add", profession, page)

page.goto(placeholder)
return grade, business_unit, profession


def add_via_admin(url, value, page):
page.goto(str(url))
page.get_by_label("Name:").fill(value)
page.get_by_role("button", name="Save", exact=True).click()

0 comments on commit 59e4d4b

Please sign in to comment.