-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Page model for isolated test cases
- Loading branch information
Showing
1 changed file
with
124 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import { Selector, t } from 'testcafe'; | ||
import { link } from '../utilities/page-model/helpers/field'; | ||
|
||
class Page { | ||
constructor( name ) { | ||
this.pageName = name; | ||
this.sortDateColumn = Selector( 'th#date' ); | ||
this.addNewPageLink = link( '.wrap', 'Add New Page' ); | ||
this.trashLink = Selector( 'a' ).withAttribute( | ||
'aria-label', | ||
`Move “${ name }” to the Trash` | ||
); | ||
this.closePopupButton = Selector( 'button' ).withAttribute( | ||
'aria-label', | ||
'Close dialog' | ||
); | ||
this.closePopupPattern = Selector( 'button' ).withAttribute( | ||
'aria-label', | ||
'Close' | ||
); | ||
this.titleField = Selector( '.editor-post-title__input' ); | ||
this.addBlockToolbarIcon = Selector( | ||
'button.editor-document-tools__inserter-toggle' | ||
); | ||
this.searchBlock = Selector( '.block-editor-inserter__search' ) | ||
.find( 'input' ) | ||
.withAttribute( 'type', 'search' ); | ||
this.searchResults = Selector( '.block-editor-block-types-list' ); | ||
this.documentPanel = Selector( 'div.editor-sidebar' ); | ||
this.documentPanelToolbarButton = Selector( | ||
'button.components-button' | ||
).withAttribute( 'aria-label', 'Settings' ); | ||
this.documentPanelCloseButton = Selector( | ||
'button.components-button' | ||
).withAttribute( 'aria-label', 'Close panel' ); | ||
this.publishToolbarButton = Selector( | ||
'.editor-post-publish-button__button' | ||
); | ||
this.confirmPublishButton = Selector( | ||
'.editor-post-publish-panel__header-publish-button button' | ||
).withText( 'Publish' ); | ||
this.trashButton = Selector( 'button.editor-post-trash' ).withText( | ||
'Move to trash' | ||
); | ||
} | ||
|
||
/** | ||
* Creates a new page on this instance. | ||
* Must only be used once per instance to prevent anomalies | ||
* | ||
* @return {Promise<void>} none | ||
*/ | ||
async add() { | ||
await t.click( this.addNewPageLink ); | ||
|
||
if ( await this.closePopupButton.exists ) { | ||
await t.click( this.closePopupButton ); | ||
} | ||
|
||
if ( await this.closePopupPattern.exists ) { | ||
await t.click( this.closePopupPattern ); | ||
} | ||
|
||
await t.typeText( this.titleField, this.pageName, { paste: true } ); | ||
} | ||
|
||
/** | ||
* Deletes the page of this instance | ||
* | ||
* @return {Promise<void>} none | ||
*/ | ||
async delete() { | ||
if ( ! ( await this.documentPanel.exists ) ) { | ||
await t.click( this.documentPanelToolbarButton ); | ||
} | ||
|
||
await t.click( this.trashButton ).pressKey( 'enter' ); | ||
} | ||
|
||
/** | ||
* Inserts a block on this page instance | ||
* | ||
* @param { string } block name i.e paragraph, shortcode | ||
* @param { { | ||
* target: string | ||
* content: string | ||
* }= } node content of the block to be added | ||
* | ||
* @return {Promise<void>} none | ||
*/ | ||
async insertBlock( block, node ) { | ||
await t | ||
.click( this.addBlockToolbarIcon ) | ||
.typeText( this.searchBlock.filterVisible(), block, { | ||
paste: true, | ||
} ); | ||
|
||
const resultBlock = this.searchResults.find( 'button' ); | ||
|
||
await t.click( resultBlock ); | ||
|
||
if ( node?.content ) { | ||
await t.typeText( Selector( node.target ), node.content ); | ||
} | ||
} | ||
|
||
/** | ||
* Saves content added to the page | ||
* | ||
* @return {Promise<void>} none | ||
*/ | ||
async saveChanges() { | ||
await t.click( this.publishToolbarButton ); | ||
} | ||
|
||
async publishChanges() { | ||
await t | ||
.click( this.publishToolbarButton ) | ||
.click( this.confirmPublishButton ) | ||
.click( this.documentPanelCloseButton ); | ||
} | ||
} | ||
|
||
export default Page; |