[15 Min Fix] Added the custom Cypress command, createResponseTemplate, to create comment templates. (#13167)
Co-authored-by: Suzanne Aitchison <suzanne@forem.com>
This commit is contained in:
parent
b12c6807fb
commit
d23a5a82e7
2 changed files with 33 additions and 1 deletions
|
|
@ -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<Cypress.Response>} 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}`,
|
||||
);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue