-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dataviews: Add first e2e tests (#56634)
* Dataviews: Add first e2e tests * refactor tests and add `createTemplate` util
- Loading branch information
1 parent
57eded6
commit c703616
Showing
4 changed files
with
143 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
/** | ||
* Plugin Name: Gutenberg Test DataViews | ||
* Plugin URI: https://github.com/WordPress/gutenberg | ||
* Author: Gutenberg Team | ||
* | ||
* @package gutenberg-test-dataviews | ||
*/ | ||
|
||
/** | ||
* Disables the DataViews experiment on plugin deactivation. | ||
*/ | ||
function disable_dataviews_experiment() { | ||
update_option( 'gutenberg-experiments', array() ); | ||
} | ||
|
||
/** | ||
* Enables the DataViews experiment. | ||
*/ | ||
function enable_dataviews_experiment() { | ||
update_option( 'gutenberg-experiments', array( 'gutenberg-dataviews' => true ) ); | ||
register_deactivation_hook( __FILE__, 'disable_dataviews_experiment' ); | ||
} | ||
|
||
add_action( 'init', 'enable_dataviews_experiment' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); | ||
|
||
test.describe( 'Templates', () => { | ||
test.beforeAll( async ( { requestUtils } ) => { | ||
await Promise.all( [ | ||
requestUtils.activateTheme( 'emptytheme' ), | ||
requestUtils.activatePlugin( 'gutenberg-test-dataviews' ), | ||
] ); | ||
} ); | ||
test.afterAll( async ( { requestUtils } ) => { | ||
await Promise.all( [ | ||
requestUtils.activateTheme( 'twentytwentyone' ), | ||
requestUtils.deactivatePlugin( 'gutenberg-test-dataviews' ), | ||
] ); | ||
} ); | ||
test( 'Sorting', async ( { admin, page } ) => { | ||
await admin.visitSiteEditor( { path: '/wp_template/all' } ); | ||
// Descending by title. | ||
await page.getByRole( 'button', { name: 'Template' } ).click(); | ||
await page.getByRole( 'menuitem', { name: 'Sort descending' } ).click(); | ||
const firstTitle = page | ||
.getByRole( 'region', { | ||
name: 'Template', | ||
includeHidden: true, | ||
} ) | ||
.getByRole( 'heading', { | ||
level: 3, | ||
includeHidden: true, | ||
} ) | ||
.first(); | ||
await expect( firstTitle ).toHaveText( 'Tag Archives' ); | ||
// Ascending by title. | ||
await page.getByRole( 'menuitem', { name: 'Sort ascending' } ).click(); | ||
await expect( firstTitle ).toHaveText( 'Category Archives' ); | ||
} ); | ||
test( 'Filtering', async ( { requestUtils, admin, page } ) => { | ||
await requestUtils.createTemplate( 'wp_template', { | ||
slug: 'date', | ||
title: 'Date Archives', | ||
content: 'hi', | ||
} ); | ||
await admin.visitSiteEditor( { path: '/wp_template/all' } ); | ||
// Global search. | ||
await page.getByRole( 'searchbox', { name: 'Filter list' } ).click(); | ||
await page.keyboard.type( 'tag' ); | ||
const titles = page | ||
.getByRole( 'region', { name: 'Template' } ) | ||
.getByRole( 'heading', { level: 3 } ); | ||
await expect( titles ).toHaveCount( 1 ); | ||
await expect( titles.first() ).toHaveText( 'Tag Archives' ); | ||
await page.getByRole( 'button', { name: 'Reset filters' } ).click(); | ||
await expect( titles ).toHaveCount( 6 ); | ||
|
||
// Filter by author. | ||
await page.getByRole( 'button', { name: 'Add filter' } ).click(); | ||
await page.getByRole( 'menuitem', { name: 'Author' } ).hover(); | ||
await page.getByRole( 'menuitemcheckbox', { name: 'admin' } ).click(); | ||
await expect( titles ).toHaveCount( 1 ); | ||
await expect( titles.first() ).toHaveText( 'Date Archives' ); | ||
|
||
// Filter by author and text. | ||
await page.getByRole( 'button', { name: 'Reset filters' } ).click(); | ||
await page.getByRole( 'searchbox', { name: 'Filter list' } ).click(); | ||
await page.keyboard.type( 'archives' ); | ||
await expect( titles ).toHaveCount( 3 ); | ||
await page.getByRole( 'button', { name: 'Add filter' } ).click(); | ||
await page.getByRole( 'menuitem', { name: 'Author' } ).hover(); | ||
await page | ||
.getByRole( 'menuitemcheckbox', { name: 'Emptytheme' } ) | ||
.click(); | ||
await expect( titles ).toHaveCount( 2 ); | ||
|
||
await requestUtils.deleteAllTemplates( 'wp_template' ); | ||
} ); | ||
test( 'Field visibility', async ( { admin, page } ) => { | ||
await admin.visitSiteEditor( { path: '/wp_template/all' } ); | ||
await page.getByRole( 'button', { name: 'Description' } ).click(); | ||
await page.getByRole( 'menuitem', { name: 'Hide' } ).click(); | ||
await expect( | ||
page.getByRole( 'button', { name: 'Description' } ) | ||
).toBeHidden(); | ||
} ); | ||
} ); |