summaryrefslogtreecommitdiff
path: root/cypress/support
diff options
context:
space:
mode:
authorAndreas Nedbal <github-bf215181b5140522137b3d4f6b73544a@desu.email>2022-05-31 10:57:01 +0200
committerGitHub <noreply@github.com>2022-05-31 17:57:01 +0900
commitd3e242a7f25e72bd65f27feebd878f5a45e7ae3b (patch)
tree1f35d1ff5760145fd10bae755216f658a72b3a08 /cypress/support
parentFix `Cannot find module` issue (#8770) (diff)
downloadsharkey-d3e242a7f25e72bd65f27feebd878f5a45e7ae3b.tar.gz
sharkey-d3e242a7f25e72bd65f27feebd878f5a45e7ae3b.tar.bz2
sharkey-d3e242a7f25e72bd65f27feebd878f5a45e7ae3b.zip
Extract commonly used test logic to commands (#8767)
* meta(tests): enable workflows to run in branch * feat(tests): move commonly used logic to Cypress commands * chore(tests): replace more code with commands * meta(tests): disable workflows to run in branch
Diffstat (limited to 'cypress/support')
-rw-r--r--cypress/support/commands.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/cypress/support/commands.js b/cypress/support/commands.js
index 119ab03f7c..95bfcf6855 100644
--- a/cypress/support/commands.js
+++ b/cypress/support/commands.js
@@ -23,3 +23,33 @@
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
+
+Cypress.Commands.add('resetState', () => {
+ cy.window(win => {
+ win.indexedDB.deleteDatabase('keyval-store');
+ });
+ cy.request('POST', '/api/reset-db').as('reset');
+ cy.get('@reset').its('status').should('equal', 204);
+ cy.reload(true);
+});
+
+Cypress.Commands.add('registerUser', (username, password, isAdmin = false) => {
+ const route = isAdmin ? '/api/admin/accounts/create' : '/api/signup';
+
+ cy.request('POST', route, {
+ username: username,
+ password: password,
+ }).its('body').as(username);
+});
+
+Cypress.Commands.add('login', (username, password) => {
+ cy.visit('/');
+
+ cy.intercept('POST', '/api/signin').as('signin');
+
+ cy.get('[data-cy-signin]').click();
+ cy.get('[data-cy-signin-username] input').type(username);
+ cy.get('[data-cy-signin-password] input').type(`${password}{enter}`);
+
+ cy.wait('@signin').as('signedIn');
+});