[Launch Your Store] Add e2e tests (#47239)

* LYS spec

* get homescreen check working

* move over to shopper

* basic test

* get first test working

* Store only coming soon mode - logged out

* add logged in ttests

* linter

* Add changefile(s) from automation for the following project(s): woocommerce

* Remove skip from tests

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Paul Sealock 2024-05-14 11:41:35 +12:00 committed by GitHub
parent d19e90105a
commit 208e5633ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 176 additions and 7 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: add
Comment: Add e2e test to unreleased feature

View File

@ -87,11 +87,17 @@ function api_update_option( WP_REST_Request $request ) {
$option_name = sanitize_text_field( $request['option_name'] );
$option_value = sanitize_text_field( $request['option_value'] );
if ( update_option( $option_name, $option_value ) ) {
return new WP_REST_Response( 'Option updated', 200 );
$existing_value = get_option( $option_name );
if ( $existing_value === $option_value ) {
return new WP_REST_Response( 'Option ' . $option_name . ' already set to: ' . $option_value, 200 );
}
return new WP_REST_Response( 'Invalid request body', 400 );
if ( update_option( $option_name, $option_value ) ) {
return new WP_REST_Response( 'Update option SUCCESS: ' . $option_name . ' => ' . $option_value, 200 );
}
return new WP_REST_Response( 'Update option FAILED: ' . $option_name . ' => ' . $option_value, 400 );
}
/**

View File

@ -0,0 +1,75 @@
const { test, expect, request } = require( '@playwright/test' );
const { setOption } = require( '../../utils/options' );
test.describe( 'Launch Your Store front end - logged in', () => {
test.use( { storageState: process.env.ADMINSTATE } );
test.afterAll( async ( { baseURL } ) => {
try {
await setOption(
request,
baseURL,
'woocommerce_coming_soon',
'no'
);
} catch ( error ) {
console.log( error );
}
} );
test( 'Entire site coming soon mode', async ( { page, baseURL } ) => {
try {
await setOption(
request,
baseURL,
'woocommerce_coming_soon',
'yes'
);
await setOption(
request,
baseURL,
'woocommerce_store_pages_only',
'no'
);
} catch ( error ) {
console.log( error );
}
await page.goto( baseURL );
await expect(
page.getByText(
'This page is in "Coming soon" mode and is only visible to you and those who have permission. To make it public to everyone, change visibility settings'
)
).toBeVisible();
} );
test( 'Store only coming soon mode', async ( { page, baseURL } ) => {
try {
await setOption(
request,
baseURL,
'woocommerce_coming_soon',
'yes'
);
await setOption(
request,
baseURL,
'woocommerce_store_pages_only',
'yes'
);
} catch ( error ) {
console.log( error );
}
await page.goto( baseURL + '/shop/' );
await expect(
page.getByText(
'This page is in "Coming soon" mode and is only visible to you and those who have permission. To make it public to everyone, change visibility settings'
)
).toBeVisible();
} );
} );

View File

@ -0,0 +1,77 @@
const { test, expect, request } = require( '@playwright/test' );
const { setOption } = require( '../../utils/options' );
test.describe( 'Launch Your Store front end - logged out', () => {
test.afterAll( async ( { baseURL } ) => {
try {
await setOption(
request,
baseURL,
'woocommerce_coming_soon',
'no'
);
} catch ( error ) {
console.log( error );
}
} );
test( 'Entire site coming soon mode', async ( { page, baseURL } ) => {
try {
await setOption(
request,
baseURL,
'woocommerce_coming_soon',
'yes'
);
await setOption(
request,
baseURL,
'woocommerce_store_pages_only',
'no'
);
} catch ( error ) {
console.log( error );
}
await page.goto( baseURL );
await expect(
page.getByText(
'Pardon our dust! Were working on something amazing — check back soon!'
)
).toBeVisible();
} );
test( 'Store only coming soon mode', async ( { page, baseURL } ) => {
try {
await setOption(
request,
baseURL,
'woocommerce_coming_soon',
'yes'
);
await setOption(
request,
baseURL,
'woocommerce_store_pages_only',
'yes'
);
} catch ( error ) {
console.log( error );
}
await page.goto( baseURL + '/shop/' );
await expect(
page.getByText( 'Great things are on the horizon' )
).toBeVisible();
await expect(
page.getByText(
'Something big is brewing! Our store is in the works and will be launching soon!'
)
).toBeVisible();
} );
} );

View File

@ -1,3 +1,6 @@
/**
* Internal dependencies
*/
import { encodeCredentials } from './plugin-utils';
export const setOption = async (
@ -17,8 +20,12 @@ export const setOption = async (
},
} );
await apiContext.post( '/wp-json/e2e-options/update', {
failOnStatusCode: true,
data: { option_name: optionName, option_value: optionValue },
} );
return await apiContext
.post( '/wp-json/e2e-options/update', {
failOnStatusCode: true,
data: { option_name: optionName, option_value: optionValue },
} )
.then( ( response ) => {
return response.json();
} );
};