2021-03-25 09:21:32 +00:00
|
|
|
/* eslint-disable jest/no-export, jest/no-disabled-tests */
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
const {
|
|
|
|
merchant,
|
2021-05-24 16:00:26 +00:00
|
|
|
waitForSelectorWithoutThrow,
|
2021-03-25 09:21:32 +00:00
|
|
|
} = require( '@woocommerce/e2e-utils' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
const {
|
|
|
|
it,
|
|
|
|
describe,
|
|
|
|
beforeAll,
|
|
|
|
} = require( '@jest/globals' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Quick check for page title and no data message.
|
|
|
|
*
|
|
|
|
* @param pageTitle Page title in H1.
|
|
|
|
* @param element Defaults to '.d3-chart__empty-message'
|
|
|
|
* @param elementText Defaults to 'No data for the selected date range'
|
|
|
|
*/
|
|
|
|
const checkHeadingAndElement = async (
|
|
|
|
pageTitle, element = '.d3-chart__empty-message', elementText = 'No data for the selected date range') => {
|
|
|
|
await expect(page).toMatchElement('h1', {text: pageTitle});
|
2021-05-24 16:00:26 +00:00
|
|
|
|
|
|
|
// Depending on order of tests the chart may not be empty.
|
|
|
|
const found = await waitForSelectorWithoutThrow( element );
|
|
|
|
if ( found ) {
|
|
|
|
await expect(page).toMatchElement(element, {text: elementText});
|
|
|
|
} else {
|
|
|
|
await expect(page).toMatchElement( '.woocommerce-chart' );
|
|
|
|
}
|
2021-03-25 09:21:32 +00:00
|
|
|
};
|
|
|
|
|
2021-07-01 07:44:36 +00:00
|
|
|
// Analytics pages that we'll test against
|
|
|
|
const pages = [
|
|
|
|
['Overview'],
|
|
|
|
['Products'],
|
|
|
|
['Revenue'],
|
|
|
|
['Orders'],
|
|
|
|
['Variations'],
|
|
|
|
['Categories'],
|
|
|
|
['Coupons'],
|
|
|
|
['Taxes'],
|
|
|
|
['Downloads'],
|
|
|
|
['Stock', '.components-button > span', 'Product / Variation'],
|
|
|
|
['Settings', 'h2', 'Analytics Settings']
|
|
|
|
];
|
|
|
|
|
2021-03-25 09:21:32 +00:00
|
|
|
const runAnalyticsPageLoadsTest = () => {
|
|
|
|
describe('Analytics > Opening Top Level Pages', () => {
|
|
|
|
beforeAll(async () => {
|
|
|
|
await merchant.login();
|
|
|
|
});
|
|
|
|
|
2021-07-01 07:44:36 +00:00
|
|
|
it.each(pages)(
|
|
|
|
'can see %s page properly',
|
|
|
|
async (pageTitle, element, elementText) => {
|
|
|
|
// Go to the desired page and verify it
|
|
|
|
await merchant.openAnalyticsPage(pageTitle.toLowerCase());
|
|
|
|
await checkHeadingAndElement(pageTitle, element, elementText);
|
|
|
|
}
|
|
|
|
);
|
2021-03-25 09:21:32 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = runAnalyticsPageLoadsTest;
|