Files
chrnx-dev-wp/tests/e2e/visual-scenarios.spec.mjs

47 lines
1.7 KiB
JavaScript

import { expect, test } from '@playwright/test';
import { execFileSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
const projectRoot = fileURLToPath( new URL( '../..', import.meta.url ) );
const seedScenario = ( scenario ) =>
execFileSync( './scripts/seed-test-content.sh', [ scenario ], {
cwd: projectRoot,
env: {
...process.env,
PATH: `/opt/homebrew/opt/docker/bin:${ process.env.PATH ?? '' }`,
},
stdio: 'pipe',
} );
test.describe.configure( { mode: 'serial' } );
test.afterAll( () => {
seedScenario( 'default' );
} );
test( 'local featured and subscribe scenarios restore the default dataset', async ( { page } ) => {
try {
for ( const count of [ 1, 2 ] ) {
seedScenario( `featured-${ count }` );
await page.goto( `/?fixtureScenario=featured-${ count }` );
await expect( page.locator( '.chrnx-featured-stories article' ) ).toHaveCount( count );
const hrefs = await page
.locator( '.chrnx-featured-stories article a' )
.evaluateAll( ( links ) => links.map( ( link ) => link.href ) );
expect( new Set( hrefs ).size ).toBe( hrefs.length );
}
for ( const scenario of [ 'subscribe-unpublished', 'subscribe-unavailable' ] ) {
seedScenario( scenario );
await page.goto( `/?fixtureScenario=${ scenario }` );
await expect( page.locator( '.chrnx-subscribe-cta' ) ).toHaveCount( 0 );
}
} finally {
seedScenario( 'default' );
}
await page.goto( '/' );
await expect( page.locator( '.chrnx-featured-stories article' ) ).toHaveCount( 3 );
await expect(
page.getByRole( 'link', { name: 'Subscribe', exact: true } ).first(),
).toBeVisible();
} );