Skip to content

Commit

Permalink
Build: (ce294ae) Merge pull request #28 from 10up/command/createPost
Browse files Browse the repository at this point in the history
Added createPost command.
  • Loading branch information
cadic committed Mar 25, 2022
1 parent d7ba3a0 commit 339bdc8
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 0 deletions.
45 changes: 45 additions & 0 deletions lib/commands/create-post.d.ts
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;
71 changes: 71 additions & 0 deletions lib/commands/create-post.js
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;
2 changes: 2 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { deleteAllTerms } from './commands/delete-all-terms';
import { createTerm } from './commands/create-term';
import { logout } from './commands/logout';
import { login } from './commands/login';
import { createPost } from './commands/create-post';
declare global {
namespace Cypress {
interface Chainable<Subject> {
Expand All @@ -25,6 +26,7 @@ declare global {
openDocumentSettingsSidebar: typeof openDocumentSettingsSidebar;
deleteAllTerms: typeof deleteAllTerms;
createTerm: typeof createTerm;
createPost: typeof createPost;
logout: typeof logout;
login: typeof login;
}
Expand Down
2 changes: 2 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const delete_all_terms_1 = require("./commands/delete-all-terms");
const create_term_1 = require("./commands/create-term");
const logout_1 = require("./commands/logout");
const login_1 = require("./commands/login");
const create_post_1 = require("./commands/create-post");
// Register commands
Cypress.Commands.add('wpCliEval', wp_cli_eval_1.wpCliEval);
Cypress.Commands.add('wpCli', wp_cli_1.wpCli);
Expand All @@ -28,5 +29,6 @@ Cypress.Commands.add('openDocumentSettingsPanel', open_document_settings_panel_1
Cypress.Commands.add('openDocumentSettingsSidebar', open_document_settings_sidebar_1.openDocumentSettingsSidebar);
Cypress.Commands.add('deleteAllTerms', delete_all_terms_1.deleteAllTerms);
Cypress.Commands.add('createTerm', create_term_1.createTerm);
Cypress.Commands.add('createPost', create_post_1.createPost);
Cypress.Commands.add('logout', logout_1.logout);
Cypress.Commands.add('login', login_1.login);

0 comments on commit 339bdc8

Please sign in to comment.