Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
timarney committed Apr 21, 2022
1 parent 93cf953 commit 08876dd
Showing 1 changed file with 17 additions and 49 deletions.
66 changes: 17 additions & 49 deletions packages/e2e-tests/src/specs/editor/shopping/woocommerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import {
createNewStory,
withExperimentalFeatures,
publishStory,
activatePlugin,
deactivatePlugin,
takeSnapshot,
minWPVersionRequired,
previewStory,
withPlugin,
} from '@web-stories-wp/e2e-test-utils';

/**
Expand All @@ -39,65 +39,33 @@ expect.extend(matchers);

describe('Shopping', () => {
describe('Shopping schema', () => {
const WPVersion = process.env?.WP_VERSION || 'latest';

minWPVersionRequired('5.8');
withExperimentalFeatures(['shoppingIntegration']);

beforeAll(async () => {
if ('latest' === WPVersion) {
await activatePlugin('woocommerce');
}
});

afterAll(async () => {
if ('latest' === WPVersion) {
await deactivatePlugin('woocommerce');
}
});

if (WPVersion !== 'latest') {
//eslint-disable-next-line jest/expect-expect, jest/no-focused-tests
it.only('minimum WordPress requirement not met', () => {});
}
withPlugin('woocommerce');

it('should should match a valid schema', async () => {
await createNewStory();
await expect(page).toClick('[aria-controls="library-pane-shopping"]');
await expect(page).toClick('[aria-label="Product"]');
await page.type('[aria-label="Product"]', 'Hoodie with Zipper');
await page.keyboard.press('ArrowDown');
await page.keyboard.press('Enter');
await expect(page).toClick('button', { text: 'Insert product' });
await takeSnapshot(page, 'insert product');
await publishStory();
const previewPage = await previewStory(page);
await previewPage.waitForSelector('amp-story-shopping-attachment script');

// open story dev tools
await page.keyboard.down('Meta');
await page.keyboard.down('Alt');
await page.keyboard.down('Shift');
await page.keyboard.down('J');

await takeSnapshot(page, 'shopping schema');

// pull story data
const state = JSON.parse(
await page.$eval(
'textArea[class^="devTools__Textarea"]',
(el) => el.value
// pull product data from the DOM
const data = await previewPage.evaluate(() =>
JSON.parse(
document.querySelector('amp-story-shopping-attachment script')
.textContent
)
);
const products = [];
state.pages.forEach((page) => {
page.elements.forEach((element) => {
const { type, product } = element;
//eslint-disable-next-line jest/no-conditional-in-test -- only add products
if (type === 'product') {
products.push(product);
}
});
});

expect(products).toHaveLength(1);
expect(products[0]).toMatchSchema(schema);
await page.bringToFront();
await previewPage.close();
expect(data.items).toHaveLength(1);
expect(data.items[0]).toMatchSchema(schema);
});
});
});

0 comments on commit 08876dd

Please sign in to comment.