-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Added createPost command.
- Loading branch information
Showing
4 changed files
with
120 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,45 @@ | ||
/** | ||
* Create a Post | ||
* | ||
* @param postData { | ||
* `postType` - Post type, | ||
* `title` - Post Title, | ||
* `content` - Post Content, | ||
* `status` - Post Status | ||
* } | ||
* | ||
* @example | ||
* Create a Post | ||
* ``` | ||
* cy.createPost({ | ||
* title: 'Test Post', | ||
* content: 'Test Content' | ||
* }) | ||
* ``` | ||
* | ||
* @example | ||
* Create a Post with draft status. | ||
* ``` | ||
* cy.createPost({ | ||
* title: 'Test Post', | ||
* content: 'Test Content', | ||
* status: 'draft' | ||
* }) | ||
* ``` | ||
* | ||
* @example | ||
* Create a Page | ||
* ``` | ||
* cy.createPost({ | ||
* postType: 'page' | ||
* title: 'Test page', | ||
* content: 'Page Content' | ||
* }) | ||
* ``` | ||
*/ | ||
export declare const createPost: ({ postType, title, content, status, }: { | ||
title: string; | ||
postType?: string | undefined; | ||
content?: string | undefined; | ||
status?: string | undefined; | ||
}) => void; |
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,71 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createPost = void 0; | ||
/** | ||
* Create a Post | ||
* | ||
* @param postData { | ||
* `postType` - Post type, | ||
* `title` - Post Title, | ||
* `content` - Post Content, | ||
* `status` - Post Status | ||
* } | ||
* | ||
* @example | ||
* Create a Post | ||
* ``` | ||
* cy.createPost({ | ||
* title: 'Test Post', | ||
* content: 'Test Content' | ||
* }) | ||
* ``` | ||
* | ||
* @example | ||
* Create a Post with draft status. | ||
* ``` | ||
* cy.createPost({ | ||
* title: 'Test Post', | ||
* content: 'Test Content', | ||
* status: 'draft' | ||
* }) | ||
* ``` | ||
* | ||
* @example | ||
* Create a Page | ||
* ``` | ||
* cy.createPost({ | ||
* postType: 'page' | ||
* title: 'Test page', | ||
* content: 'Page Content' | ||
* }) | ||
* ``` | ||
*/ | ||
const createPost = ({ postType = 'post', title = 'Test Post', content = 'Test content', status = 'publish', }) => { | ||
cy.visit(`/wp-admin/post-new.php?post_type=${postType}`); | ||
const titleInput = 'h1.editor-post-title__input, #post-title-0'; | ||
const contentInput = '.block-editor-default-block-appender__content'; | ||
const welcomeGuide = '.edit-post-welcome-guide .components-modal__header button'; | ||
// Make sure editor loaded properly. | ||
cy.get(titleInput).should('exist'); | ||
// Close Welcome Guide. | ||
cy.get('body').then($body => { | ||
if ($body.find(welcomeGuide).length > 0) { | ||
cy.get(welcomeGuide).click(); | ||
} | ||
}); | ||
// Fill out data. | ||
cy.get(titleInput).clear().type(title); | ||
cy.get(contentInput).type(content); | ||
// Save/Publish Post. | ||
if (status === 'draft') { | ||
cy.get('.editor-post-save-draft').click(); | ||
cy.get('.editor-post-saved-state').should('have.text', 'Saved'); | ||
} | ||
else { | ||
cy.get('.editor-post-publish-panel__toggle').should('be.enabled'); | ||
cy.get('.editor-post-publish-panel__toggle').click(); | ||
cy.get('.editor-post-publish-button').click(); | ||
cy.get('.components-snackbar').should('be.visible'); | ||
} | ||
}; | ||
exports.createPost = createPost; |
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