Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Add E2E tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gigitux committed Nov 27, 2023
1 parent 9c3a97b commit 2390c43
Show file tree
Hide file tree
Showing 2 changed files with 210 additions and 0 deletions.
115 changes: 115 additions & 0 deletions tests/e2e/tests/single-product-template/compatibility-plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php
/**
* Plugin Name: Compatibility Layer Plugin
* Description: Adds custom content to the Shop page with Product Collection included
* @package WordPress
*/

add_action(
'woocommerce_before_main_content',
function () {
echo '<p data-testid="woocommerce_before_main_content">
Hook: woocommerce_before_main_content
</p>';
}
);

add_action(
'woocommerce_sidebar',
function () {
echo '<p data-testid="woocommerce_sidebar">
Hook: woocommerce_sidebar
</p>';
}
);

add_action(
'woocommerce_before_single_product',
function () {
echo '<p data-testid="woocommerce_before_single_product">
Hook: woocommerce_before_single_product
</p>';
}
);

add_action(
'woocommerce_before_single_product_summary',
function () {
echo '<p data-testid="woocommerce_before_single_product_summary">
Hook: woocommerce_before_single_product_summary
</p>';
}
);

add_action(
'woocommerce_single_product_summary',
function () {
echo '<p data-testid="woocommerce_single_product_summary">
Hook: woocommerce_single_product_summary
</p>';
}
);

add_action(
'woocommerce_before_add_to_cart_button',
function () {
echo '<p data-testid="woocommerce_before_add_to_cart_button">
Hook: woocommerce_before_add_to_cart_button
</p>';
}
);


add_action(
'woocommerce_product_meta_start',
function () {
echo '<p data-testid="woocommerce_product_meta_start">
Hook: woocommerce_product_meta_start
</p>';
}
);

add_action(
'woocommerce_product_meta_end',
function () {
echo '<p data-testid="woocommerce_product_meta_end">
Hook: woocommerce_product_meta_end
</p>';
}
);

add_action(
'woocommerce_share',
function () {
echo '<p data-testid="woocommerce_share">
Hook: woocommerce_share
</p>';
}
);

add_action(
'woocommerce_after_single_product_summary',
function () {
echo '<p data-testid="woocommerce_after_single_product_summary">
Hook: woocommerce_after_single_product_summary
</p>';
}
);

add_action(
'woocommerce_after_single_product',
function () {
echo '<p data-testid="woocommerce_after_single_product">
Hook: woocommerce_after_single_product
</p>';
}
);

add_action(
'woocommerce_after_main_content',
function () {
echo '<p data-testid="woocommerce_after_main_content">
Hook: woocommerce_after_main_content
</p>';
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/**
* External dependencies
*/
import { test, expect } from '@woocommerce/e2e-playwright-utils';
import {
installPluginFromPHPFile,
uninstallPluginFromPHPFile,
} from '@woocommerce/e2e-mocks/custom-plugins';

/**
* Internal dependencies
*/

type Scenario = {
title: string;
dataTestId: string;
content: string;
amount: number;
};

const singleOccurranceScenarios: Scenario[] = [
{
title: 'Before Single Product',
dataTestId: 'woocommerce_before_single_product',
content: 'Hook: woocommerce_before_single_product',
amount: 1,
},
{
title: 'Before Add To Cart Button',
dataTestId: 'woocommerce_before_add_to_cart_button',
content: 'Hook: woocommerce_before_add_to_cart_button',
amount: 1,
},
{
title: 'Single Product Summary',
dataTestId: 'woocommerce_single_product_summary',
content: 'Hook: woocommerce_single_product_summary',
amount: 1,
},
{
title: 'Product Meta Start',
dataTestId: 'woocommerce_product_meta_start',
content: 'Hook: woocommerce_product_meta_start',
amount: 1,
},
{
title: 'After Single Product Summary',
dataTestId: 'woocommerce_after_single_product_summary',
content: 'Hook: woocommerce_after_single_product_summary',
amount: 1,
},
{
title: 'After Single Product',
dataTestId: 'woocommerce_after_single_product',
content: 'Hook: woocommerce_after_single_product',
amount: 1,
},
];

const compatiblityPluginFileName = 'compatibility-plugin.php';

test.describe( 'Compatibility Layer with Product Collection block', () => {
test.beforeAll( async () => {
await installPluginFromPHPFile(
`${ __dirname }/${ compatiblityPluginFileName }`
);
} );

test.describe(
'Product Archive with Product Collection block',
async () => {
test.beforeAll( async ( { page } ) => {
await page.goto( '/product/hoodie/' );
} );

for ( const scenario of singleOccurranceScenarios ) {
test( `${ scenario.title } is attached to the page`, async ( {
page,
} ) => {
const hooks = page.getByTestId( scenario.dataTestId );

await expect( hooks ).toHaveCount( scenario.amount );
await expect( hooks ).toHaveText( scenario.content );
} );
}
}
);
} );

test.afterAll( async ( { requestUtils } ) => {
await uninstallPluginFromPHPFile(
`${ __dirname }/${ compatiblityPluginFileName }`
);
await requestUtils.deleteAllTemplates( 'wp_template' );
} );

0 comments on commit 2390c43

Please sign in to comment.