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

Add a spec for the Content Object Store #46

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 12 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect } from "@playwright/test";

function publishingAppUrl(appName) {
return `https://${appName}.${process.env.PUBLISHING_DOMAIN}`;
}
Expand All @@ -8,4 +10,13 @@ async function logIntoSignon(page) {
await page.getByRole("button", { name: "Sign in" }).click();
}

export { publishingAppUrl, logIntoSignon };
async function waitForUrlToBeAvailable(page, url) {
await expect(async () => {
url = `${url}?cacheBust=${new Date().getTime()}`;
const response = await page.request.get(url);
expect(response.status()).toBe(200);
}).toPass();
return url;
}

export { publishingAppUrl, logIntoSignon, waitForUrlToBeAvailable };
115 changes: 115 additions & 0 deletions tests/content-block-manager.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { expect } from "@playwright/test";
import { test } from "../lib/cachebust-test";
import { publishingAppUrl, waitForUrlToBeAvailable } from "../lib/utils";

test.describe("Content Block Manager", { tag: ["@app-content-object-store", "@integration"] }, () => {
test.use({ baseURL: publishingAppUrl("whitehall-admin") });

test("Can create and embed an object", async ({ page }) => {
await test.step("Logging in", async () => {
await page.goto("/content-block-manager");
await expect(page.getByRole("banner", { text: "Content Block Manager" })).toBeVisible();
await expect(page.getByRole("heading", { name: "All content blocks" })).toBeVisible();
});

const title = await test.step("Can create an object", async () => {
const title = `E2E TEST EMAIL - ${new Date().getTime()}`;

await page.goto("/content-block-manager");
await page.getByRole("button", { text: "Create new object" }).click();
await page.getByLabel("Email address").click();
await page.getByRole("button", { text: "Save and continute" }).click();

await page.getByLabel("Title").fill(title);
await page.getByLabel("Email address").fill(`foo${new Date().getTime()}@example.com`);

await page.getByRole("combobox").click();
await page.getByRole("option", { name: "Academy for Social Justice" }).click();
await page.getByRole("button", { name: "Save and continue" }).click();
await page.getByRole("button", { name: "Accept and publish" }).click();

await expect(page.getByRole("heading", { name: "Your content block is available for use" })).toBeVisible();

return title;
});

const url = await test.step("Can embed an object", async () => {
await page.goto("/content-block-manager");

const summaryCardRows = page
.locator(".govuk-summary-list")
.filter({ hasText: title })
.locator(".govuk-summary-list__row");

const emailAddress = await summaryCardRows
.filter({ hasText: "Email address" })
.locator(".govuk-summary-list__value")
.textContent();

const embedCode = await summaryCardRows
.filter({ hasText: "Embed code" })
.locator(".govuk-summary-list__value")
.textContent();

await page.goto(publishingAppUrl("whitehall-admin"));

await page.getByRole("link", { name: "New document" }).click();
await page.getByLabel("News article").check();
await page.getByRole("button", { name: "Next" }).click();

await page.locator(".choices__item").first().click();
await page.getByRole("option", { name: "News story", exact: true }).click();

const documentTitle = `TEST DOCUMENT - ${new Date().getTime()}`;

await page.getByLabel("Title (required)").fill(documentTitle);
await page.getByLabel("Summary (required)").fill("Some summary");
await page.getByLabel("Body (required)").fill(`Text goes here - ${embedCode}`);
await page.getByRole("button", { name: "Save and go to document" }).click();
await page.getByRole("link", { name: "Add tags" }).click();
await page
.locator('[id="taxonomy_tag_form\\[taxons\\]"]')
.getByRole("list")
.locator("div")
.filter({ hasText: "Brexit" })
.click();
await page.getByRole("button", { name: "Save" }).click();
await page.getByRole("button", { name: "Force publish" }).click();
await page.getByLabel("Reason for force publishing").fill("Some reason");
await page.getByRole("button", { name: "Force publish" }).click();

await page.getByRole("link", { name: documentTitle }).click();
const url = await waitForUrlToBeAvailable(
page,
await page.getByRole("link", { name: "View on website" }).getAttribute("href")
Comment on lines +83 to +84
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm it's a shame there's not a why to write the test where we just click on the link instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's annoying. I think the issue is there's latency between when we send the document to be published and when it actually gets published. Additionally, if we keep trying to click the link, the page gets cached from the first visit, so we need to add a cachebust param to the URL to force the reload 😞

);

await page.goto(url);
await expect(page.getByText(emailAddress)).toBeVisible();

return url;
});

await test.step("Dependent content updates when block content changes", async () => {
await page.goto("/content-block-manager");

await page
.getByRole("link")
.filter({ hasText: `View/edit ${title}` })
.click();

await page.locator(".govuk-summary-list").getByRole("link").filter({ hasText: "Change" }).first().click();

const emailAddress = `foo${new Date().getTime()}@example.org`;
await page.getByLabel("Email address").fill(emailAddress);
await page.getByRole("button", { name: "Save and continue" }).click();

await page.getByRole("button", { name: "Save and continue" }).click();
await page.getByLabel("Publish the change now").check();
await page.getByRole("button", { name: "Accept and publish" }).click();

await page.goto(url);
await expect(page.getByText(emailAddress)).toBeVisible();
});
});
});