Skip to content

Commit

Permalink
use more descriptive names
Browse files Browse the repository at this point in the history
  • Loading branch information
gigitux committed Dec 20, 2024
1 parent a25fbae commit cc3c2ea
Showing 1 changed file with 32 additions and 29 deletions.
61 changes: 32 additions & 29 deletions test/e2e/specs/site-editor/page-list.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ test.describe( 'Page List', () => {
test.describe( 'Quick Edit Mode', () => {
const fields = {
featuredImage: {
edit: async ( page ) => {
performEdit: async ( page ) => {
const placeholder = page.getByRole( 'button', {
name: 'Choose an image…',
} );
Expand All @@ -91,15 +91,15 @@ test.describe( 'Page List', () => {
.getByRole( 'button', { name: 'Select', exact: true } )
.click();
},
initialView: async ( page ) => {
assertInitialState: async ( page ) => {
const el = page.getByText( 'Choose an image…' );
const placeholder = page.getByRole( 'button', {
name: 'Choose an image…',
} );
await expect( el ).toBeVisible();
await expect( placeholder ).toBeVisible();
},
viewAfterEdit: async ( page ) => {
assertEditedState: async ( page ) => {
const placeholder = page.getByRole( 'button', {
name: 'Choose an image…',
} );
Expand All @@ -111,7 +111,7 @@ test.describe( 'Page List', () => {
},
},
statusVisibility: {
edit: async ( page ) => {
performEdit: async ( page ) => {
const statusAndVisibility = page.getByLabel(
'Status & Visibility'
);
Expand Down Expand Up @@ -140,15 +140,15 @@ test.describe( 'Page List', () => {
}
}
},
initialView: async ( page ) => {
assertInitialState: async ( page ) => {
const statusAndVisibility = page.getByLabel(
'Status & Visibility'
);
await expect( statusAndVisibility ).toContainText(
'Published'
);
},
viewAfterEdit: async ( page ) => {
assertEditedState: async ( page ) => {
const statusAndVisibility = page.getByLabel(
'Status & Visibility'
);
Expand All @@ -158,29 +158,29 @@ test.describe( 'Page List', () => {
},
},
author: {
initialView: async ( page ) => {
assertInitialState: async ( page ) => {
const author = page.getByLabel( 'Author' );
await expect( author ).toContainText( 'admin' );
},
edit: async ( page ) => {
performEdit: async ( page ) => {
const author = page.getByLabel( 'Author' );
await author.click();
const selectElement = page.locator(
'select:has(option[value="1"])'
);
await selectElement.selectOption( { value: '1' } );
},
viewAfterEdit: async () => {},
assertEditedState: async () => {},
},
date: {
initialView: async ( page ) => {
assertInitialState: async ( page ) => {
const dateEl = page.getByLabel( 'Edit Date' );
const date = new Date();
const yy = String( date.getFullYear() );

await expect( dateEl ).toContainText( yy );
},
edit: async ( page ) => {
performEdit: async ( page ) => {
const dateEl = page.getByLabel( 'Edit Date' );
await dateEl.click();
const date = new Date();
Expand All @@ -192,19 +192,19 @@ test.describe( 'Page List', () => {
await yyEl.focus();
await page.keyboard.press( 'ArrowUp' );
},
viewAfterEdit: async ( page ) => {
assertEditedState: async ( page ) => {
const date = new Date();
const yy = Number( date.getFullYear() );
const dateEl = page.getByLabel( 'Edit Date' );
await expect( dateEl ).toContainText( String( yy + 1 ) );
},
},
slug: {
initialView: async ( page ) => {
assertInitialState: async ( page ) => {
const slug = page.getByLabel( 'Edit Slug' );
await expect( slug ).toContainText( 'privacy-policy' );
},
edit: async ( page ) => {
performEdit: async ( page ) => {
const slug = page.getByLabel( 'Edit Slug' );
await slug.click();
await expect(
Expand All @@ -213,14 +213,14 @@ test.describe( 'Page List', () => {
} )
).toBeVisible();
},
viewAfterEdit: async () => {},
assertEditedState: async () => {},
},
parent: {
initialView: async ( page ) => {
assertInitialState: async ( page ) => {
const parent = page.getByLabel( 'Edit Parent' );
await expect( parent ).toContainText( 'None' );
},
edit: async ( page ) => {
performEdit: async ( page ) => {
const parent = page.getByLabel( 'Edit Parent' );
await parent.click();
await page
Expand All @@ -231,14 +231,14 @@ test.describe( 'Page List', () => {
.getByRole( 'option', { name: 'Sample Page' } )
.click();
},
viewAfterEdit: async ( page ) => {
assertEditedState: async ( page ) => {
const parent = page.getByLabel( 'Edit Parent' );
await expect( parent ).toContainText( 'Sample Page' );
},
},
// TODO: Re-enable this test once https://github.com/WordPress/gutenberg/issues/68173 is fixed
// template: {
// initialView: async ( page ) => {
// assertInitialState: async ( page ) => {
// const template = page.getByRole( 'button', {
// name: 'Single Entries',
// } );
Expand All @@ -253,16 +253,16 @@ test.describe( 'Page List', () => {
// .getByRole( 'menuitem', { name: 'Swap template' } )
// .click();
// },
// viewAfterEdit: async ( page ) => {
// assertEditedState: async ( page ) => {
//
// },
// },
discussion: {
initialView: async ( page ) => {
assertInitialState: async ( page ) => {
const discussion = page.getByLabel( 'Edit Discussion' );
await expect( discussion ).toContainText( 'Closed' );
},
edit: async ( page ) => {
performEdit: async ( page ) => {
const discussion = page.getByLabel( 'Edit Discussion' );
await discussion.click();
await page
Expand All @@ -271,7 +271,7 @@ test.describe( 'Page List', () => {
} )
.check();
},
viewAfterEdit: async ( page ) => {
assertEditedState: async ( page ) => {
const discussion = page.getByLabel( 'Edit Discussion' );
await expect( discussion ).toContainText( 'Open' );
},
Expand Down Expand Up @@ -299,15 +299,18 @@ test.describe( 'Page List', () => {
} );

Object.entries( fields ).forEach(
( [ key, { edit, initialView, viewAfterEdit } ] ) => {
( [
key,
{ performEdit, assertInitialState, assertEditedState },
] ) => {
// Asserts are done in the individual functions
// eslint-disable-next-line playwright/expect-expect
test( `should initialize, edit, and update ${ key } field correctly`, async ( {
page,
} ) => {
await initialView( page );
await edit( page );
await viewAfterEdit( page );
await assertInitialState( page );
await performEdit( page );
await assertEditedState( page );
} );
}
);
Expand All @@ -326,8 +329,8 @@ test.describe( 'Page List', () => {
await expect( status ).toBeVisible();

const { featuredImage, statusVisibility } = fields;
await statusVisibility.edit( page );
await featuredImage.edit( page );
await statusVisibility.performEdit( page );
await featuredImage.performEdit( page );
// Ensure that no dropdown is open
await page.getByRole( 'button', { name: 'Close' } ).click();
const saveButton = page.getByLabel( 'Review 1 change…' );
Expand Down

0 comments on commit cc3c2ea

Please sign in to comment.