From d23a5a82e7cf020534dd86a68488f0af8a0b1c23 Mon Sep 17 00:00:00 2001 From: Nick Taylor Date: Mon, 29 Mar 2021 12:39:45 -0400 Subject: [PATCH] [15 Min Fix] Added the custom Cypress command, createResponseTemplate, to create comment templates. (#13167) Co-authored-by: Suzanne Aitchison --- cypress/support/commands.js | 19 +++++++++++++++++++ docs/tests/e2e-tests.md | 15 ++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 17c7f0689..18333a8b7 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -196,3 +196,22 @@ Cypress.Commands.add( }); }, ); + +/** + * Creates a response template. + * + * @param {string} title The title of a response template. + * @param {string} content The content of the response template. + * + * @returns {Cypress.Chainable} A cypress request for creating a response template. + */ +Cypress.Commands.add('createResponseTemplate', ({ title, content }) => { + const encodedTitle = encodeURIComponent(title); + const encodedContent = encodeURIComponent(content); + + return cy.request( + 'POST', + '/response_templates', + `utf8=%E2%9C%93&response_template%5Btitle%5D=${encodedTitle}&response_template%5Bcontent%5D=${encodedContent}`, + ); +}); diff --git a/docs/tests/e2e-tests.md b/docs/tests/e2e-tests.md index 6ce3a52c4..7b96d7df2 100644 --- a/docs/tests/e2e-tests.md +++ b/docs/tests/e2e-tests.md @@ -116,7 +116,8 @@ of Forem, we need custom commands to create an article, for example. A custom command is prefixed like any Cypress command by `cy.` All custom commands can be found in the -[commands.js](https://github.com/forem/forem/blob/master/cypress/support/commands.js) file. +[commands.js](https://github.com/forem/forem/blob/master/cypress/support/commands.js) +file. ### Creating a Custom Article Command @@ -144,6 +145,18 @@ cy.createArticle({ }); ``` +### Creating a Response Template Command + +To create a response template as part of your test's setup, use the +`cy.createResponseTemplate` custom command. It can be called like so: + +```javascript +cy.createResponseTemplate({ + title: 'Test Canned Response', + content: 'This is a test canned response', +}); +``` + ## Additional Resources - [Cypress documentation](https://docs.cypress.io)