Skip to content

Commit d705087

Browse files
chore: update the tests and hierarchy
1 parent 9112fed commit d705087

File tree

13 files changed

+367
-144
lines changed

13 files changed

+367
-144
lines changed

.github/workflows/test-e2e.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
run: composer install --no-dev
3939
- name: Install environment
4040
run: |
41-
npm run up:ci
41+
npm run env:up
4242
- name: Run the tests
4343
run: |
4444
npm run test:e2e:playwright

docker-compose.ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ services:
1010
MYSQL_DATABASE: wordpress
1111
MYSQL_USER: wordpress
1212
MYSQL_PASSWORD: wordpress
13+
ports:
14+
- 3306:3306
1315
cli:
1416
privileged: true
1517
image: wordpress:cli
@@ -45,4 +47,4 @@ services:
4547
WORDPRESS_DEBUG: 1
4648

4749
volumes:
48-
wpcore:
50+
wpcore:

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
"scripts": {
2020
"dist": "bash bin/dist.sh",
2121
"release": "semantic-release --debug",
22-
"up:ci": "export DOCKER_FILE=docker-compose.ci.yml && bash bin/wp-init.sh",
23-
"down:ci": "export DOCKER_FILE=docker-compose.ci.yml && bash bin/wp-down.sh",
22+
"env:up": "export DOCKER_FILE=docker-compose.ci.yml && bash bin/wp-init.sh",
23+
"env:down": "export DOCKER_FILE=docker-compose.ci.yml && bash bin/wp-down.sh",
2424
"cypress:open": "cypress open",
2525
"cypress:run": "cypress run --browser=chrome",
2626
"wp-env": "wp-env",

tests/e2e/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ npm run test:e2e:playwright:debug
3434
> [!NOTE]
3535
> When writing a test, using the debug mode is recommended since it will allow you to see the browser and the test in action.
3636
37+
For database connection, the credentials are:
38+
39+
- Host: `localhost` or `127.0.0.1`
40+
- Database: `wordpress`
41+
- User: `admin`
42+
- Password: `password`
43+
- Port: `3306`
44+
45+
> [!NOTE]
46+
> You can modify the credentials in the `docker-compose.yml` file.
47+
3748
### Learn more about E2E testing
3849

3950
Resources:

tests/e2e/assets/area.csv

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Month,Bolivia,Ecuador,Madagascar,Papua New Guinea,Rwanda
2+
string,number,number,number,number,number
3+
2004/05/01,165,938,522,998,450
4+
2005/06/01,135,1120,599,1268,288
5+
2006/07/01,157,1167,587,807,397
6+
2007/08/01,139,1110,615,968,215
7+
2008/09/01,136,691,629,1026,366

tests/e2e/assets/pie.csv

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Task,Hours per Day
2+
string,number
3+
Work,5
4+
Eat,5
5+
Commute,5
6+
Watch TV,5
7+
Sleep,5
8+
World Of Warcraft,5

tests/e2e/specs/gutenberg/admin.spec.js renamed to tests/e2e/specs/admin.spec.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* WordPress dependencies
33
*/
44
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );
5-
const { createChartWithAdmin, deleteAllCharts, waitForLibraryToLoad } = require('../common');
5+
const { createChartWithAdmin, deleteAllCharts, waitForLibraryToLoad, createAllFreeCharts } = require('../utils/common');
66

77
test.describe( 'Chart Library', () => {
88

@@ -111,6 +111,16 @@ test.describe( 'Chart Library', () => {
111111
await waitForLibraryToLoad( page );
112112
await expect( page.locator(`#visualizer-${chartId}`).count() ).resolves.toBe( 0 );
113113
} );
114+
115+
test( 'create all free charts', async ( { admin, page } ) => {
116+
const chartsId = await createAllFreeCharts( admin, page );
117+
await waitForLibraryToLoad( page );
118+
119+
expect( page.locator('.visualizer-chart').count() ).resolves.toBe( 4 );
120+
for (const chartId of chartsId) {
121+
await expect( page.locator(`#visualizer-${chartId}`).count() ).resolves.toBeGreaterThan( 0 );
122+
}
123+
} );
114124
} );
115125

116126
test.describe( 'Support', () => {

tests/e2e/specs/chart-sources.spec.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
* WordPress dependencies
3+
*/
4+
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );
5+
const { deleteAllCharts, getAssetFilePath, CHART_JS_LABELS, selectChartAdmin } = require('../utils/common');
6+
7+
test.describe( 'Data Free Sources', () => {
8+
test.beforeEach( async ( { admin, requestUtils, page } ) => {
9+
await deleteAllCharts( requestUtils );
10+
await admin.visitAdminPage( 'admin.php?page=visualizer' );
11+
page.setDefaultTimeout( 5000 );
12+
} );
13+
14+
test( 'import a local CSV file', async ( { admin, page } ) => {
15+
await admin.visitAdminPage( 'admin.php?page=visualizer&vaction=addnew' );
16+
await page.waitForURL( '**/admin.php?page=visualizer&vaction=addnew' );
17+
await page.waitForSelector('h1:text("Visualizer")');
18+
19+
await selectChartAdmin( page.frameLocator('iframe'), CHART_JS_LABELS.pie );
20+
await page.frameLocator('iframe').getByRole('button', { name: 'Next' }).click();
21+
22+
// Upload the CSV file
23+
await expect( page.frameLocator('iframe').locator('#csv-file') ).toBeVisible();
24+
await page.frameLocator('iframe').locator('#csv-file').setInputFiles( getAssetFilePath( 'pie.csv' ) );
25+
await page.frameLocator('iframe').getByRole('button', { name: 'Import' }).click();
26+
27+
28+
await page.frameLocator('iframe').getByRole('button', { name: 'Create Chart' }).click();
29+
30+
// Check if the chart contains the data from the CSV file
31+
await expect( page.locator('text').filter({ hasText: 'Warcraft' }) ).toBeVisible();
32+
} );
33+
34+
test( 'import a remote CSV file', async ( { admin, page } ) => {
35+
const importURL = 'https://s3.amazonaws.com/verti-utils/samples-visualizer/area.csv';
36+
37+
await admin.visitAdminPage( 'admin.php?page=visualizer&vaction=addnew' );
38+
await page.waitForURL( '**/admin.php?page=visualizer&vaction=addnew' );
39+
await page.waitForSelector('h1:text("Visualizer")');
40+
41+
await selectChartAdmin( page.frameLocator('iframe'), CHART_JS_LABELS.area );
42+
await page.frameLocator('iframe').getByRole('button', { name: 'Next' }).click();
43+
44+
// Fill the URL of the CSV file and import it.
45+
await page.frameLocator('iframe').getByRole('heading', { name: 'Import data from URL' }).click();
46+
await page.frameLocator('iframe').getByText('Import from CSV').click();
47+
await page.frameLocator('iframe').getByPlaceholder('Please enter the URL of CSV').fill( importURL );
48+
await page.frameLocator('iframe').getByRole('button', { name: 'Import' }).click();
49+
await expect( page.frameLocator('iframe').getByRole('img').getByText('Bolivia') ).toBeVisible();
50+
51+
await page.frameLocator('iframe').getByRole('button', { name: 'Create Chart' }).click();
52+
53+
// Check if the chart contains the data from the CSV file
54+
await expect( page.locator('text').filter({ hasText: '/05/01' }) ).toBeVisible();
55+
} );
56+
57+
test( 'import a remote JSON file', async ( { admin, page } ) => {
58+
const importURL = 'https://s3.amazonaws.com/verti-utils/samples-visualizer/test.json';
59+
60+
await admin.visitAdminPage( 'admin.php?page=visualizer&vaction=addnew' );
61+
await page.waitForURL( '**/admin.php?page=visualizer&vaction=addnew' );
62+
await page.waitForSelector('h1:text("Visualizer")');
63+
64+
await selectChartAdmin( page.frameLocator('iframe'), CHART_JS_LABELS.table );
65+
await page.frameLocator('iframe').getByRole('button', { name: 'Next' }).click();
66+
67+
await page.frameLocator('iframe').getByRole('heading', { name: 'Import data from URL' }).click();
68+
await page.frameLocator('iframe').getByText('Import from JSON').click();
69+
await page.frameLocator('iframe').getByRole('button', { name: 'Create Parameters' }).click();
70+
71+
await page.frameLocator('iframe').getByPlaceholder('Please enter the URL', { exact: true }).fill( importURL );
72+
await page.frameLocator('iframe').getByRole('button', { name: 'Fetch Endpoint' }).click({ force: true});
73+
74+
await page.frameLocator('iframe').getByRole('button', { name: 'Create Chart' }).click();
75+
76+
// Check if the chart contains the data from the JSON file
77+
await expect( page.getByRole('gridcell', { name: '/05/01' }) ).toBeVisible();
78+
} );
79+
} );
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* WordPress dependencies
3+
*/
4+
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );
5+
const { deleteAllCharts, createChartWithAdmin } = require('../utils/common');
6+
7+
test.describe( 'Charts with Classic Editor', () => {
8+
test.beforeAll( async ( { requestUtils } ) => {
9+
await deleteAllCharts( requestUtils );
10+
await requestUtils.activatePlugin( 'classic-editor' );
11+
} );
12+
13+
test.afterAll( async ( { requestUtils } ) => {
14+
await requestUtils.deactivatePlugin( 'classic-editor' );
15+
} );
16+
17+
test('insert chart into a Post via Media', async({ admin, page }) => {
18+
const chartId = await createChartWithAdmin( admin, page );
19+
await admin.visitAdminPage( 'post-new.php' );
20+
21+
await page.getByRole('button', { name: 'Add Media' }).click();
22+
await page.getByRole('tab', { name: 'Visualizations' }).click();
23+
24+
await page.waitForSelector('.visualizer-library-chart', {timeout: 5000});
25+
26+
await page.locator('.visualizer-library-chart').click({ force: true});
27+
28+
await expect( page.frameLocator('iframe[title*="Rich Text Area"]').getByText(`[visualizer id="${chartId}"]`) ).toBeVisible();
29+
});
30+
});

tests/e2e/specs/common.js

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)