Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Add tests #182

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ const { defineConfig } = require('cypress');

module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
}
baseUrl: 'https://conduit.mate.academy/',
setupNodeEvents(on, config) {}
}
});
13 changes: 13 additions & 0 deletions cypress/e2e/signUp.cy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
/// <reference types='cypress' />
import { generateUser } from '../support/generate';

describe('Sign Up page', () => {
const { username, email, password } = generateUser();

it('should provide an ability to register new account', () => {
cy.visit('/user/register');

cy.getByPlaceholder('Username', username);
cy.getByPlaceholder('Email', email);
cy.getByPlaceholder('Password', password);
cy.get('button[type="submit"]').click();
cy.get('a[class=nav-link]')
.contains(username.toLowerCase())
.should('be.visible');
});
});
30 changes: 5 additions & 25 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
// ***********************************************
// 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) => { ... })
/// <reference types='cypress' />

Cypress.Commands.add('getByPlaceholder', (placeholder, value) => {
cy.get(`input[placeholder="${placeholder}"]`).type(value);
});
20 changes: 1 addition & 19 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,2 @@
// ***********************************************************
// This example support/e2e.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands';

// Alternatively you can use CommonJS syntax:
// require('./commands')
import './generate';
12 changes: 12 additions & 0 deletions cypress/support/generate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { faker } from '@faker-js/faker';

function generateUser() {
const randomNumber = Math.random().toString().slice(2, 6);
const username = faker.internet.userName() + '_' + randomNumber;
const email = `${username}@mail.com`;
const password = '12345Qwert!';

return { email, password, username };
}

module.exports = { generateUser };
Loading