pvtchat/frontend/e2e/support/commands.ts
2021-11-10 19:22:04 +00:00

33 lines
961 B
TypeScript

import { Chance } from 'chance';
const chance = new Chance();
const url = `${Cypress.env('URL')}:${Cypress.env('PORT')}`;
let token: string;
Cypress.Commands.add('register', (email = chance.email(), password = chance.string()) => {
cy.visit(url);
cy.get('a[href*="/login"]').first().click();
cy.contains('Register').click();
cy.get('input[name=email]').type(email);
cy.get('input[name=username]').type(chance.name());
cy.get('input[name=password]').type(password);
cy.contains('Register').click();
cy.wait(2000);
cy.url()
.should('equal', `${url}/channels/@me`)
.then(() => token = localStorage.getItem('token')!);
});
Cypress.Commands.add('createGuild', () => {
cy.visit(url + '/channels/@me');
cy.get('#createGuildButton').click();
cy.get('input[name=name]').type(chance.tv());
cy.get('button').contains('Create').click();
cy.wait(1000);
});
Cypress.Commands.add('logout', () => cy.visit(url + '/logout'));
export {}