Skip to content
Merged
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
5 changes: 3 additions & 2 deletions docs/e2e-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ The setup script (`scripts/setup.php`) creates these WordPress pages:
| `e2e-supporter` | Supporter mode with 3 tiers (GBP 5, 10, 20/month) |
| `e2e-supporter-custom` | Supporter mode with custom amount allowed |
| `e2e-supporter-no-plans` | Supporter mode with no plans (triggers warning UI) |
| `e2e-custom-fields` | Standard membership with one custom field ("Branch") |


## What is covered
Expand Down Expand Up @@ -77,8 +78,8 @@ The join form specs (the table below) are listed with their test counts. The set
|---|---|---|
| Features | `features.spec.ts`, `features-integrations.spec.ts` | Every setting. Integration switches: refused without credentials, saved with them, payment-step and form effects. Use Stripe sets global plans up in Stripe on save (fake API). Known problem: JOIN-161 (a rejected Stripe key crashes the save). |
| Membership Plans | | Not yet |
| Theme | | Not yet |
| Copy | | Not yet |
| Theme | `theme.spec.ts` | Every setting: colour defaults, each colour reaching the form's styles (the primary colour on its buttons), custom CSS applied. |
| Copy | `copy.spec.ts` | Every setting: each one's default (or none), the fallbacks for blank sidebar, stage label and joining verb, and where each shows (details, plan and bank-details steps, confirmation step, sidebar). Known problems: JOIN-162 (Home Address Copy never shows), JOIN-163 (day-of-month copy unused), JOIN-164 (organisation details marked required but not enforced). |
| Integrations | | Not yet. What Mailchimp, Action Network and Zetkin receive on a join will be covered here. |
| Logging | | Not yet |
| Debug | | Not yet |
Expand Down
18 changes: 18 additions & 0 deletions packages/join-e2e/scripts/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,22 @@ function ck_e2e_upsert_page(string $slug, string $title, string $content): int
// that care about it.
carbon_set_theme_option('stripe_direct_debit_only', true);

// Custom fields page: standard join with one custom field, so the form shows
// its "more about you" section (and the settings page's heading for it).
$custom_fields_page_id = ck_e2e_upsert_page(
'e2e-custom-fields',
'E2E Custom Fields Test',
ck_e2e_make_block_content($standard_plans, [
'custom_fields' => [[
'_type' => '_',
'label' => 'Branch',
'id' => 'branch',
'required' => false,
'field_type' => 'text',
]],
])
);

// Persist URLs as options so get-page-url.sh can retrieve them.
update_option('ck_e2e_standard_page_url', get_permalink($standard_page_id));
update_option('ck_e2e_free_page_url', get_permalink($free_page_id));
Expand All @@ -414,6 +430,7 @@ function ck_e2e_upsert_page(string $slug, string $title, string $content): int
update_option('ck_e2e_supporter_no_plans_page_url', get_permalink($supporter_no_plans_page_id));
update_option('ck_e2e_allow_cards_override_page_url', get_permalink($allow_cards_override_page_id));
update_option('ck_e2e_multi_currency_page_url', get_permalink($multi_currency_page_id));
update_option('ck_e2e_custom_fields_page_url', get_permalink($custom_fields_page_id));

echo 'Standard page URL: ' . get_permalink($standard_page_id) . "\n";
echo 'Free page URL: ' . get_permalink($free_page_id) . "\n";
Expand All @@ -423,4 +440,5 @@ function ck_e2e_upsert_page(string $slug, string $title, string $content): int
echo 'Supporter no-plans page URL: ' . get_permalink($supporter_no_plans_page_id) . "\n";
echo 'Allow cards override page URL: ' . get_permalink($allow_cards_override_page_id) . "\n";
echo 'Multi-currency page URL: ' . get_permalink($multi_currency_page_id) . "\n";
echo 'Custom fields page URL: ' . get_permalink($custom_fields_page_id) . "\n";
echo "Setup complete.\n";
29 changes: 24 additions & 5 deletions packages/join-e2e/tests/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ import path from 'path';
export const SAVED_STATE_KEY = 'ck_join_state_flow';
export const CONTINUE = 'button[type="submit"]:has-text("Continue")';

// Join form pages created by scripts/setup.php.
export const STANDARD_JOIN_PAGE = '/e2e-standard-join/';
export const FREE_JOIN_PAGE = '/e2e-free-join/';
/** A join form with one custom field, so it shows the "more about you" section. */
export const CUSTOM_FIELDS_PAGE = '/e2e-custom-fields/';
/** A join form offering the same plan in GBP and EUR. */
export const MULTI_CURRENCY_PAGE = '/e2e-multi-currency-join/';

/** `text` with any regular expression characters in it escaped. */
export const escapeRegExp = (text: string) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');

/** A pattern matching exactly `text`, e.g. exactly('#336699', 'i') for any case. */
export const exactly = (text: string, flags?: string) => new RegExp(`^${escapeRegExp(text)}$`, flags);

/** Clicks Continue on the join form's details step and waits for the plan step. */
export async function continueToPlans(page: Page): Promise<void> {
await page.locator(CONTINUE).click();
await page.waitForSelector('[role="radiogroup"]');
}

/**
* Intercepts both REST endpoints the form calls during navigation and fulfils
* them with empty 200 responses so that network errors never block progression.
Expand Down Expand Up @@ -146,9 +166,9 @@ export function wp(...args: string[]): string {
export function field(scope: Locator, label: string): Locator {
// One selector rather than a `has` filter, so it also works inside the
// block editor's iframe.
return scope
.locator(`.cf-field:not(.cf-separator):has(.cf-field__label:text-matches("^${label}[*]?$"))`)
.first();
// JSON.stringify quotes the pattern for the selector, escaping its backslashes.
const pattern = JSON.stringify(`^${escapeRegExp(label)}[*]?$`);
return scope.locator(`.cf-field:not(.cf-separator):has(.cf-field__label:text-matches(${pattern}))`).first();
}

/** The CK Join Form block. The block editor renders its content in an iframe. */
Expand Down Expand Up @@ -188,8 +208,7 @@ export async function openNewPageWithJoinBlock(page: Page, title: string): Promi

/** Continues from the details step, picks the plan by its label, and continues again. */
export async function choosePlan(page: Page, label: string): Promise<void> {
await page.locator(CONTINUE).click();
await page.waitForSelector('[role="radiogroup"]');
await continueToPlans(page);
await page.locator('label.radio-panel', { has: page.locator(`[id="membership-${label}"]`) }).click();
await page.locator(CONTINUE).click();
}
Expand Down
8 changes: 3 additions & 5 deletions packages/join-e2e/tests/multi-currency-plans.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from '@playwright/test';
import { CONTINUE, mockRestEndpoints } from './helpers';
import { CONTINUE, continueToPlans, mockRestEndpoints, MULTI_CURRENCY_PAGE } from './helpers';

/**
* Multi-currency plan selection
Expand All @@ -17,16 +17,14 @@ import { CONTINUE, mockRestEndpoints } from './helpers';
* - "Standard" EUR €7/month (id: standard-eur)
*/

const MULTI_CURRENCY_PAGE = '/e2e-multi-currency-join/';

async function advanceToPlanStep(page: import('@playwright/test').Page) {
await mockRestEndpoints(page);
await page.goto(MULTI_CURRENCY_PAGE);
await page.waitForSelector('input#firstName');

// Test data auto-fills the details form; click Continue to advance.
await page.locator(CONTINUE).click();
await page.waitForSelector('[role="radiogroup"]');
// Test data auto-fills the details form; Continue to the plans.
await continueToPlans(page);
}

test.describe('Multi-currency plan selection', () => {
Expand Down
Loading
Loading