16029: Adds first end-to-end tests for the login flow.
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Mon, 24 Feb 2020 20:35:36 +0000 (17:35 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Mon, 24 Feb 2020 20:35:36 +0000 (17:35 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

.gitignore
cypress.json [new file with mode: 0644]
cypress/fixtures/.gitkeep [new file with mode: 0644]
cypress/integration/login.spec.js [new file with mode: 0644]
cypress/plugins/index.js [new file with mode: 0644]
cypress/support/commands.js [new file with mode: 0644]
cypress/support/index.js [new file with mode: 0644]
tsconfig.json

index 45df030d3294be423b92aa8d9f355b00a7f7a34a..8273cc9ff63fcd5a971535902e4923b5f795b44c 100644 (file)
@@ -12,6 +12,8 @@
 
 # testing
 /coverage
+/cypress/videos
+/cypress/screenshots
 
 # production
 /build
diff --git a/cypress.json b/cypress.json
new file mode 100644 (file)
index 0000000..e62577e
--- /dev/null
@@ -0,0 +1,4 @@
+{
+    "baseUrl": "https://localhost:3000/",
+    "chromeWebSecurity": false
+}
diff --git a/cypress/fixtures/.gitkeep b/cypress/fixtures/.gitkeep
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/cypress/integration/login.spec.js b/cypress/integration/login.spec.js
new file mode 100644 (file)
index 0000000..1082819
--- /dev/null
@@ -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 (file)
index 0000000..b11d552
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+/// <reference types="cypress" />
+// ***********************************************************
+// 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 (file)
index 0000000..a74cbba
--- /dev/null
@@ -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 (file)
index 0000000..0a89cb5
--- /dev/null
@@ -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')
index b0e2455281bd09f74171637f30e6e7b22b351319..34ee9ecdaf1555768ca910190a95f9e6a39f66da 100644 (file)
@@ -30,6 +30,7 @@
     "acceptance-tests",
     "webpack",
     "jest",
+    "cypress",
     "src/setupTests.ts",
     "**/*.test.tsx"
   ]