Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Methodology page UI tests #102

Merged
merged 34 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
9a51654
Add fix from PR #101
kacperpONS Feb 12, 2025
fb62b84
Merge branch 'main' into methodology-page-ui-tests-CMS-323
kacperpONS Feb 12, 2025
98ba8a4
Added the test
kacperpONS Feb 13, 2025
bfba37f
Ignore pylint errors
kacperpONS Feb 13, 2025
651fd5c
Make them pass
kacperpONS Feb 13, 2025
d49d9f2
Fix an issue with tests failing in headless and passing in headed mode
kacperpONS Feb 13, 2025
aec1e54
Merge branch 'main' into methodology-page-ui-tests-CMS-323
kacperpONS Feb 13, 2025
eea9a2f
Rewording to match steps pulled from main
kacperpONS Feb 14, 2025
87625be
Formatting + rewording
kacperpONS Feb 14, 2025
8f9754f
Revert a change to make tests pass
kacperpONS Feb 14, 2025
d2f07a6
A bunch of improvements
kacperpONS Feb 14, 2025
9da95a6
Remove no longer needed file for theme page set up
kacperpONS Feb 14, 2025
fa52b91
Remove duplicated step definition
kacperpONS Feb 14, 2025
4b8c769
Add missing assertion
kacperpONS Feb 17, 2025
45d784b
Topic page test fix
kacperpONS Feb 17, 2025
3a63889
Added missing checks + where I got with testing preview (failing so c…
kacperpONS Feb 17, 2025
4897f99
Formatting - all green locally
kacperpONS Feb 17, 2025
2f944a2
Test
kacperpONS Feb 17, 2025
b6cf356
Attempt to fix headless failures
zerolab Feb 18, 2025
6fa3b21
Bump the wait time a bit
zerolab Feb 18, 2025
0c8bdbc
Refactor the fix above into it's own step
kacperpONS Feb 18, 2025
5f6f6a0
Uncommented the preview test
kacperpONS Feb 18, 2025
6e37061
Added a test for the draft functionality of the page
kacperpONS Feb 18, 2025
add2895
Refactoring
kacperpONS Feb 19, 2025
7260ac0
Renamed a test function
kacperpONS Feb 20, 2025
6031393
Experiment - removed the delay in preview test
kacperpONS Feb 21, 2025
2e69f7f
^ the same for the mandatory fields scenario 🤔
kacperpONS Feb 21, 2025
e9cb0a5
Add back the delay for mandatory fields scenario + make step wording …
kacperpONS Feb 21, 2025
c5f28f7
Experiment - move the delay to the 'then' step of the mandatory field…
kacperpONS Feb 21, 2025
ffff22d
^ revert the above
kacperpONS Feb 21, 2025
f70920f
Experiment - replace delay with wait_for_load_state
kacperpONS Feb 21, 2025
eb87cf1
^ the same but after clicking the button
kacperpONS Feb 21, 2025
ac9c421
Revert to using delay
kacperpONS Feb 21, 2025
9755549
Test improvements
kacperpONS Feb 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions functional_tests/features/methodology_page.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Feature: A general use of Methodology Page

Scenario: A CMS user can create and publish a Methodology Page
Given a theme page exists
And a topic page exists as a child of the existing theme page
And a CMS user logs into the admin site
When the user creates a methodology page as a child of the existing topic page
And the user populates the methodology page
And the user clicks publish page
And the user clicks "View Live" on the publish confirmation banner
Then the published methodology page is displayed with the populated data

Scenario: A CMS user can add a published statistical articles in the Related publication section of the Methodology page
Given a theme page exists
And a topic page exists as a child of the existing theme page
And a statistical article page has been published under the existing theme page
And a CMS user logs into the admin site
When the user creates a methodology page as a child of the existing topic page
And the user populates the methodology page
And the user selects the article page in the Related publications block
And the user clicks publish page
And the user clicks "View Live" on the publish confirmation banner
Then the article is displayed correctly under the Related publication section

Scenario: A CMS user can add a Contact Details snippet on the Methodology page
Given a theme page exists
And a topic page exists as a child of the existing theme page
And a contact details snippet exists
And a CMS user logs into the admin site
When the user creates a methodology page as a child of the existing topic page
And the user populates the methodology page
And the user selects the Contact Details
And the user clicks publish page
And the user clicks "View Live" on the publish confirmation banner
Then the Contact Details are visible on the page

Scenario: The mandatory fields raise validation errors when left empty on the Methodology page.
Given a theme page exists
And a topic page exists as a child of the existing theme page
And a CMS user logs into the admin site
When the user creates a methodology page as a child of the existing topic page
And the user clicks Save draft
Then the mandatory fields raise a validation error

Scenario: The Last revised date field has appropriate validation on Methodology page.
Given a theme page exists
And a topic page exists as a child of the existing theme page
And a CMS user logs into the admin site
When the user creates a methodology page as a child of the existing topic page
And the user populates the methodology page
And the Last revised date is set to be before the Publication date
And the user clicks Save draft
Then a validation error for the Last revised date is displayed

10 changes: 10 additions & 0 deletions functional_tests/steps/article_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from behave import given
from behave.runner import Context

from cms.articles.tests.factories import ArticleSeriesFactory, StatisticalArticlePageFactory


@given("a statistical article page has been published under the existing theme page")
def create_article_page(context: Context):
context.article_series = ArticleSeriesFactory(parent=context.topic_page)
context.statistical_article = StatisticalArticlePageFactory(parent=context.article_series)
100 changes: 100 additions & 0 deletions functional_tests/steps/methodology_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
from behave import then, when
from behave.runner import Context
from playwright.sync_api import expect


@when("the user creates a methodology page as a child of the existing topic page")
def user_creates_methodology_page(context: Context):
context.page.get_by_role("button", name="Pages").click()
context.page.get_by_role("link", name="View child pages of 'Home'").click()
context.page.get_by_role("link", name=f"View child pages of '{context.theme_page.title}'").click()
context.page.get_by_role("link", name=f"Edit '{context.topic_page.title}'").click()
context.page.get_by_role("button", name="Actions", exact=True).click()
context.page.get_by_label(f"Add a child page to '{context.topic_page.title}'").click()
context.page.get_by_role("link", name="Methodology page", exact=True).click()


@when("the user populates the methodology page")
def user_populates_the_methodology_page(context: Context):
context.page.get_by_placeholder("Page title*").fill("Methodology page")
context.page.get_by_role("region", name="Summary*").get_by_role("textbox").fill("Page summary")

context.page.get_by_label("Publication date*").fill("1950-01-01")

context.page.get_by_title("Insert a block").click()
context.page.get_by_label("Section heading*").fill("Heading")
context.page.locator("#panel-child-content-content-content").get_by_role("region").get_by_role(
"button", name="Insert a block"
).click()
context.page.get_by_text("Rich text").click()
context.page.get_by_role("region", name="Rich text *").get_by_role("textbox").fill("Content")


@then("the published methodology page is displayed with the populated data")
def the_methodology_page_is_displayed_correctly(context: Context):
expect(context.page.get_by_role("heading", name="Methodology page")).to_be_visible()

expect(context.page.get_by_text("Page summary")).to_be_visible()

expect(context.page.get_by_text("Published: 1 January 1950")).to_be_visible()

expect(context.page.get_by_role("heading", name="Cite this methodology")).to_be_visible()


@when("the user selects the article page in the Related publications block")
def the_user_selects_statistical_articles_as_related_publications(context: Context):
context.page.get_by_role("button", name="Add related publications").click()
context.page.get_by_role("button", name="Choose a page (Statistical").click()
context.page.get_by_role(
"cell", name=f"{context.article_series.title}: {context.statistical_article.title}"
).click()


@then("the article is displayed correctly under the Related publication section")
def related_publications_are_displayed_correctly(context: Context):
expect(context.page.get_by_role("heading", name="Related publications")).to_be_visible()
expect(context.page.locator("li").filter(has_text=f"{context.topic_page.title}")).to_be_visible()


@when("the user selects the Contact Details")
def user_selects_the_contact_details(context: Context):
context.page.get_by_role("button", name="Choose contact details").click()
context.page.get_by_role("link", name=context.contact_details_snippet.name).click()


@then("the Contact Details are visible on the page")
def contact_details_are_visible_on_the_page(context: Context):
# in the header
expect(context.page.get_by_text(f"Contact: {context.contact_details_snippet.name}")).to_be_visible()
# in the section
expect(context.page.get_by_role("heading", name="Contact details")).to_be_visible()
expect(context.page.get_by_text(f"Name: {context.contact_details_snippet.name}")).to_be_visible()
expect(context.page.get_by_text(f"Email: {context.contact_details_snippet.email}")).to_be_visible()


@when("the Last revised date is set to be before the Publication date")
def set_last_revised_date_before_publication_date(context: Context):
context.page.get_by_label("Publication date*").fill("1950-01-02")
context.page.get_by_label("Last revised date").fill("1950-01-01")


@then("a validation error for the Last revised date is displayed")
def validation_error_displayed_when_incorrect_date_selected(context: Context):
expect(context.page.get_by_text("The last revised date must be after the published date.")).to_be_visible()


@then("the mandatory fields raise a validation error")
def mandatory_fields_raise_validation_error_when_not_set(context: Context):
expect(context.page.get_by_text("The page could not be created due to validation errors")).to_be_visible()

expect(context.page.locator("#panel-child-content-child-title-errors")).to_be_visible()
expect(context.page.locator("#panel-child-content-child-summary-errors")).to_be_visible()
expect(
context.page.locator("#panel-child-content-child-metadata-child-panel-child-publication_date-errors")
).to_be_visible()
expect(context.page.locator(".help-block.help-critical").get_by_text("This field is required"))


@when("the user clicks Save draft")
def user_saves_draft(context: Context):
context.page.get_by_role("button", name="Save draft").click()
9 changes: 9 additions & 0 deletions functional_tests/steps/theme_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from behave import given
from behave.runner import Context

from cms.themes.tests.factories import ThemePageFactory


@given("a theme page exists")
def a_theme_page_already_exists(context: Context):
context.theme_page = ThemePageFactory()
9 changes: 9 additions & 0 deletions functional_tests/steps/topic_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from behave import given
from behave.runner import Context

from cms.topics.tests.factories import TopicPageFactory


@given("a topic page exists as a child of the existing theme page")
def a_topic_page_already_exists_under_theme_page(context: Context):
context.topic_page = TopicPageFactory(parent=context.theme_page)
Loading