* add util folder and add util to generate pages

* add loader to insert and remove pages

* update tests to use the new page creator

* refactor tests to not create pages

* remove fullscreen check

* update single product test.

The test kept failing for me locally (it wasn’t deleting the block), when I manually tested following the same manual steps would not delete the block.

* add `quiet-pull` flag to docker command to hopefully reduce noice on builds

* adjust page loader to simplfy the loop

* remove extra comment

* add docs

* move promise inside map

Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
This commit is contained in:
Seghir Nadir 2020-06-15 15:59:18 +01:00 committed by GitHub
parent 2004c48c5e
commit dbd3c7ef16
25 changed files with 437 additions and 157 deletions

View File

@ -3916,6 +3916,26 @@
"path-exists": "^4.0.0"
}
},
"fs-extra": {
"version": "8.1.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz",
"integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==",
"dev": true,
"requires": {
"graceful-fs": "^4.2.0",
"jsonfile": "^4.0.0",
"universalify": "^0.1.0"
}
},
"jsonfile": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz",
"integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=",
"dev": true,
"requires": {
"graceful-fs": "^4.1.6"
}
},
"locate-path": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz",
@ -3975,6 +3995,12 @@
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-5.0.0.tgz",
"integrity": "sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==",
"dev": true
},
"universalify": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
"integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==",
"dev": true
}
}
},
@ -9220,6 +9246,12 @@
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
},
"at-least-node": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz",
"integrity": "sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==",
"dev": true
},
"atob": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz",
@ -15747,23 +15779,25 @@
"dev": true
},
"fs-extra": {
"version": "8.1.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz",
"integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==",
"version": "9.0.1",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.0.1.tgz",
"integrity": "sha512-h2iAoN838FqAFJY2/qVpzFXy+EBxfVE220PalAqQLDVsFOHLJrZvut5puAbCdNv6WJk+B8ihI+k0c7JK5erwqQ==",
"dev": true,
"requires": {
"at-least-node": "^1.0.0",
"graceful-fs": "^4.2.0",
"jsonfile": "^4.0.0",
"universalify": "^0.1.0"
"jsonfile": "^6.0.1",
"universalify": "^1.0.0"
},
"dependencies": {
"jsonfile": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz",
"integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=",
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.0.1.tgz",
"integrity": "sha512-jR2b5v7d2vIOust+w3wtFKZIfpC2pnRmFAhAC/BuweZFQR8qZzxH1OyrQ10HmdVYiXWkYUqPVsz91cG7EL2FBg==",
"dev": true,
"requires": {
"graceful-fs": "^4.1.6"
"graceful-fs": "^4.1.6",
"universalify": "^1.0.0"
}
}
}
@ -16089,6 +16123,15 @@
}
}
},
"glob-promise": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/glob-promise/-/glob-promise-3.4.0.tgz",
"integrity": "sha512-q08RJ6O+eJn+dVanerAndJwIcumgbDdYiUT7zFQl3Wm1xD6fBKtah7H8ZJChj4wP+8C+QfeVy8xautR7rdmKEw==",
"dev": true,
"requires": {
"@types/glob": "*"
}
},
"glob-to-regexp": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/glob-to-regexp/-/glob-to-regexp-0.3.0.tgz",
@ -34093,9 +34136,9 @@
}
},
"universalify": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
"integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==",
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-1.0.0.tgz",
"integrity": "sha512-rb6X1W158d7pRQBg5gkR8uPaSfiids68LTJQYOtEUhoJUWBdaQHsuT/EUduxXYxcrt4r5PJ4fuHW1MHT6p0qug==",
"dev": true
},
"unpipe": {

View File

@ -53,7 +53,7 @@
"test:e2e:down:reset": "docker-compose down -v",
"test:e2e:ssh": "docker exec -it woo-blocks_wordpress-www_1 /bin/bash",
"test:e2e:up": "docker-compose up -d",
"test:e2e:up:build": "docker-compose up --build -d",
"test:e2e:up:build": "docker-compose up --build -d --quiet-pull",
"test:e2e": "./tests/bin/e2e-test-integration.js",
"test:e2e-dev": "./tests/bin/e2e-test-integration.js --dev",
"test:e2e:update": "./tests/bin/e2e-test-integration.js -- --updateSnapshot",
@ -91,7 +91,7 @@
"@wordpress/components": "8.5.0",
"@wordpress/data-controls": "1.6.0",
"@wordpress/dependency-extraction-webpack-plugin": "2.1.0",
"@wordpress/e2e-test-utils": "4.3.1",
"@wordpress/e2e-test-utils": "^4.3.1",
"@wordpress/editor": "9.10.0",
"@wordpress/element": "2.10.0",
"@wordpress/eslint-plugin": "3.3.0",
@ -101,6 +101,7 @@
"@wordpress/jest-preset-default": "5.3.1",
"@wordpress/scripts": "6.2.0",
"autoprefixer": "9.8.0",
"axios": "^0.19.2",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "10.1.0",
"babel-loader": "8.1.0",
@ -122,6 +123,8 @@
"eslint-plugin-jest": "23.13.2",
"eslint-plugin-react-hooks": "4.0.0",
"eslint-plugin-woocommerce": "file:bin/eslint-plugin-woocommerce",
"fs-extra": "^9.0.1",
"glob-promise": "^3.4.0",
"husky": "2.4.1",
"ignore-loader": "0.1.2",
"jest": "25.5.4",
@ -208,4 +211,4 @@
"license.txt",
"woocommerce-gutenberg-products-block.php"
]
}
}

View File

@ -8,6 +8,7 @@ module.exports = {
moduleNameMapper: {
'@woocommerce/e2e-tests/(.*)':
'<rootDir>/node_modules/woocommerce/tests/e2e-tests/$1',
'@woocommerce/blocks-test-utils': '<rootDir>/tests/utils',
},
preset: 'jest-puppeteer',

View File

@ -12,6 +12,7 @@ import {
createCoupons,
createProducts,
createShippingZones,
createBlockPages,
enablePaymentGateways,
} from '../fixtures/fixture-loaders';
@ -30,6 +31,7 @@ module.exports = async ( globalConfig ) => {
createCoupons(),
createProducts(),
createShippingZones(),
createBlockPages(),
enablePaymentGateways(),
] )
.then( ( results ) => {
@ -39,12 +41,20 @@ module.exports = async ( globalConfig ) => {
* in which setup and teardown run in is separate from the one our
* test use, so there is no risk of data bleeding.
*/
const [ , taxes, coupons, products, shippingZones ] = results;
const [
,
taxes,
coupons,
products,
shippingZones,
pages,
] = results;
global.fixtureData = {
taxes,
coupons,
products,
shippingZones,
pages,
};
} )
.catch( console.log );

View File

@ -12,15 +12,23 @@ import {
deleteCoupons,
deleteProducts,
deleteShippingZones,
deleteBlockPages,
} from '../fixtures/fixture-loaders';
module.exports = async ( globalConfig ) => {
await teardownPuppeteer( globalConfig );
const { taxes, coupons, products, shippingZones } = global.fixtureData;
const {
taxes,
coupons,
products,
shippingZones,
pages,
} = global.fixtureData;
return Promise.all( [
deleteTaxes( taxes ),
deleteCoupons( coupons ),
deleteProducts( products ),
deleteShippingZones( shippingZones ),
deleteBlockPages( pages ),
] ).catch( console.log );
};

View File

@ -3,7 +3,10 @@
*/
const WooCommerceRestApi = require( '@woocommerce/woocommerce-rest-api' )
.default;
const glob = require( 'glob-promise' );
const { dirname } = require( 'path' );
const { readJson } = require( 'fs-extra' );
const axios = require( 'axios' ).default;
require( 'dotenv' ).config();
/**
@ -29,6 +32,7 @@ const WooCommerce = new WooCommerceRestApi( {
},
} );
const WPAPI = `${ process.env.WORDPRESS_BASE_URL }:${ process.env.WORDPRESS_PORT }/wp-json/wp/v2/pages`;
/**
* prepare some store settings.
*
@ -249,6 +253,51 @@ const deleteShippingZones = ( ids ) => {
return Promise.all( ids.map( deleteZone ) );
};
const createBlockPages = () => {
return glob( `${ dirname( __filename ) }/../specs/**/*.fixture.json` ).then(
( files ) => {
return Promise.all(
files.map( async ( filePath ) => {
const file = await readJson( filePath );
const { title, pageContent: content } = file;
return axios
.post(
WPAPI,
{
title,
content,
status: 'publish',
},
{
auth: {
username: process.env.WORDPRESS_LOGIN,
password: process.env.WORDPRESS_PASSWORD,
},
}
)
.then( ( response ) => response.data.id );
} )
);
}
);
};
const deleteBlockPages = ( ids ) => {
return Promise.all(
ids.map( ( id ) =>
axios.delete( `${ WPAPI }/${ id }`, {
params: {
force: true,
},
auth: {
username: process.env.WORDPRESS_LOGIN,
password: process.env.WORDPRESS_PASSWORD,
},
} )
)
);
};
module.exports = {
setupSettings,
createTaxes,
@ -260,4 +309,6 @@ module.exports = {
enablePaymentGateways,
createShippingZones,
deleteShippingZones,
createBlockPages,
deleteBlockPages,
};

View File

@ -1,7 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Single Product Block can be created 1`] = `
"<!-- wp:woocommerce/single-product -->
<div class=\\"wp-block-woocommerce-single-product is-loading\\"></div>
<!-- /wp:woocommerce/single-product -->"
`;

View File

@ -0,0 +1 @@
{"title":"All Products Block","pageContent":"<!-- wp:woocommerce/all-products {\"columns\":3,\"rows\":3,\"alignButtons\":false,\"contentVisibility\":{\"orderBy\":true},\"orderby\":\"date\",\"layoutConfig\":[[\"woocommerce/product-image\"],[\"woocommerce/product-title\"],[\"woocommerce/product-price\"],[\"woocommerce/product-rating\"],[\"woocommerce/product-button\"]]} -->\n<div class=\"wp-block-woocommerce-all-products wc-block-all-products\" data-attributes=\"{&quot;alignButtons&quot;:false,&quot;columns&quot;:3,&quot;contentVisibility&quot;:{&quot;orderBy&quot;:true},&quot;isPreview&quot;:false,&quot;layoutConfig&quot;:[[&quot;woocommerce/product-image&quot;],[&quot;woocommerce/product-title&quot;],[&quot;woocommerce/product-price&quot;],[&quot;woocommerce/product-rating&quot;],[&quot;woocommerce/product-button&quot;]],&quot;orderby&quot;:&quot;date&quot;,&quot;rows&quot;:3}\"></div>\n<!-- /wp:woocommerce/all-products -->"}

View File

@ -0,0 +1 @@
{"title":"Cart Block","pageContent":"<!-- wp:woocommerce/cart -->\n<div class=\"wp-block-woocommerce-cart is-loading\"><!-- wp:image {\"align\":\"center\",\"sizeSlug\":\"small\"} -->\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-small\"><img src=\"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzgiIGhlaWdodD0iMzgiIHZpZXdCb3g9IjAgMCAzOCAzOCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTE5IDBDOC41MDQwMyAwIDAgOC41MDQwMyAwIDE5QzAgMjkuNDk2IDguNTA0MDMgMzggMTkgMzhDMjkuNDk2IDM4IDM4IDI5LjQ5NiAzOCAxOUMzOCA4Lj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My45MDMyIDI1LjYxMTcgMjUuNDA0OCAyNy43ODc1IDI4LjAyNUMyOC44NDQ4IDI5LjI4MTUgMjYuOTI5NCAzMC44MjE0IDI1LjkxMDUgMjkuNTg3OVoiIGZpbGw9ImJsYWNrIi8+Cjwvc3ZnPgo=\" alt=\"\"/></figure></div>\n<!-- /wp:image -->\n\n<!-- wp:heading {\"align\":\"center\",\"className\":\"wc-block-cart__empty-cart__title\"} -->\n<h2 class=\"has-text-align-center wc-block-cart__empty-cart__title\">Your cart is currently empty!</h2>\n<!-- /wp:heading -->\n\n<!-- wp:paragraph {\"align\":\"center\"} -->\n<p class=\"has-text-align-center\"><a href=\"false\">Browse store</a>.</p>\n<!-- /wp:paragraph -->\n\n<!-- wp:separator {\"className\":\"is-style-dots\"} -->\n<hr class=\"wp-block-separator is-style-dots\"/>\n<!-- /wp:separator -->\n\n<!-- wp:heading {\"align\":\"center\"} -->\n<h2 class=\"has-text-align-center\">New in store</h2>\n<!-- /wp:heading -->\n\n<!-- wp:woocommerce/product-new {\"rows\":1} /--></div>\n<!-- /wp:woocommerce/cart -->"}

View File

@ -0,0 +1 @@
{"title":"Checkout Block","pageContent":"<!-- wp:woocommerce/checkout -->\n<div class=\"wp-block-woocommerce-checkout is-loading\"></div>\n<!-- /wp:woocommerce/checkout -->"}

View File

@ -0,0 +1 @@
{"title":"Product Search Block","pageContent":"<!-- wp:woocommerce/product-search {\"formId\":\"wc-block-product-search-2\"} -->\n<div class=\"wp-block-woocommerce-product-search\"><div class=\"wc-block-product-search\"><form role=\"search\" method=\"get\" action=\"http://localhost:8084/\"><label for=\"wc-block-product-search-2\" class=\"wc-block-product-search__label\">Search</label><div class=\"wc-block-product-search__fields\"><input type=\"search\" id=\"wc-block-product-search-2\" class=\"wc-block-product-search__field\" placeholder=\"Search products…\" name=\"s\"/><input type=\"hidden\" name=\"post_type\" value=\"product\"/><button type=\"submit\" class=\"wc-block-product-search__button\" label=\"Search\"><svg aria-hidden=\"true\" role=\"img\" focusable=\"false\" class=\"dashicon dashicons-arrow-right-alt2\" xmlns=\"http://www.w3.org/2000/svg\" width=\"20\" height=\"20\" viewbox=\"0 0 20 20\"><path d=\"M6 15l5-5-5-5 1-2 7 7-7 7z\"></path></svg></button></div></form></div></div>\n<!-- /wp:woocommerce/product-search -->"}

View File

@ -0,0 +1 @@
{"title":"Single Product Block","pageContent":"<!-- wp:woocommerce/single-product -->\n<div class=\"wp-block-woocommerce-single-product is-loading\"></div>\n<!-- /wp:woocommerce/single-product -->"}

View File

@ -1,7 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`All Products can be created 1`] = `
"<!-- wp:woocommerce/all-products {\\"columns\\":3,\\"rows\\":3,\\"alignButtons\\":false,\\"contentVisibility\\":{\\"orderBy\\":true},\\"orderby\\":\\"date\\",\\"layoutConfig\\":[[\\"woocommerce/product-image\\"],[\\"woocommerce/product-title\\"],[\\"woocommerce/product-price\\"],[\\"woocommerce/product-rating\\"],[\\"woocommerce/product-button\\"]]} -->
<div class=\\"wp-block-woocommerce-all-products wc-block-all-products\\" data-attributes=\\"{&quot;alignButtons&quot;:false,&quot;columns&quot;:3,&quot;contentVisibility&quot;:{&quot;orderBy&quot;:true},&quot;isPreview&quot;:false,&quot;layoutConfig&quot;:[[&quot;woocommerce/product-image&quot;],[&quot;woocommerce/product-title&quot;],[&quot;woocommerce/product-price&quot;],[&quot;woocommerce/product-rating&quot;],[&quot;woocommerce/product-button&quot;]],&quot;orderby&quot;:&quot;date&quot;,&quot;rows&quot;:3}\\"></div>
<!-- /wp:woocommerce/all-products -->"
`;

View File

@ -1,27 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Cart Block can be created 1`] = `
"<!-- wp:woocommerce/cart -->
<div class=\\"wp-block-woocommerce-cart is-loading\\"><!-- wp:image {\\"align\\":\\"center\\",\\"sizeSlug\\":\\"small\\"} -->
<div class=\\"wp-block-image\\"><figure class=\\"aligncenter size-small\\"><img src=\\"data:image/svg+x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IDEyLjg3MSAxNS4zMjI2IDEzLjk2NjUgMTUuMzIyNiAxNS4zMjI2QzE1LjMyMjYgMTYuNjc4NiAxNC4yMjcgMTcuNzc0MiAxMi44NzEgMTcuNzc0MlpNMjUuOTEwNSAyOS41ODc5QzI0LjE5NDQgMjcuNTM0NyAyMS42NzM4IDI2LjM1NDggMTkgMjYuMzU0OEMxNy4zNzU4IDI2LjM1NDggMTcuMzc1OCAyMy45MDMyIDE5IDIzLjkwMzJDMjIuNDAxNiAyMy45MDMyIDI1LjYxMTcgMjUuNDA0OCAyNy43ODc1IDI4LjAyNUMyOC44NDQ4IDI5LjI4MTUgMjYuOTI5NCAzMC44MjE0IDI1LjkxMDUgMjkuNTg3OVoiIGZpbGw9ImJsYWNrIi8+Cjwvc3ZnPgo=\\" alt=\\"\\"/></figure></div>
<!-- /wp:image -->
<!-- wp:heading {\\"align\\":\\"center\\",\\"className\\":\\"wc-block-cart__empty-cart__title\\"} -->
<h2 class=\\"has-text-align-center wc-block-cart__empty-cart__title\\">Your cart is currently empty!</h2>
<!-- /wp:heading -->
<!-- wp:paragraph {\\"align\\":\\"center\\"} -->
<p class=\\"has-text-align-center\\"><a href=\\"false\\">Browse store</a>.</p>
<!-- /wp:paragraph -->
<!-- wp:separator {\\"className\\":\\"is-style-dots\\"} -->
<hr class=\\"wp-block-separator is-style-dots\\"/>
<!-- /wp:separator -->
<!-- wp:heading {\\"align\\":\\"center\\"} -->
<h2 class=\\"has-text-align-center\\">New in store</h2>
<!-- /wp:heading -->
<!-- wp:woocommerce/product-new {\\"rows\\":1} /--></div>
<!-- /wp:woocommerce/cart -->"
`;

View File

@ -1,7 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Checkout Block can be created 1`] = `
"<!-- wp:woocommerce/checkout -->
<div class=\\"wp-block-woocommerce-checkout is-loading\\"></div>
<!-- /wp:woocommerce/checkout -->"
`;

View File

@ -1,12 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Product Search can be created 1`] = `
"<!-- wp:woocommerce/product-search {\\"formId\\":\\"wc-block-product-search-2\\"} -->
<div class=\\"wp-block-woocommerce-product-search\\"><div class=\\"wc-block-product-search\\"><form role=\\"search\\" method=\\"get\\" action=\\"http://localhost:8084/\\"><label for=\\"wc-block-product-search-2\\" class=\\"wc-block-product-search__label\\">Search</label><div class=\\"wc-block-product-search__fields\\"><input type=\\"search\\" id=\\"wc-block-product-search-2\\" class=\\"wc-block-product-search__field\\" placeholder=\\"Search products…\\" name=\\"s\\"/><input type=\\"hidden\\" name=\\"post_type\\" value=\\"product\\"/><button type=\\"submit\\" class=\\"wc-block-product-search__button\\" label=\\"Search\\"><svg aria-hidden=\\"true\\" role=\\"img\\" focusable=\\"false\\" class=\\"dashicon dashicons-arrow-right-alt2\\" xmlns=\\"http://www.w3.org/2000/svg\\" width=\\"20\\" height=\\"20\\" viewbox=\\"0 0 20 20\\"><path d=\\"M6 15l5-5-5-5 1-2 7 7-7 7z\\"></path></svg></button></div></form></div></div>
<!-- /wp:woocommerce/product-search -->"
`;
exports[`Product Search can change field labels in editor 1`] = `
exports[`Product Search Block can change field labels in editor 1`] = `
"<!-- wp:woocommerce/product-search {\\"formId\\":\\"wc-block-product-search-2\\"} -->
<div class=\\"wp-block-woocommerce-product-search\\"><div class=\\"wc-block-product-search\\"><form role=\\"search\\" method=\\"get\\" action=\\"http://localhost:8084/\\"><label for=\\"wc-block-product-search-2\\" class=\\"wc-block-product-search__label\\">The Label</label><div class=\\"wc-block-product-search__fields\\"><input type=\\"search\\" id=\\"wc-block-product-search-2\\" class=\\"wc-block-product-search__field\\" placeholder=\\"The Placeholder\\" name=\\"s\\"/><input type=\\"hidden\\" name=\\"post_type\\" value=\\"product\\"/><button type=\\"submit\\" class=\\"wc-block-product-search__button\\" label=\\"Search\\"><svg aria-hidden=\\"true\\" role=\\"img\\" focusable=\\"false\\" class=\\"dashicon dashicons-arrow-right-alt2\\" xmlns=\\"http://www.w3.org/2000/svg\\" width=\\"20\\" height=\\"20\\" viewbox=\\"0 0 20 20\\"><path d=\\"M6 15l5-5-5-5 1-2 7 7-7 7z\\"></path></svg></button></div></form></div></div>
<!-- /wp:woocommerce/product-search -->"

View File

@ -3,20 +3,49 @@
*/
import {
insertBlock,
getEditedPostContent,
createNewPost,
getAllBlocks,
switchUserToAdmin,
} from '@wordpress/e2e-test-utils';
describe( 'All Products', () => {
beforeEach( async () => {
import { visitBlockPage } from '@woocommerce/blocks-test-utils';
const block = {
name: 'All Products',
slug: 'woocommerce/all-products',
class: '.wc-block-all-products',
};
describe( `${ block.name } Block`, () => {
beforeAll( async () => {
await switchUserToAdmin();
await createNewPost();
await visitBlockPage( `${ block.name } Block` );
} );
it( 'can be created', async () => {
await insertBlock( 'All Products' );
it( 'can only be inserted once', async () => {
await insertBlock( block.name );
expect( await getAllBlocks() ).toHaveLength( 1 );
} );
expect( await getEditedPostContent() ).toMatchSnapshot();
it( 'renders without crashing', async () => {
// Gutenberg error
expect(
( await page.content() ).match(
/Your site doesnt include support for/gi
)
).toBeNull();
// Our ErrorBoundary
expect(
( await page.content() ).match(
/There was an error whilst rendering/gi
)
).toBeNull();
// Validation Error
expect(
( await page.content() ).match(
/This block contains unexpected or invalid content/gi
)
).toBeNull();
await expect( page ).toMatchElement( block.class );
} );
} );

View File

@ -3,28 +3,49 @@
*/
import {
insertBlock,
getEditedPostContent,
getAllBlocks,
createNewPost,
switchUserToAdmin,
} from '@wordpress/e2e-test-utils';
describe( 'Cart Block', () => {
beforeEach( async () => {
await switchUserToAdmin();
await createNewPost();
} );
import { visitBlockPage } from '@woocommerce/blocks-test-utils';
it( 'can be created', async () => {
await insertBlock( 'Cart' );
expect( await getEditedPostContent() ).toMatchSnapshot();
const block = {
name: 'Cart',
slug: 'woocommerce/cart',
class: '.wc-block-cart',
};
describe( `${ block.name } Block`, () => {
beforeAll( async () => {
await switchUserToAdmin();
await visitBlockPage( `${ block.name } Block` );
} );
it( 'can only be inserted once', async () => {
await insertBlock( 'Cart' );
expect( await getAllBlocks() ).toHaveLength( 1 );
await insertBlock( 'Cart' );
await insertBlock( block.name );
expect( await getAllBlocks() ).toHaveLength( 1 );
} );
it( 'renders without crashing', async () => {
// Gutenberg error
expect(
( await page.content() ).match(
/Your site doesnt include support for/gi
)
).toBeNull();
// Our ErrorBoundary
expect(
( await page.content() ).match(
/There was an error whilst rendering/gi
)
).toBeNull();
// Validation Error
expect(
( await page.content() ).match(
/This block contains unexpected or invalid content/gi
)
).toBeNull();
await expect( page ).toMatchElement( block.class );
} );
} );

View File

@ -3,28 +3,49 @@
*/
import {
insertBlock,
getEditedPostContent,
getAllBlocks,
createNewPost,
switchUserToAdmin,
} from '@wordpress/e2e-test-utils';
describe( 'Checkout Block', () => {
beforeEach( async () => {
await switchUserToAdmin();
await createNewPost();
} );
import { visitBlockPage } from '@woocommerce/blocks-test-utils';
it( 'can be created', async () => {
await insertBlock( 'Checkout' );
expect( await getEditedPostContent() ).toMatchSnapshot();
const block = {
name: 'Checkout',
slug: 'woocommerce/checkout',
class: '.wc-block-checkout',
};
describe( `${ block.name } Block`, () => {
beforeAll( async () => {
await switchUserToAdmin();
await visitBlockPage( `${ block.name } Block` );
} );
it( 'can only be inserted once', async () => {
await insertBlock( 'Checkout' );
expect( await getAllBlocks() ).toHaveLength( 1 );
await insertBlock( 'Checkout' );
await insertBlock( block.name );
expect( await getAllBlocks() ).toHaveLength( 1 );
} );
it( 'renders without crashing', async () => {
// Gutenberg error
expect(
( await page.content() ).match(
/Your site doesnt include support for/gi
)
).toBeNull();
// Our ErrorBoundary
expect(
( await page.content() ).match(
/There was an error whilst rendering/gi
)
).toBeNull();
// Validation Error
expect(
( await page.content() ).match(
/This block contains unexpected or invalid content/gi
)
).toBeNull();
await expect( page ).toMatchElement( block.class );
} );
} );

View File

@ -2,37 +2,63 @@
* External dependencies
*/
import {
insertBlock,
getEditedPostContent,
createNewPost,
switchUserToAdmin,
getEditedPostContent,
openDocumentSettingsSidebar,
} from '@wordpress/e2e-test-utils';
import { clearAndFillInput } from '@woocommerce/e2e-tests/utils';
import { visitBlockPage } from '@woocommerce/blocks-test-utils';
describe( 'Product Search', () => {
beforeEach( async () => {
const block = {
name: 'Product Search',
slug: 'woocommerce/product-search',
class: '.wc-block-product-search',
};
describe( `${ block.name } Block`, () => {
beforeAll( async () => {
await switchUserToAdmin();
await createNewPost();
await visitBlockPage( `${ block.name } Block` );
} );
it( 'can be created', async () => {
await insertBlock( 'Product Search' );
it( 'renders without crashing', async () => {
// Gutenberg error
expect(
( await page.content() ).match(
/Your site doesnt include support for/gi
)
).toBeNull();
// Our ErrorBoundary
expect(
( await page.content() ).match(
/There was an error whilst rendering/gi
)
).toBeNull();
// Validation Error
expect(
( await page.content() ).match(
/This block contains unexpected or invalid content/gi
)
).toBeNull();
expect( await getEditedPostContent() ).toMatchSnapshot();
await expect( page ).toMatchElement( block.class );
} );
it( 'can toggle field label', async () => {
await insertBlock( 'Product Search' );
await openDocumentSettingsSidebar();
// we focus on the block
await page.click( block.class );
await page.click( '.components-form-toggle__input' );
await expect( page ).not.toMatchElement(
'.wc-block-product-search .wc-block-product-search__label'
`${ block.class } .wc-block-product-search__label`
);
await page.click( '.components-form-toggle__input' );
await expect( page ).toMatchElement(
`${ block.class } .wc-block-product-search__label`
);
} );
it( 'can change field labels in editor', async () => {
await insertBlock( 'Product Search' );
await expect( page ).toFill(
'textarea.wc-block-product-search__label',
'I am a new label'

View File

@ -0,0 +1,56 @@
/**
* External dependencies
*/
import {
insertBlock,
getAllBlocks,
switchUserToAdmin,
} from '@wordpress/e2e-test-utils';
import { visitBlockPage } from '@woocommerce/blocks-test-utils';
const block = {
name: 'Single Product',
slug: 'woocommerce/single-product',
class: '.wc-block-single-product',
};
describe( `${ block.name } Block`, () => {
beforeAll( async () => {
await switchUserToAdmin();
await visitBlockPage( `${ block.name } Block` );
} );
it( 'can be inserted more than once', async () => {
await insertBlock( block.name );
expect( await getAllBlocks() ).toHaveLength( 2 );
await page.keyboard.down( 'Shift' );
await page.keyboard.press( 'Tab' );
await page.keyboard.up( 'Shift' );
await page.keyboard.press( 'Delete' );
expect( await getAllBlocks() ).toHaveLength( 1 );
} );
it( 'renders without crashing', async () => {
// Gutenberg error
expect(
( await page.content() ).match(
/Your site doesnt include support for/gi
)
).toBeNull();
// Our ErrorBoundary
expect(
( await page.content() ).match(
/There was an error whilst rendering/gi
)
).toBeNull();
// Validation Error
expect(
( await page.content() ).match(
/This block contains unexpected or invalid content/gi
)
).toBeNull();
await expect( page ).toMatchElement( block.class );
} );
} );

View File

@ -1,30 +0,0 @@
/**
* External dependencies
*/
import {
insertBlock,
getEditedPostContent,
getAllBlocks,
createNewPost,
switchUserToAdmin,
} from '@wordpress/e2e-test-utils';
describe( 'Single Product Block', () => {
beforeEach( async () => {
await switchUserToAdmin();
await createNewPost();
} );
it( 'can be created', async () => {
await insertBlock( 'Single Product' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'can be inserted more than once', async () => {
await insertBlock( 'Single Product' );
expect( await getAllBlocks() ).toHaveLength( 1 );
await insertBlock( 'Single Product' );
expect( await getAllBlocks() ).toHaveLength( 2 );
} );
} );

View File

@ -6,7 +6,9 @@
"!**/vendor/**",
"!**/test/**"
],
"moduleDirectories": [ "node_modules" ],
"moduleDirectories": [
"node_modules"
],
"moduleNameMapper": {
"@woocommerce/atomic-blocks": "assets/js/atomic/blocks",
"@woocommerce/atomic-utils": "assets/js/atomic/utils",
@ -23,7 +25,8 @@
"@woocommerce/base-utils(.*)$": "assets/js/base/utils",
"@woocommerce/block-data": "assets/js/data",
"@woocommerce/resource-previews": "assets/js/previews",
"@woocommerce/shared-context": "assets/js/shared/context"
"@woocommerce/shared-context": "assets/js/shared/context",
"@woocommerce/blocks-test-utils": "tests/utils"
},
"setupFiles": [
"<rootDir>/node_modules/@wordpress/jest-preset-default/scripts/setup-globals.js",
@ -39,11 +42,13 @@
"<rootDir>/node_modules/",
"<rootDir>/vendor/"
],
"transformIgnorePatterns": [ "node_modules/(?!(simple-html-tokenizer)/)" ],
"transformIgnorePatterns": [
"node_modules/(?!(simple-html-tokenizer)/)"
],
"testEnvironment": "jest-environment-jsdom-sixteen",
"preset": "@wordpress/jest-preset-default",
"transform": {
"^.+\\.js$": "<rootDir>/tests/js/jestPreprocess.js"
},
"verbose": true
}
}

View File

@ -0,0 +1 @@
export { visitBlockPage } from './visit-block-page';

View File

@ -0,0 +1,84 @@
/**
* External dependencies
*/
import {
createNewPost,
visitAdminPage,
insertBlock,
getEditedPostContent,
} from '@wordpress/e2e-test-utils';
import { outputFile } from 'fs-extra';
import { dirname } from 'path';
import kebabCase from 'lodash/kebabCase';
/**
*
* @param {string} link the page or post you want to visit.
*
* This will visit a GB page or post, and will hide the welcome guide.
*/
async function visitPage( link ) {
await page.goto( link );
const isWelcomeGuideActive = await page.evaluate( () =>
wp.data.select( 'core/edit-post' ).isFeatureActive( 'welcomeGuide' )
);
if ( isWelcomeGuideActive ) {
await page.evaluate( () =>
wp.data.dispatch( 'core/edit-post' ).toggleFeature( 'welcomeGuide' )
);
}
}
/**
*
* @param {string} title the page title, written as `BLOCK_NAME block`
*
* This function will attempt to search for a page with the `title`
* if that block is found, it will open it, if it's not found, it will open
* a new page, insert the block, save the page content and title as a fixture file.
* In both cases, this page will end up with a page open with the block inserted.
*/
export async function visitBlockPage( title ) {
let link = '';
// Visit Import Products page.
await visitAdminPage( 'edit.php', 'post_type=page' );
// If the website has no pages, `#post-search-input` will not render.
if ( await page.$( '#post-search-input' ) ) {
// search for the page.
await page.type( '#post-search-input', title );
await page.click( '#search-submit', { waitUntil: 'domcontentloaded' } );
const pageLink = await page.$x( `//a[contains(text(), '${ title }')]` );
if ( ( await pageLink.length ) > 0 ) {
// clicking the link directly caused racing issues, so I used goto.
link = await page.evaluate(
( a ) => a.getAttribute( 'href' ),
pageLink[ 0 ]
);
}
}
if ( link ) {
await visitPage( link );
} else {
await createNewPost( { postType: 'page', title } );
await insertBlock( title.replace( /block/i, '' ).trim() );
const pageContent = await getEditedPostContent();
await outputFile(
`${ dirname(
// we want to fetch the path of the test file who triggered this function
// this could be two levels up, or one level up, depending on how you launch the test.
module.parent.parent.filename ||
module.parent.filename ||
module.filename
) }/__fixtures__/${ kebabCase(
title.replace( /block/i, '' ).trim()
) }.fixture.json`,
JSON.stringify( {
title,
pageContent,
} )
);
}
}
export default visitBlockPage;