Skip to content

Commit 7de74ae

Browse files
committed
feat: add delete lifecycle
1 parent 0d5e852 commit 7de74ae

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

tests/e2e/advanced-checks/confirmation-shortcode.test.js

+9-19
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ import { Selector, RequestLogger } from 'testcafe';
22
import { baseURL } from '../auth';
33
import { link } from '../utilities/page-model/helpers/field';
44
import AdvancedCheck from '../utilities/page-model/helpers/advanced-check';
5-
import Page from '../utilities/page-model/helpers/page';
65
// new Page model. Might be used soon as default
7-
import PagePostType from '../models/Page';
6+
import Page from '../models/Page';
87

98
let shortcodeHolder;
109
let downloadUrl;
1110
const run = new AdvancedCheck();
12-
const page = new Page();
1311
const downloadLogger = RequestLogger( downloadUrl, {
1412
logResponseBody: true,
1513
logResponseHeaders: true,
@@ -87,13 +85,14 @@ test( 'should check if the shortcode confirmation type PAGE is working correctly
8785

8886
// Create a new page and insert a shortcode block
8987
const name = 'Shortcode confrimation type Page';
90-
const pagePostType = new PagePostType( name );
91-
await pagePostType.add();
92-
await pagePostType.insertBlock( 'shortcode', {
88+
const page = new Page( name );
89+
await page.add();
90+
await page.insertBlock( 'shortcode', {
9391
target: '.block-editor-plain-text',
9492
content: shortcodeHolder,
9593
} );
96-
await pagePostType.publishChanges();
94+
await page.saveChanges();
95+
await page.publishChanges();
9796

9897
// update form settings
9998
await run.navigateConfirmationSection(
@@ -150,6 +149,9 @@ test( 'should check if the shortcode confirmation type PAGE is working correctly
150149
)
151150
)
152151
.ok();
152+
153+
// Cleanup
154+
await page.delete();
153155
} );
154156

155157
test( 'should check if the shortcode confirmation type REDIRECT download is working correctly', async ( t ) => {
@@ -199,15 +201,3 @@ test( 'should check if the shortcode confirmation type REDIRECT download is work
199201
)
200202
.ok();
201203
} );
202-
203-
// TODO: make these scenarios as part of the isolated test cases
204-
// eslint-disable-next-line jest/no-commented-out-tests
205-
// test( 'reset/clean Page entry for the next test', async ( t ) => {
206-
// // Actions & Assertions
207-
// await page.navigatePage();
208-
// await t
209-
// .hover( link( '#the-list', 'Test-page' ) )
210-
// .click( page.trashLink )
211-
// .expect( link( '#the-list', 'Test-page' ).exists )
212-
// .notOk();
213-
// } );

tests/e2e/models/Page.js

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { Selector, t } from 'testcafe';
22
import { link } from '../utilities/page-model/helpers/field';
3+
import { admin, baseURL } from '../auth';
4+
import { getQueryParam } from '../utilities/page-model/helpers/search-params';
35

46
class Page {
57
constructor( name ) {
8+
this.pageId = '';
69
this.pageName = name;
7-
this.sortDateColumn = Selector( 'th#date' );
810
this.addNewPageLink = link( '.wrap', 'Add New Page' );
911
this.trashLink = Selector( 'a' ).withAttribute(
1012
'aria-label',
@@ -33,6 +35,9 @@ class Page {
3335
this.documentPanelCloseButton = Selector(
3436
'button.components-button'
3537
).withAttribute( 'aria-label', 'Close panel' );
38+
this.saveToolbarButton = Selector(
39+
'button.components-button'
40+
).withText( 'Save' );
3641
this.publishToolbarButton = Selector(
3742
'.editor-post-publish-button__button'
3843
);
@@ -70,6 +75,12 @@ class Page {
7075
* @return {Promise<void>} none
7176
*/
7277
async delete() {
78+
await t
79+
.useRole( admin )
80+
.navigateTo(
81+
`${ baseURL }/wp-admin/post.php?post=${ this.pageId }&action=edit`
82+
);
83+
7384
if ( ! ( await this.documentPanel.exists ) ) {
7485
await t.click( this.documentPanelToolbarButton );
7586
}
@@ -110,14 +121,17 @@ class Page {
110121
* @return {Promise<void>} none
111122
*/
112123
async saveChanges() {
113-
await t.click( this.publishToolbarButton );
124+
await t.click( this.saveToolbarButton );
114125
}
115126

116127
async publishChanges() {
117128
await t
118129
.click( this.publishToolbarButton )
119-
.click( this.confirmPublishButton )
120-
.click( this.documentPanelCloseButton );
130+
.click( this.confirmPublishButton );
131+
132+
this.pageId = await getQueryParam( 'post' );
133+
134+
await t.click( this.documentPanelCloseButton );
121135
}
122136
}
123137

tests/e2e/utilities/page-model/helpers/search-params.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ClientFunction } from 'testcafe';
55
*
66
* @param { string } param
77
*
8-
* @return { * } param value
8+
* @return { string } param value
99
*/
1010
export const getQueryParam = ClientFunction( ( param ) => {
1111
const urlParams = new URLSearchParams( window.location.search );

0 commit comments

Comments
 (0)