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

Playwright tests - added coverage for ShareProgress buttons #12857

Merged
merged 8 commits into from
Sep 13, 2024
8 changes: 7 additions & 1 deletion network-api/networkapi/wagtailpages/factory/campaign_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ class Params:
no_cta = Trait(cta=None)
cta_show_all_fields = Trait(
cta=SubFactory(
PetitionFactory, show_country_field=True, show_postal_code_field=True, show_comment_field=True
PetitionFactory,
show_country_field=True,
show_postal_code_field=True,
show_comment_field=True,
share_facebook="sp_111111", # a fake ShareProgress ID for testing
share_twitter="sp_222222", # a fake ShareProgress ID for testing
share_email="sp_333333", # a fake ShareProgress ID for testing
)
)

Expand Down
35 changes: 35 additions & 0 deletions tests/integration/petition/002-thank-you.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ test.describe("Donation modal", () => {
await modalContent.waitFor({ state: "visible" });
});

test("ShareProgress script is included in the DOM", async ({ page }) => {
const spScriptUrl = "https://c.shpg.org/352/sp.js";

// Check if the ShareProgress script is present in the DOM
const scriptElement = await page.$(`script[src="${spScriptUrl}"]`);
expect(scriptElement).not.toBeNull();
});

test("Donation modal can be closed using the 'x' button", async ({
page,
}) => {
Expand Down Expand Up @@ -79,6 +87,33 @@ test.describe("Share buttons", () => {
expect(await closeButton.count()).toBe(1);
await closeButton.click();
expect(await page.locator(`.modal-content`).isVisible()).toBe(false);

// test if Share section is visible
let shareSection = page.locator(`.formassembly-petition-thank-you`);
await shareSection.waitFor({ state: "visible" });
});

test("Facebook share button (linked with ShareProgress)", async ({
page,
}) => {
// Because it's mostly ShareProgress's script doing the magic,
// we can only test if an anchor element has been injected by ShareProgress
const facebookButton = page.locator("#share-progress-fb a");
expect(await facebookButton.count()).toBe(1);
});

test("Twitter share button (linked with ShareProgress)", async ({ page }) => {
// Because it's mostly ShareProgress's script doing the magic,
// we can only test if an anchor element has been injected by ShareProgress
const twitterButton = page.locator("#share-progress-tw a");
expect(await twitterButton.count()).toBe(1);
});

test("Email share button (linked with ShareProgress)", async ({ page }) => {
// Because it's mostly ShareProgress's script doing the magic,
// we can only test if an anchor element has been injected by ShareProgress
const twitterButton = page.locator("#share-progress-em a");
expect(await twitterButton.count()).toBe(1);
});

test("Copy button", async ({ page }) => {
Expand Down
Loading