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

Migrate rss.cy and signup.cy to Playwright #2907

Open
wants to merge 14 commits into
base: staging
Choose a base branch
from
Open
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
56 changes: 0 additions & 56 deletions site/gatsby-site/cypress/e2e/integration/rss.cy.js

This file was deleted.

137 changes: 0 additions & 137 deletions site/gatsby-site/cypress/e2e/integration/signup.cy.js

This file was deleted.

52 changes: 52 additions & 0 deletions site/gatsby-site/playwright/e2e-full/rss.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { expect } from '@playwright/test';
import { test } from '../utils';
import { XMLParser } from 'fast-xml-parser';
import { init } from '../memory-mongo';

test.describe('RSS', () => {
test('Should generate a valid RSS feed', async ({ page }) => {
await init();
const response = await page.request.get('/rss.xml');
expect(response.status()).toBe(200);
expect(response.headers()['content-type']).toContain('application/xml');

const xml = await response.text();
const parser = new XMLParser();
const parsedXml = parser.parse(xml);

const hasChannelTag = parsedXml.rss.channel !== undefined;
expect(hasChannelTag).toBe(true);

const items = parsedXml.rss.channel.item.slice(0, 20);
expect(items.length).toBeGreaterThan(0);
});

test('Should generate a valid RSS feed data', async ({ page, skipOnEmptyEnvironment }) => {
await init();
const response = await page.request.get('/rss.xml');
expect(response.status()).toBe(200);
expect(response.headers()['content-type']).toContain('application/xml');

const xml = await response.text();
const parser = new XMLParser();
const parsedXml = parser.parse(xml);

const hasChannelTag = parsedXml.rss.channel !== undefined;
expect(hasChannelTag).toBe(true);

const items = parsedXml.rss.channel.item.slice(0, 20);
expect(items.length).toBeGreaterThan(0);

items.forEach((item: any) => {
const description = item.description;
const title = item.title;
const pubDate = item.pubDate;
const guid = item.guid;

expect(description).not.toBeNull();
expect(title).not.toBeNull();
expect(pubDate).not.toBeNull();
expect(guid).not.toBeNull();
});
});
});
122 changes: 122 additions & 0 deletions site/gatsby-site/playwright/e2e-full/signup.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import { expect } from '@playwright/test';
import { test, conditionalIntercept, waitForRequest } from '../utils';
import config from '../config';

test.describe('Signup', () => {
const url = '/signup';

test('Should successfully load sign up page', async ({ page }) => {
await page.goto(url);
});

test('Should display success toast message after a sign up', async ({ page }) => {
await page.goto(url);

const email = '[email protected]';
const password = 'newUserPassword';

await page.locator('[data-cy="signup-btn"]').click();

await page.locator('input[name=email]').fill(email);
await page.locator('input[name=password]').fill(password);
await page.locator('input[name=passwordConfirm]').fill(password);

await conditionalIntercept(
page,
'**/register',
(req) => req.postDataJSON().email == email && req.postDataJSON().password == password,
{ statusCode: 201 },
'Register'
);

await page.locator('[data-cy="signup-btn"]').click();
await waitForRequest('Register');

const result = await page.evaluate(() => JSON.parse(JSON.stringify(localStorage)));
expect(result).toHaveProperty('signup');
await expect(page.locator('[data-cy="toast"]')).toBeVisible({ timeout: 30000 });
await expect(page.locator('[data-cy="toast"]').getByText(`Verification email sent to ${email}`)).toBeVisible();
});

test('Should display the error toast message if the user already exists', async ({ page, skipOnEmptyEnvironment }) => {
await page.goto(url);

await page.locator('[data-cy="signup-btn"]').click();

await page.locator('input[name=email]').fill(config.E2E_ADMIN_USERNAME);
await page.locator('input[name=password]').fill('anyPassword');
await page.locator('input[name=passwordConfirm]').fill('anyPassword');
await page.locator('[data-cy="signup-btn"]').click();
await expect(page.locator('[data-cy="toast"]').getByText('name already in use')).toBeVisible();
});

test('Should display the error toast message if any other sign up error occurs', async ({ page }) => {
await page.goto(url);

await page.locator('[data-cy="signup-btn"]').click();

await page.locator('input[name=email]').fill('[email protected]');
await page.locator('input[name=password]').fill('anyPassword');
await page.locator('input[name=passwordConfirm]').fill('anyPassword');

await conditionalIntercept(
page,
'**/register',
(req) => req.method() === 'POST',
{ error: 'Something bad happened :(' },
'Register',
500
);

await page.locator('[data-cy="signup-btn"]').click();
await waitForRequest('Register');
await expect(page.locator('[data-cy="toast"]')).toBeVisible({ timeout: 30000 });
await expect(page.locator('[data-cy="toast"]').getByText('Something bad happened :(')).toBeVisible();
});

test('Should redirect to specific page after sign up if redirectTo is provided', async ({ page }) => {
const redirectTo = '/cite/10/';
await page.goto(`${url}?redirectTo=${redirectTo}`);

await page.locator('[data-cy="signup-btn"]').click();

const email = '[email protected]';
const password = 'newUserPassword';

await page.locator('input[name=email]').fill(email);
await page.locator('input[name=password]').fill(password);
await page.locator('input[name=passwordConfirm]').fill(password);

await conditionalIntercept(
page,
'**/register',
(req) => req.postDataJSON().email == email && req.postDataJSON().password == password,
{ statusCode: 201 },
'Register'
);

await page.locator('[data-cy="signup-btn"]').click();
await waitForRequest('Register');
await page.waitForURL(redirectTo);
});

test('Should display success toast message after a subscription to Major updates', async ({ page }) => {
await page.goto(url);

const email = '[email protected]';

await page.locator('input[name=emailSubscription]').fill(email);

await conditionalIntercept(
page,
'**/register',
(req) => req.postDataJSON().email == email && req.postDataJSON().password == '123456',
{ statusCode: 201 },
'Register'
);

await page.locator('[data-cy="subscribe-to-updates-btn"]').click();
await waitForRequest('Register');
await expect(page.locator('[data-cy="toast"]').getByText(`Thanks for subscribing to our Newsletter!`)).toBeVisible();
});
});
Loading