From: Lucas Di Pentima Date: Mon, 24 Feb 2020 20:35:36 +0000 (-0300) Subject: 16029: Adds first end-to-end tests for the login flow. X-Git-Tag: 2.1.0~32^2~14 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/ac975ab3e027c2b7bca986f218e6e81c45f292cb 16029: Adds first end-to-end tests for the login flow. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- diff --git a/.gitignore b/.gitignore index 45df030d..8273cc9f 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,8 @@ # testing /coverage +/cypress/videos +/cypress/screenshots # production /build diff --git a/cypress.json b/cypress.json new file mode 100644 index 00000000..e62577e6 --- /dev/null +++ b/cypress.json @@ -0,0 +1,4 @@ +{ + "baseUrl": "https://localhost:3000/", + "chromeWebSecurity": false +} diff --git a/cypress/fixtures/.gitkeep b/cypress/fixtures/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/cypress/integration/login.spec.js b/cypress/integration/login.spec.js new file mode 100644 index 00000000..1082819c --- /dev/null +++ b/cypress/integration/login.spec.js @@ -0,0 +1,50 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +describe('Login tests', function() { + before(function() { + this.email = `account_${Math.random()}@example.com` + this.password = Math.random() + this.firstName = 'Test' + this.lastName = 'User' + }) + + beforeEach(function() { + cy.visit('/') + cy.contains('Please log in') + cy.get('button').contains('Log in').click() + cy.url().should('contain', "/users/sign_in") + }) + + it('register a new user', function() { + cy.get('a[role=button]').contains('Sign up for a new account').click() + cy.url().should('contain', '/users/sign_up') + cy.get('input[name="user[first_name]"]').type(this.firstName) + cy.get('input[name="user[last_name]"]').type(this.lastName) + cy.get('input[name="user[email]"]').type(this.email) + cy.get('input[name="user[password]"]').type(this.password) + cy.get('input[name="user[password_confirmation]"]').type(this.password) + cy.get('input[type=submit]').contains('Sign up').click() + cy.url().should('contain', '/projects/') + cy.get('button[title="Account Management"]').click() + cy.get('ul[role=menu] > li[role=menuitem]').contains(`${this.firstName} ${this.lastName}`) + }) + + it('logs in successfully', function() { + cy.get('input[type=email]').type(this.email) + cy.get('input[type=password]').type(this.password) + cy.get('input[type=submit]').contains('Sign in').click() + cy.url().should('contain', '/projects/') + cy.get('button[title="Account Management"]').click() + cy.get('ul[role=menu] > li[role=menuitem]').contains(`${this.firstName} ${this.lastName}`) + }) + + it('fails to log in with incorrect password', function() { + cy.get('input[type=email]').type(this.email) + cy.get('input[type=password]').type('incorrect') + cy.get('input[type=submit]').contains('Sign in').click() + cy.url().should('contain', "/users/sign_in") + cy.get('div.alert').contains('Invalid email or password') + }) +}) \ No newline at end of file diff --git a/cypress/plugins/index.js b/cypress/plugins/index.js new file mode 100644 index 00000000..b11d5528 --- /dev/null +++ b/cypress/plugins/index.js @@ -0,0 +1,25 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +/// +// *********************************************************** +// This example plugins/index.js can be used to load plugins +// +// You can change the location of this file or turn off loading +// the plugins file with the 'pluginsFile' configuration option. +// +// You can read more here: +// https://on.cypress.io/plugins-guide +// *********************************************************** + +// This function is called when a project is opened or re-opened (e.g. due to +// the project's config changing) + +/** + * @type {Cypress.PluginConfig} + */ +module.exports = (on, config) => { + // `on` is used to hook into various events Cypress emits + // `config` is the resolved Cypress config +} diff --git a/cypress/support/commands.js b/cypress/support/commands.js new file mode 100644 index 00000000..a74cbba1 --- /dev/null +++ b/cypress/support/commands.js @@ -0,0 +1,29 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +// *********************************************** +// 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) => { ... }) diff --git a/cypress/support/index.js b/cypress/support/index.js new file mode 100644 index 00000000..0a89cb5b --- /dev/null +++ b/cypress/support/index.js @@ -0,0 +1,24 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +// *********************************************************** +// This example support/index.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') diff --git a/tsconfig.json b/tsconfig.json index b0e24552..34ee9ecd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -30,6 +30,7 @@ "acceptance-tests", "webpack", "jest", + "cypress", "src/setupTests.ts", "**/*.test.tsx" ]