[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:
parent
d19e90105a
commit
208e5633ba
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: add
|
||||
Comment: Add e2e test to unreleased feature
|
||||
|
|
@ -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 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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();
|
||||
} );
|
||||
} );
|
|
@ -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! We’re 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();
|
||||
} );
|
||||
} );
|
|
@ -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();
|
||||
} );
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue