2021-08-12 19:05:07 +09:00
|
|
|
// ***********************************************
|
|
|
|
// This example commands.js shows you how to
|
|
|
|
// create various custom commands and overwrite
|
|
|
|
// existing commands.
|
|
|
|
//
|
|
|
|
// For more comprehensive examples of custom
|
|
|
|
// commands please read more here:
|
|
|
|
// https://on.cypress.io/custom-commands
|
|
|
|
// ***********************************************
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// -- This is a parent command --
|
|
|
|
// Cypress.Commands.add('login', (email, password) => { ... })
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// -- This is a child command --
|
|
|
|
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// -- This is a dual command --
|
|
|
|
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// -- This will overwrite an existing command --
|
|
|
|
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
|
2022-05-31 17:57:01 +09:00
|
|
|
|
2023-06-06 08:40:48 +09:00
|
|
|
Cypress.Commands.add("resetState", () => {
|
|
|
|
cy.window((win) => {
|
|
|
|
win.indexedDB.deleteDatabase("keyval-store");
|
2022-05-31 17:57:01 +09:00
|
|
|
});
|
2023-06-06 08:40:48 +09:00
|
|
|
cy.request("POST", "/api/reset-db").as("reset");
|
|
|
|
cy.get("@reset").its("status").should("equal", 204);
|
2022-05-31 17:57:01 +09:00
|
|
|
cy.reload(true);
|
|
|
|
});
|
|
|
|
|
2023-06-06 08:40:48 +09:00
|
|
|
Cypress.Commands.add("registerUser", (username, password, isAdmin = false) => {
|
|
|
|
const route = isAdmin ? "/api/admin/accounts/create" : "/api/signup";
|
2022-05-31 17:57:01 +09:00
|
|
|
|
2023-06-06 08:40:48 +09:00
|
|
|
cy.request("POST", route, {
|
2022-05-31 17:57:01 +09:00
|
|
|
username: username,
|
|
|
|
password: password,
|
2023-06-06 08:40:48 +09:00
|
|
|
})
|
|
|
|
.its("body")
|
|
|
|
.as(username);
|
2022-05-31 17:57:01 +09:00
|
|
|
});
|
|
|
|
|
2023-06-06 08:40:48 +09:00
|
|
|
Cypress.Commands.add("login", (username, password) => {
|
|
|
|
cy.visit("/");
|
2022-05-31 17:57:01 +09:00
|
|
|
|
2023-06-06 08:40:48 +09:00
|
|
|
cy.intercept("POST", "/api/signin").as("signin");
|
2022-05-31 17:57:01 +09:00
|
|
|
|
2023-06-06 08:40:48 +09:00
|
|
|
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}`);
|
2022-05-31 17:57:01 +09:00
|
|
|
|
2023-06-06 08:40:48 +09:00
|
|
|
cy.wait("@signin").as("signedIn");
|
2022-05-31 17:57:01 +09:00
|
|
|
});
|