129 lines
3.3 KiB
JavaScript
129 lines
3.3 KiB
JavaScript
// ***********************************************
|
|
// 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 is will overwrite an existing command --
|
|
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
|
|
|
|
import 'cypress-graphql-mock';
|
|
|
|
Cypress.Commands.add('apolloLogin', (username, password) => {
|
|
const payload = {
|
|
'operationName': 'Login',
|
|
'variables': {
|
|
'input': {
|
|
'usernameInput': username,
|
|
'passwordInput': password
|
|
}
|
|
},
|
|
'query': 'mutation Login($input: LoginInput!) {\n login(input: $input) {\n success\n errors {\n field\n __typename\n }\n __typename\n }\n}\n'
|
|
};
|
|
|
|
cy.request({
|
|
method: 'POST',
|
|
url: '/api/graphql-public/',
|
|
body: payload
|
|
});
|
|
|
|
|
|
});
|
|
|
|
// todo: replace with apollo call
|
|
Cypress.Commands.add("login", (username, password, visitLogin = false) => {
|
|
if (visitLogin) {
|
|
cy.visit('/login');
|
|
}
|
|
|
|
if (username != '') {
|
|
cy.get('[data-cy=email-input]').type(username);
|
|
}
|
|
|
|
if (password != '') {
|
|
cy.get('[data-cy=password-input]').type(password);
|
|
}
|
|
cy.get('[data-cy=login-button]').click();
|
|
});
|
|
|
|
Cypress.Commands.add("logout", () => {
|
|
cy.get('[data-cy=user-icon]').click();
|
|
cy.get('[data-cy=logout]').click();
|
|
});
|
|
|
|
Cypress.Commands.add('loginByCsrf', (username, password, csrftoken) => {
|
|
cy.request({
|
|
method: 'POST',
|
|
url: '/accounts/login/',
|
|
failOnStatusCode: false,
|
|
form: true,
|
|
body: {
|
|
username: username,
|
|
password: password,
|
|
csrfmiddlewaretoken: csrftoken
|
|
}
|
|
});
|
|
});
|
|
|
|
Cypress.Commands.add('startGraphQLCapture', () => {
|
|
cy.server();
|
|
cy.route('POST', '/api/graphql/').as('graphQL');
|
|
});
|
|
|
|
// from https://stackoverflow.com/questions/53814647/how-can-i-alias-specific-graphql-requests-in-cypress
|
|
Cypress.Commands.add('waitFor', operationName => {
|
|
cy.wait('@graphQL').then(({request}) => {
|
|
if (request.body.operationName !== operationName) {
|
|
return cy.waitFor(operationName);
|
|
}
|
|
});
|
|
});
|
|
|
|
Cypress.Commands.add('changePassword', (oldPassword, newPassword) => {
|
|
if (oldPassword) {
|
|
cy.get('[data-cy=old-password]').type(oldPassword);
|
|
}
|
|
|
|
if (newPassword) {
|
|
cy.get('[data-cy=new-password]').type(newPassword);
|
|
}
|
|
cy.get('[data-cy=change-password-button]').click();
|
|
});
|
|
|
|
Cypress.Commands.add('register', (firstname, lastname, email, licenseKey) => {
|
|
if (firstname != '') {
|
|
cy.get('[data-cy=firstname-input]').type(firstname);
|
|
}
|
|
|
|
if (lastname != '') {
|
|
cy.get('[data-cy=lastname-input]').type(lastname);
|
|
}
|
|
|
|
if (email != '') {
|
|
cy.get('[data-cy=email-input]').type(email);
|
|
}
|
|
|
|
if (licenseKey != '') {
|
|
cy.get('[data-cy=licenseKey-input]').type(licenseKey);
|
|
}
|
|
|
|
cy.get('[data-cy=register-button]').click();
|
|
});
|