From 25bfbaabf2592fb62038c901e4a84a96d330c46e Mon Sep 17 00:00:00 2001 From: sendilkumarn Date: Fri, 19 Jun 2020 23:39:58 +0200 Subject: [PATCH 001/116] feat: add cypress initial commit --- generators/app/prompts.js | 1 + generators/client/files-angular.js | 17 ++++++ generators/client/files-react.js | 17 ++++++ .../client/templates/angular/cypress.json.ejs | 3 + .../account/login_page_spec.js.ejs | 44 ++++++++++++++ .../account/register_page_spec.js.ejs | 47 +++++++++++++++ .../administration/administration_spec.js.ejs | 58 +++++++++++++++++++ .../angular/cypress/plugins/index.js.ejs | 22 +++++++ .../angular/cypress/support/commands.js.ejs | 34 +++++++++++ .../angular/cypress/support/index.js.ejs | 17 ++++++ .../client/templates/react/cypress.json.ejs | 3 + .../account/login_page_spec.js.ejs | 44 ++++++++++++++ .../account/register_page_spec.js.ejs | 47 +++++++++++++++ .../administration/administration_spec.js.ejs | 58 +++++++++++++++++++ .../react/cypress/plugins/index.js.ejs | 22 +++++++ .../react/cypress/support/commands.js.ejs | 34 +++++++++++ .../react/cypress/support/index.js.ejs | 17 ++++++ .../client/templates/react/package.json.ejs | 6 ++ 18 files changed, 491 insertions(+) create mode 100644 generators/client/templates/angular/cypress.json.ejs create mode 100644 generators/client/templates/angular/cypress/integration/account/login_page_spec.js.ejs create mode 100644 generators/client/templates/angular/cypress/integration/account/register_page_spec.js.ejs create mode 100644 generators/client/templates/angular/cypress/integration/administration/administration_spec.js.ejs create mode 100644 generators/client/templates/angular/cypress/plugins/index.js.ejs create mode 100644 generators/client/templates/angular/cypress/support/commands.js.ejs create mode 100644 generators/client/templates/angular/cypress/support/index.js.ejs create mode 100644 generators/client/templates/react/cypress.json.ejs create mode 100644 generators/client/templates/react/cypress/integration/account/login_page_spec.js.ejs create mode 100644 generators/client/templates/react/cypress/integration/account/register_page_spec.js.ejs create mode 100644 generators/client/templates/react/cypress/integration/administration/administration_spec.js.ejs create mode 100644 generators/client/templates/react/cypress/plugins/index.js.ejs create mode 100644 generators/client/templates/react/cypress/support/commands.js.ejs create mode 100644 generators/client/templates/react/cypress/support/index.js.ejs diff --git a/generators/app/prompts.js b/generators/app/prompts.js index c791119f0157..7a9b187a8418 100644 --- a/generators/app/prompts.js +++ b/generators/app/prompts.js @@ -100,6 +100,7 @@ async function askForTestOpts() { if (!this.skipClient) { // all client side test frameworks should be added here choices.push({ name: 'Protractor', value: 'protractor' }); + choices.push({ name: 'Cypress **In Developement**', value: 'cypress' }); } const PROMPT = { type: 'checkbox', diff --git a/generators/client/files-angular.js b/generators/client/files-angular.js index e1abd4b1adbc..5f8b49b16ece 100644 --- a/generators/client/files-angular.js +++ b/generators/client/files-angular.js @@ -23,6 +23,7 @@ const constants = require('../generator-constants'); const MAIN_SRC_DIR = constants.CLIENT_MAIN_SRC_DIR; const TEST_SRC_DIR = constants.CLIENT_TEST_SRC_DIR; const ANGULAR_DIR = constants.ANGULAR_DIR; +const CYPRESS_DIR = 'cypress/'; /** * The default is to use a file path string. It implies use of the template method. @@ -486,6 +487,22 @@ const files = { condition: generator => generator.protractorTests, templates: ['tsconfig.e2e.json'], }, + { + condition: generator => generator.cypressTests, + path: CYPRESS_DIR, + templates: [ + 'integration/account/login_page_spec.js', + 'integration/account/register_page_spec.js', + 'integration/administration/administration_spec.js', + 'plugins/index.js', + 'support/index.js', + 'support/commands.js', + ], + }, + { + condition: generator => generator.cypressTests, + templates: ['cypress.json'], + }, ], }; diff --git a/generators/client/files-react.js b/generators/client/files-react.js index 3b82c173ce90..5f27485d54bd 100644 --- a/generators/client/files-react.js +++ b/generators/client/files-react.js @@ -23,6 +23,7 @@ const constants = require('../generator-constants'); const MAIN_SRC_DIR = constants.CLIENT_MAIN_SRC_DIR; const TEST_SRC_DIR = constants.CLIENT_TEST_SRC_DIR; const REACT_DIR = constants.ANGULAR_DIR; +const CYPRESS_DIR = 'cypress/'; /** * The default is to use a file path string. It implies use of the template method. @@ -391,6 +392,22 @@ const files = { path: TEST_SRC_DIR, templates: ['e2e/page-objects/password-page.ts', 'e2e/page-objects/settings-page.ts', 'e2e/page-objects/register-page.ts'], }, + { + condition: generator => generator.cypressTests, + path: CYPRESS_DIR, + templates: [ + 'integration/account/login_page_spec.js', + 'integration/account/register_page_spec.js', + 'integration/administration/administration_spec.js', + 'plugins/index.js', + 'support/index.js', + 'support/commands.js', + ], + }, + { + condition: generator => generator.cypressTests, + templates: ['cypress.json'], + }, ], }; diff --git a/generators/client/templates/angular/cypress.json.ejs b/generators/client/templates/angular/cypress.json.ejs new file mode 100644 index 000000000000..489903c79de8 --- /dev/null +++ b/generators/client/templates/angular/cypress.json.ejs @@ -0,0 +1,3 @@ +{ + "baseUrl": "http://localhost:8080" +} \ No newline at end of file diff --git a/generators/client/templates/angular/cypress/integration/account/login_page_spec.js.ejs b/generators/client/templates/angular/cypress/integration/account/login_page_spec.js.ejs new file mode 100644 index 000000000000..03c2b05cb344 --- /dev/null +++ b/generators/client/templates/angular/cypress/integration/account/login_page_spec.js.ejs @@ -0,0 +1,44 @@ +describe('/login', () => { + + beforeEach(() => { + cy.visit('/login'); + }) + + it('greets with signin', () => { + // TODO add translation support here. + cy.contains('h5', 'Sign in'); + }); + + it('links to /register', () => { + cy.contains('Register a new account') + .should('have.attr', 'href', '/account/register'); + }); + + it('links to /account/reset/password', () => { + cy.contains('Did you forget your password?') + .should('have.attr', 'href', '/account/reset/request'); + }); + + it('requires username', () => { + cy.get('button').contains('Sign in').click(); + cy.get('#username').should('have.class', 'is-invalid'); + }); + + it('requires password', () => { + cy.login('admin', ''); + cy.get('#username').should('not.have.class', 'is-invalid'); + cy.get('#password').should('have.class', 'is-invalid'); + cy.get('.alert-danger').contains('Failed to sign in!'); + }); + + it('errors when password is incorrect', () => { + cy.login('admin', 'bad-password'); + // TODO add translation support here. + cy.get('.alert-danger').contains('Failed to sign in!'); + }); + + it('go to login page when successfully logs in', () => { + cy.login('admin', 'admin'); + cy.logout(); + }); +}); \ No newline at end of file diff --git a/generators/client/templates/angular/cypress/integration/account/register_page_spec.js.ejs b/generators/client/templates/angular/cypress/integration/account/register_page_spec.js.ejs new file mode 100644 index 000000000000..755fdac34beb --- /dev/null +++ b/generators/client/templates/angular/cypress/integration/account/register_page_spec.js.ejs @@ -0,0 +1,47 @@ +describe('/account/register', () => { + beforeEach(() => { + cy.server(); + cy.route('POST', '/api/register').as('registerSave') + }); + + it('should load the register page', () => { + cy.visit('/account/register'); + // TODO add translation support here. + cy.contains('h1', 'Registration'); + }); + + it('requires username', () => { + cy.register('', 'someemail@example.com', 'password', 'password'); + cy.get('#username').should('have.class', 'is-invalid'); + }); + + it('requires email', () => { + cy.register('admin', '', 'password', 'password'); + cy.get('#email').should('have.class', 'is-invalid'); + }); + + it('requires email in correct format', () => { + cy.register('admin', 'someemail', 'password', 'password'); + cy.get('#email').should('have.class', 'is-invalid'); + }); + + it('requires confirm password', () => { + cy.register('admin', 'someemail@example.com', 'password', ''); + cy.get('#secondPassword').should('have.class', 'is-invalid'); + }); + + it('requires password and confirm password to be same', () => { + cy.register('admin', 'someemail@example.com', 'password', 'different-password'); + cy.get('#secondPassword').should('have.class', 'is-invalid'); + }); + + it('register a valid user', () => { + cy.register('new-user', 'new-user@example.com', 'password', 'password'); + cy.wait('@registerSave').its('status').should('equal', 201); + }); + + it('error for existing user', () => { + cy.register('admin', 'admin@localhost.com', 'password', 'password'); + cy.wait('@registerSave').its('status').should('equal', 400); + }); +}); \ No newline at end of file diff --git a/generators/client/templates/angular/cypress/integration/administration/administration_spec.js.ejs b/generators/client/templates/angular/cypress/integration/administration/administration_spec.js.ejs new file mode 100644 index 000000000000..0258e2230c90 --- /dev/null +++ b/generators/client/templates/angular/cypress/integration/administration/administration_spec.js.ejs @@ -0,0 +1,58 @@ +<%# Add OAuth2 login feature %> +describe('/admin', () => { + + before(() => { + cy.login(); + }); + + after(() => { + cy.logout(); + }); +<%_ if (!skipUserManagement) { _%> + describe('/user-management', () => { + it('should load the page', () => { + cy.visit('/admin/user-management'); + cy.contains('#user-management-page-heading', 'Users'); + }); + }); +<%_ } _%> + + describe('/metrics', () => { + it('should load the page', () => { + cy.visit('/admin/metrics'); + cy.contains('#metrics-page-heading', 'Application Metrics'); + }); + }); + + + describe('/health', () => { + it('should load the page', () => { + cy.visit('/admin/health'); + cy.contains('#health-page-heading', 'Health Checks'); + }); + }); + +<%_ if ((databaseType !== 'no' || authenticationType === 'uaa') && databaseType !== 'cassandra') { _%> + describe('/audits', () => { + it('should load the page', () => { + cy.visit('/admin/audits'); + cy.contains('#audits-page-heading', 'Audits'); + }); + }); +<%_ } _%> + + describe('/logs', () => { + it('should load the page', () => { + cy.visit('/admin/logs'); + cy.contains('#logs-page-heading', 'Logs'); + }); + }); + + describe('/configuration', () => { + it('should load the page', () => { + cy.visit('/admin/configuration'); + cy.contains('#configuration-page-heading', 'Configuration'); + }); + }); + +}); diff --git a/generators/client/templates/angular/cypress/plugins/index.js.ejs b/generators/client/templates/angular/cypress/plugins/index.js.ejs new file mode 100644 index 000000000000..f3d14f989cc8 --- /dev/null +++ b/generators/client/templates/angular/cypress/plugins/index.js.ejs @@ -0,0 +1,22 @@ +/// +// *********************************************************** +// 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 +} + \ No newline at end of file diff --git a/generators/client/templates/angular/cypress/support/commands.js.ejs b/generators/client/templates/angular/cypress/support/commands.js.ejs new file mode 100644 index 000000000000..71297481fda1 --- /dev/null +++ b/generators/client/templates/angular/cypress/support/commands.js.ejs @@ -0,0 +1,34 @@ +// *********************************************** +// This 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 +// *********************************************** + +const isNotEmpty = (str) => str && str !== ''; + +Cypress.Commands.add("login", (email = "admin", password="admin") => { + cy.visit('/login'); + cy.get('#username').type(email); + cy.get('#password').type(password); + cy.get('button[type="submit"]').click(); + cy.hash().should('eq', ''); + cy.contains(`You are logged in as user "${email}".`) +}); + +Cypress.Commands.add("logout", () => { + cy.get('#account-menu').click(); + cy.get('a[href="/logout"]').click(); +}); + +Cypress.Commands.add("register", (username, email, password, confirmPassword) => { + cy.visit('/account/register'); + if(isNotEmpty(username)) cy.get('#username').type(username); + if(isNotEmpty(email)) cy.get('#email').type(email); + if(isNotEmpty(password)) cy.get('#firstPassword').type(password); + if(isNotEmpty(confirmPassword)) cy.get('#secondPassword').type(confirmPassword); + cy.get('button[type="submit"]').click(); +}); diff --git a/generators/client/templates/angular/cypress/support/index.js.ejs b/generators/client/templates/angular/cypress/support/index.js.ejs new file mode 100644 index 000000000000..498559a471fa --- /dev/null +++ b/generators/client/templates/angular/cypress/support/index.js.ejs @@ -0,0 +1,17 @@ +// *********************************************************** +// This 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'; \ No newline at end of file diff --git a/generators/client/templates/react/cypress.json.ejs b/generators/client/templates/react/cypress.json.ejs new file mode 100644 index 000000000000..489903c79de8 --- /dev/null +++ b/generators/client/templates/react/cypress.json.ejs @@ -0,0 +1,3 @@ +{ + "baseUrl": "http://localhost:8080" +} \ No newline at end of file diff --git a/generators/client/templates/react/cypress/integration/account/login_page_spec.js.ejs b/generators/client/templates/react/cypress/integration/account/login_page_spec.js.ejs new file mode 100644 index 000000000000..03c2b05cb344 --- /dev/null +++ b/generators/client/templates/react/cypress/integration/account/login_page_spec.js.ejs @@ -0,0 +1,44 @@ +describe('/login', () => { + + beforeEach(() => { + cy.visit('/login'); + }) + + it('greets with signin', () => { + // TODO add translation support here. + cy.contains('h5', 'Sign in'); + }); + + it('links to /register', () => { + cy.contains('Register a new account') + .should('have.attr', 'href', '/account/register'); + }); + + it('links to /account/reset/password', () => { + cy.contains('Did you forget your password?') + .should('have.attr', 'href', '/account/reset/request'); + }); + + it('requires username', () => { + cy.get('button').contains('Sign in').click(); + cy.get('#username').should('have.class', 'is-invalid'); + }); + + it('requires password', () => { + cy.login('admin', ''); + cy.get('#username').should('not.have.class', 'is-invalid'); + cy.get('#password').should('have.class', 'is-invalid'); + cy.get('.alert-danger').contains('Failed to sign in!'); + }); + + it('errors when password is incorrect', () => { + cy.login('admin', 'bad-password'); + // TODO add translation support here. + cy.get('.alert-danger').contains('Failed to sign in!'); + }); + + it('go to login page when successfully logs in', () => { + cy.login('admin', 'admin'); + cy.logout(); + }); +}); \ No newline at end of file diff --git a/generators/client/templates/react/cypress/integration/account/register_page_spec.js.ejs b/generators/client/templates/react/cypress/integration/account/register_page_spec.js.ejs new file mode 100644 index 000000000000..755fdac34beb --- /dev/null +++ b/generators/client/templates/react/cypress/integration/account/register_page_spec.js.ejs @@ -0,0 +1,47 @@ +describe('/account/register', () => { + beforeEach(() => { + cy.server(); + cy.route('POST', '/api/register').as('registerSave') + }); + + it('should load the register page', () => { + cy.visit('/account/register'); + // TODO add translation support here. + cy.contains('h1', 'Registration'); + }); + + it('requires username', () => { + cy.register('', 'someemail@example.com', 'password', 'password'); + cy.get('#username').should('have.class', 'is-invalid'); + }); + + it('requires email', () => { + cy.register('admin', '', 'password', 'password'); + cy.get('#email').should('have.class', 'is-invalid'); + }); + + it('requires email in correct format', () => { + cy.register('admin', 'someemail', 'password', 'password'); + cy.get('#email').should('have.class', 'is-invalid'); + }); + + it('requires confirm password', () => { + cy.register('admin', 'someemail@example.com', 'password', ''); + cy.get('#secondPassword').should('have.class', 'is-invalid'); + }); + + it('requires password and confirm password to be same', () => { + cy.register('admin', 'someemail@example.com', 'password', 'different-password'); + cy.get('#secondPassword').should('have.class', 'is-invalid'); + }); + + it('register a valid user', () => { + cy.register('new-user', 'new-user@example.com', 'password', 'password'); + cy.wait('@registerSave').its('status').should('equal', 201); + }); + + it('error for existing user', () => { + cy.register('admin', 'admin@localhost.com', 'password', 'password'); + cy.wait('@registerSave').its('status').should('equal', 400); + }); +}); \ No newline at end of file diff --git a/generators/client/templates/react/cypress/integration/administration/administration_spec.js.ejs b/generators/client/templates/react/cypress/integration/administration/administration_spec.js.ejs new file mode 100644 index 000000000000..0258e2230c90 --- /dev/null +++ b/generators/client/templates/react/cypress/integration/administration/administration_spec.js.ejs @@ -0,0 +1,58 @@ +<%# Add OAuth2 login feature %> +describe('/admin', () => { + + before(() => { + cy.login(); + }); + + after(() => { + cy.logout(); + }); +<%_ if (!skipUserManagement) { _%> + describe('/user-management', () => { + it('should load the page', () => { + cy.visit('/admin/user-management'); + cy.contains('#user-management-page-heading', 'Users'); + }); + }); +<%_ } _%> + + describe('/metrics', () => { + it('should load the page', () => { + cy.visit('/admin/metrics'); + cy.contains('#metrics-page-heading', 'Application Metrics'); + }); + }); + + + describe('/health', () => { + it('should load the page', () => { + cy.visit('/admin/health'); + cy.contains('#health-page-heading', 'Health Checks'); + }); + }); + +<%_ if ((databaseType !== 'no' || authenticationType === 'uaa') && databaseType !== 'cassandra') { _%> + describe('/audits', () => { + it('should load the page', () => { + cy.visit('/admin/audits'); + cy.contains('#audits-page-heading', 'Audits'); + }); + }); +<%_ } _%> + + describe('/logs', () => { + it('should load the page', () => { + cy.visit('/admin/logs'); + cy.contains('#logs-page-heading', 'Logs'); + }); + }); + + describe('/configuration', () => { + it('should load the page', () => { + cy.visit('/admin/configuration'); + cy.contains('#configuration-page-heading', 'Configuration'); + }); + }); + +}); diff --git a/generators/client/templates/react/cypress/plugins/index.js.ejs b/generators/client/templates/react/cypress/plugins/index.js.ejs new file mode 100644 index 000000000000..f3d14f989cc8 --- /dev/null +++ b/generators/client/templates/react/cypress/plugins/index.js.ejs @@ -0,0 +1,22 @@ +/// +// *********************************************************** +// 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 +} + \ No newline at end of file diff --git a/generators/client/templates/react/cypress/support/commands.js.ejs b/generators/client/templates/react/cypress/support/commands.js.ejs new file mode 100644 index 000000000000..71297481fda1 --- /dev/null +++ b/generators/client/templates/react/cypress/support/commands.js.ejs @@ -0,0 +1,34 @@ +// *********************************************** +// This 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 +// *********************************************** + +const isNotEmpty = (str) => str && str !== ''; + +Cypress.Commands.add("login", (email = "admin", password="admin") => { + cy.visit('/login'); + cy.get('#username').type(email); + cy.get('#password').type(password); + cy.get('button[type="submit"]').click(); + cy.hash().should('eq', ''); + cy.contains(`You are logged in as user "${email}".`) +}); + +Cypress.Commands.add("logout", () => { + cy.get('#account-menu').click(); + cy.get('a[href="/logout"]').click(); +}); + +Cypress.Commands.add("register", (username, email, password, confirmPassword) => { + cy.visit('/account/register'); + if(isNotEmpty(username)) cy.get('#username').type(username); + if(isNotEmpty(email)) cy.get('#email').type(email); + if(isNotEmpty(password)) cy.get('#firstPassword').type(password); + if(isNotEmpty(confirmPassword)) cy.get('#secondPassword').type(confirmPassword); + cy.get('button[type="submit"]').click(); +}); diff --git a/generators/client/templates/react/cypress/support/index.js.ejs b/generators/client/templates/react/cypress/support/index.js.ejs new file mode 100644 index 000000000000..498559a471fa --- /dev/null +++ b/generators/client/templates/react/cypress/support/index.js.ejs @@ -0,0 +1,17 @@ +// *********************************************************** +// This 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'; \ No newline at end of file diff --git a/generators/client/templates/react/package.json.ejs b/generators/client/templates/react/package.json.ejs index eed915742034..8e8b4eff443f 100644 --- a/generators/client/templates/react/package.json.ejs +++ b/generators/client/templates/react/package.json.ejs @@ -164,6 +164,9 @@ limitations under the License. <%_ if (protractorTests) { _%> "ts-node": "8.9.1", <%_ } _%> + <%_ if (cypressTests) { _%> + "cypress": "4.8.0", + <%_ } _%> "typescript": "3.8.3", <%_ if (protractorTests) { _%> "webdriver-manager": "12.1.7", @@ -192,6 +195,9 @@ limitations under the License. <%_ if (skipServer) { _%> "sonar": "sonar-scanner", <%_ } _%> + <%_ if (cypressTests) { _%> + "cypress": "<%= clientPackageManager %> run cypress open", + <%_ } _%> "start": "<%= clientPackageManager %> run webpack:dev", "start-tls": "<%= clientPackageManager %> run webpack:dev -- --env.tls", "jest": "jest --coverage --logHeapUsage --maxWorkers=2 --config src/test/javascript/jest.conf.js", From 9d896062b42ea267b4a7a5b1d8e4c015c8ab680b Mon Sep 17 00:00:00 2001 From: nassimerrahoui Date: Mon, 29 Jun 2020 12:11:43 +0200 Subject: [PATCH 002/116] Move to single Cypress folder Co-authored-by: Adil Abed --- generators/app/index.js | 14 +++ generators/client/files-angular.js | 16 --- .../client/templates/angular/package.json.ejs | 6 + generators/e2e/files.js | 60 ++++++++++ generators/e2e/index.js | 104 ++++++++++++++++++ generators/e2e/templates/cypress.json.ejs | 10 ++ .../account/login_page_spec.js.ejs | 0 .../account/register_page_spec.js.ejs | 0 .../administration/administration_spec.js.ejs | 0 .../javascript}/cypress/plugins/index.js.ejs | 0 .../cypress/support/commands.js.ejs | 0 .../javascript}/cypress/support/index.js.ejs | 0 12 files changed, 194 insertions(+), 16 deletions(-) create mode 100644 generators/e2e/files.js create mode 100644 generators/e2e/index.js create mode 100644 generators/e2e/templates/cypress.json.ejs rename generators/{client/templates/angular => e2e/templates/src/test/javascript}/cypress/integration/account/login_page_spec.js.ejs (100%) rename generators/{client/templates/angular => e2e/templates/src/test/javascript}/cypress/integration/account/register_page_spec.js.ejs (100%) rename generators/{client/templates/angular => e2e/templates/src/test/javascript}/cypress/integration/administration/administration_spec.js.ejs (100%) rename generators/{client/templates/angular => e2e/templates/src/test/javascript}/cypress/plugins/index.js.ejs (100%) rename generators/{client/templates/angular => e2e/templates/src/test/javascript}/cypress/support/commands.js.ejs (100%) rename generators/{client/templates/angular => e2e/templates/src/test/javascript}/cypress/support/index.js.ejs (100%) diff --git a/generators/app/index.js b/generators/app/index.js index 3137ef8c2f6d..38751bd90aa5 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -362,6 +362,20 @@ module.exports = class extends BaseBlueprintGenerator { } }, + composeE2E() { + if (this.configOptions.skipComposeE2E) return; + this.configOptions.skipComposeE2E = true; + const options = this.options; + const configOptions = this.configOptions; + + this.composeWith(require.resolve('../e2e'), { + ...options, + 'client-hook': !this.skipClient, + configOptions, + debug: this.isDebugEnabled, + }); + }, + askForTestOpts: prompts.askForTestOpts, askForMoreModules: prompts.askForMoreModules, diff --git a/generators/client/files-angular.js b/generators/client/files-angular.js index 5f8b49b16ece..2e5f15cc8b0c 100644 --- a/generators/client/files-angular.js +++ b/generators/client/files-angular.js @@ -487,22 +487,6 @@ const files = { condition: generator => generator.protractorTests, templates: ['tsconfig.e2e.json'], }, - { - condition: generator => generator.cypressTests, - path: CYPRESS_DIR, - templates: [ - 'integration/account/login_page_spec.js', - 'integration/account/register_page_spec.js', - 'integration/administration/administration_spec.js', - 'plugins/index.js', - 'support/index.js', - 'support/commands.js', - ], - }, - { - condition: generator => generator.cypressTests, - templates: ['cypress.json'], - }, ], }; diff --git a/generators/client/templates/angular/package.json.ejs b/generators/client/templates/angular/package.json.ejs index 3dc59efaab33..fe0285d7e3fb 100644 --- a/generators/client/templates/angular/package.json.ejs +++ b/generators/client/templates/angular/package.json.ejs @@ -144,6 +144,9 @@ <%_ if (protractorTests) { _%> "ts-node": "8.10.2", <%_ } _%> + <%_ if (cypressTests) { _%> + "cypress": "4.9.0", + <%_ } _%> "tslint": "6.1.2", "typescript": "3.9.5", <%_ otherModules.forEach(module => { _%> @@ -180,6 +183,9 @@ <%_ if (skipServer) { _%> "sonar": "sonar-scanner", <%_ } _%> + <%_ if (cypressTests) { _%> + "cypress": "cypress open", + <%_ } _%> "start-tls": "<%= clientPackageManager %> run webpack:dev -- --env.tls", "serve": "<%= clientPackageManager %> run start", "build": "<%= clientPackageManager %> run webpack:prod", diff --git a/generators/e2e/files.js b/generators/e2e/files.js new file mode 100644 index 000000000000..ac2dda0d9dbc --- /dev/null +++ b/generators/e2e/files.js @@ -0,0 +1,60 @@ +/** + * Copyright 2013-2020 the original author or authors from the JHipster project. + * + * This file is part of the JHipster project, see https://www.jhipster.tech/ + * for more information. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * The default is to use a file path string. It implies use of the template method. + * For any other config an object { file:.., method:.., template:.. } can be used + */ +const constants = require('../generator-constants'); + +const TEST_SRC_DIR = constants.CLIENT_TEST_SRC_DIR; + +const cypressFiles = { + common: [ + { + condition: generator => generator.cypressTests, + templates: ['cypress.json'], + }, + ], + clientTestFw: [ + { + condition: generator => generator.cypressTests, + path: TEST_SRC_DIR, + templates: [ + 'cypress/plugins/index.js', + 'cypress/integration/account/login_page_spec.js', + 'cypress/integration/account/register_page_spec.js', + 'cypress/integration/administration/administration_spec.js', + 'cypress/support/commands.js', + 'cypress/support/index.js', + ], + }, + ], +}; +module.exports = { + writeFiles, +}; + +function writeFiles() { + return { + writeFiles() { + this.writeFilesToDisk(cypressFiles, this, false, this.fetchFromInstalledJHipster('e2e/templates')); + }, + }; +} diff --git a/generators/e2e/index.js b/generators/e2e/index.js new file mode 100644 index 000000000000..7ed5577645c2 --- /dev/null +++ b/generators/e2e/index.js @@ -0,0 +1,104 @@ +/** + * Copyright 2013-2020 the original author or authors from the JHipster project. + * + * This file is part of the JHipster project, see https://www.jhipster.tech/ + * for more information. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* eslint-disable consistent-return */ +const BaseBlueprintGenerator = require('../generator-base-blueprint'); +const writeFiles = require('./files').writeFiles; +const constants = require('../generator-constants'); + +let useBlueprints; + +module.exports = class extends BaseBlueprintGenerator { + constructor(args, opts) { + super(args, opts); + + this.configOptions = this.options.configOptions || {}; + // This adds support for a `--from-cli` flag + this.option('from-cli', { + desc: 'Indicates the command is run from JHipster CLI', + type: Boolean, + defaults: false, + }); + + this.setupServerOptions(this); + this.setupClientOptions(this); + + useBlueprints = !this.fromBlueprint && this.instantiateBlueprints('e2e', { 'client-hook': !this.skipClient }); + } + + // Public API method used by the getter and also by Blueprints + _initializing() { + return { + validateFromCli() { + this.checkInvocationFromCLI(); + }, + + setupConsts() { + // Make constants available in templates + this.MAIN_DIR = constants.MAIN_DIR; + this.TEST_DIR = constants.TEST_DIR; + this.SERVER_MAIN_RES_DIR = constants.SERVER_MAIN_RES_DIR; + this.ANGULAR = constants.SUPPORTED_CLIENT_FRAMEWORKS.ANGULAR; + this.BUILD_DIR = this.getBuildDirectoryForBuildTool(this.buildTool); + this.CLIENT_DIST_DIR = this.getResourceBuildDirectoryForBuildTool(this.configOptions.buildTool) + constants.CLIENT_DIST_DIR; + }, + }; + } + + get initializing() { + if (useBlueprints) return; + return this._initializing(); + } + + // Public API method used by the getter and also by Blueprints + _default() { + return { + getSharedConfigOptions() { + this.jhipsterVersion = this.config.get('jhipsterVersion'); + this.applicationType = this.config.get('applicationType') || this.configOptions.applicationType; + this.serverPort = this.configOptions.serverPort; + this.clientFramework = this.configOptions.clientFramework; + this.authenticationType = this.config.get('authenticationType') || this.configOptions.authenticationType; + this.databaseType = this.config.get('databaseType') || this.configOptions.databaseType; + const baseName = this.config.get('baseName'); + if (baseName) { + this.baseName = baseName; + } + if (this.configOptions.testFrameworks) { + this.testFrameworks = this.configOptions.testFrameworks; + } + this.cypressTests = this.testFrameworks.includes('cypress'); + }, + }; + } + + get default() { + if (useBlueprints) return; + return this._default(); + } + + // Public API method used by the getter and also by Blueprints + _writing() { + return writeFiles(); + } + + get writing() { + if (useBlueprints) return; + return this._writing(); + } +}; diff --git a/generators/e2e/templates/cypress.json.ejs b/generators/e2e/templates/cypress.json.ejs new file mode 100644 index 000000000000..9cc81ea3462e --- /dev/null +++ b/generators/e2e/templates/cypress.json.ejs @@ -0,0 +1,10 @@ +{ + "baseUrl": "http://localhost:8080", + "testFiles": "**/*_spec.js", + "supportFile": "src/test/javascript/cypress/support/index.js", + "video": false, + "integrationFolder": "src/test/javascript/cypress/integration", + "fixturesFolder": "src/test/javascript/cypress/fixtures", + "pluginsFile": "src/test/javascript/cypress/plugins/index.js", + "screenshotsFolder": "src/test/javascript/cypress/screenshots" +} diff --git a/generators/client/templates/angular/cypress/integration/account/login_page_spec.js.ejs b/generators/e2e/templates/src/test/javascript/cypress/integration/account/login_page_spec.js.ejs similarity index 100% rename from generators/client/templates/angular/cypress/integration/account/login_page_spec.js.ejs rename to generators/e2e/templates/src/test/javascript/cypress/integration/account/login_page_spec.js.ejs diff --git a/generators/client/templates/angular/cypress/integration/account/register_page_spec.js.ejs b/generators/e2e/templates/src/test/javascript/cypress/integration/account/register_page_spec.js.ejs similarity index 100% rename from generators/client/templates/angular/cypress/integration/account/register_page_spec.js.ejs rename to generators/e2e/templates/src/test/javascript/cypress/integration/account/register_page_spec.js.ejs diff --git a/generators/client/templates/angular/cypress/integration/administration/administration_spec.js.ejs b/generators/e2e/templates/src/test/javascript/cypress/integration/administration/administration_spec.js.ejs similarity index 100% rename from generators/client/templates/angular/cypress/integration/administration/administration_spec.js.ejs rename to generators/e2e/templates/src/test/javascript/cypress/integration/administration/administration_spec.js.ejs diff --git a/generators/client/templates/angular/cypress/plugins/index.js.ejs b/generators/e2e/templates/src/test/javascript/cypress/plugins/index.js.ejs similarity index 100% rename from generators/client/templates/angular/cypress/plugins/index.js.ejs rename to generators/e2e/templates/src/test/javascript/cypress/plugins/index.js.ejs diff --git a/generators/client/templates/angular/cypress/support/commands.js.ejs b/generators/e2e/templates/src/test/javascript/cypress/support/commands.js.ejs similarity index 100% rename from generators/client/templates/angular/cypress/support/commands.js.ejs rename to generators/e2e/templates/src/test/javascript/cypress/support/commands.js.ejs diff --git a/generators/client/templates/angular/cypress/support/index.js.ejs b/generators/e2e/templates/src/test/javascript/cypress/support/index.js.ejs similarity index 100% rename from generators/client/templates/angular/cypress/support/index.js.ejs rename to generators/e2e/templates/src/test/javascript/cypress/support/index.js.ejs From 363666e0f60da83377753f0af7285266e07c63c5 Mon Sep 17 00:00:00 2001 From: nassimerrahoui Date: Mon, 29 Jun 2020 14:31:26 +0200 Subject: [PATCH 003/116] Migrate to Typescript Co-authored-by: Adil Abed --- generators/e2e/files.js | 13 +++++++------ generators/e2e/templates/cypress.json.ejs | 6 +++--- ...ogin_page_spec.js.ejs => login_page_spec.ts.ejs} | 0 ...r_page_spec.js.ejs => register_page_spec.ts.ejs} | 0 ...ation_spec.js.ejs => administration_spec.ts.ejs} | 0 .../cypress/plugins/{index.js.ejs => index.ts.ejs} | 0 .../support/{commands.js.ejs => commands.ts.ejs} | 0 .../cypress/support/{index.js.ejs => index.ts.ejs} | 0 .../src/test/javascript/cypress/tsconfig.json.ejs | 7 +++++++ 9 files changed, 17 insertions(+), 9 deletions(-) rename generators/e2e/templates/src/test/javascript/cypress/integration/account/{login_page_spec.js.ejs => login_page_spec.ts.ejs} (100%) rename generators/e2e/templates/src/test/javascript/cypress/integration/account/{register_page_spec.js.ejs => register_page_spec.ts.ejs} (100%) rename generators/e2e/templates/src/test/javascript/cypress/integration/administration/{administration_spec.js.ejs => administration_spec.ts.ejs} (100%) rename generators/e2e/templates/src/test/javascript/cypress/plugins/{index.js.ejs => index.ts.ejs} (100%) rename generators/e2e/templates/src/test/javascript/cypress/support/{commands.js.ejs => commands.ts.ejs} (100%) rename generators/e2e/templates/src/test/javascript/cypress/support/{index.js.ejs => index.ts.ejs} (100%) create mode 100644 generators/e2e/templates/src/test/javascript/cypress/tsconfig.json.ejs diff --git a/generators/e2e/files.js b/generators/e2e/files.js index ac2dda0d9dbc..0945f7614c6f 100644 --- a/generators/e2e/files.js +++ b/generators/e2e/files.js @@ -37,12 +37,13 @@ const cypressFiles = { condition: generator => generator.cypressTests, path: TEST_SRC_DIR, templates: [ - 'cypress/plugins/index.js', - 'cypress/integration/account/login_page_spec.js', - 'cypress/integration/account/register_page_spec.js', - 'cypress/integration/administration/administration_spec.js', - 'cypress/support/commands.js', - 'cypress/support/index.js', + 'cypress/plugins/index.ts', + 'cypress/integration/account/login_page_spec.ts', + 'cypress/integration/account/register_page_spec.ts', + 'cypress/integration/administration/administration_spec.ts', + 'cypress/support/commands.ts', + 'cypress/support/index.ts', + 'cypress/tsconfig.json', ], }, ], diff --git a/generators/e2e/templates/cypress.json.ejs b/generators/e2e/templates/cypress.json.ejs index 9cc81ea3462e..df064760d04a 100644 --- a/generators/e2e/templates/cypress.json.ejs +++ b/generators/e2e/templates/cypress.json.ejs @@ -1,10 +1,10 @@ { "baseUrl": "http://localhost:8080", - "testFiles": "**/*_spec.js", - "supportFile": "src/test/javascript/cypress/support/index.js", + "testFiles": "**/*_spec.ts", + "supportFile": "src/test/javascript/cypress/support/index.ts", "video": false, "integrationFolder": "src/test/javascript/cypress/integration", "fixturesFolder": "src/test/javascript/cypress/fixtures", - "pluginsFile": "src/test/javascript/cypress/plugins/index.js", + "pluginsFile": "src/test/javascript/cypress/plugins/index.ts", "screenshotsFolder": "src/test/javascript/cypress/screenshots" } diff --git a/generators/e2e/templates/src/test/javascript/cypress/integration/account/login_page_spec.js.ejs b/generators/e2e/templates/src/test/javascript/cypress/integration/account/login_page_spec.ts.ejs similarity index 100% rename from generators/e2e/templates/src/test/javascript/cypress/integration/account/login_page_spec.js.ejs rename to generators/e2e/templates/src/test/javascript/cypress/integration/account/login_page_spec.ts.ejs diff --git a/generators/e2e/templates/src/test/javascript/cypress/integration/account/register_page_spec.js.ejs b/generators/e2e/templates/src/test/javascript/cypress/integration/account/register_page_spec.ts.ejs similarity index 100% rename from generators/e2e/templates/src/test/javascript/cypress/integration/account/register_page_spec.js.ejs rename to generators/e2e/templates/src/test/javascript/cypress/integration/account/register_page_spec.ts.ejs diff --git a/generators/e2e/templates/src/test/javascript/cypress/integration/administration/administration_spec.js.ejs b/generators/e2e/templates/src/test/javascript/cypress/integration/administration/administration_spec.ts.ejs similarity index 100% rename from generators/e2e/templates/src/test/javascript/cypress/integration/administration/administration_spec.js.ejs rename to generators/e2e/templates/src/test/javascript/cypress/integration/administration/administration_spec.ts.ejs diff --git a/generators/e2e/templates/src/test/javascript/cypress/plugins/index.js.ejs b/generators/e2e/templates/src/test/javascript/cypress/plugins/index.ts.ejs similarity index 100% rename from generators/e2e/templates/src/test/javascript/cypress/plugins/index.js.ejs rename to generators/e2e/templates/src/test/javascript/cypress/plugins/index.ts.ejs diff --git a/generators/e2e/templates/src/test/javascript/cypress/support/commands.js.ejs b/generators/e2e/templates/src/test/javascript/cypress/support/commands.ts.ejs similarity index 100% rename from generators/e2e/templates/src/test/javascript/cypress/support/commands.js.ejs rename to generators/e2e/templates/src/test/javascript/cypress/support/commands.ts.ejs diff --git a/generators/e2e/templates/src/test/javascript/cypress/support/index.js.ejs b/generators/e2e/templates/src/test/javascript/cypress/support/index.ts.ejs similarity index 100% rename from generators/e2e/templates/src/test/javascript/cypress/support/index.js.ejs rename to generators/e2e/templates/src/test/javascript/cypress/support/index.ts.ejs diff --git a/generators/e2e/templates/src/test/javascript/cypress/tsconfig.json.ejs b/generators/e2e/templates/src/test/javascript/cypress/tsconfig.json.ejs new file mode 100644 index 000000000000..43d73d426cd5 --- /dev/null +++ b/generators/e2e/templates/src/test/javascript/cypress/tsconfig.json.ejs @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.json", + "include": [ + "../node_modules/cypress", + "./*/*.ts" + ] + } From 571d4bbabf67079d23f50e8f06ee5a99ca3d789c Mon Sep 17 00:00:00 2001 From: nassimerrahoui Date: Tue, 30 Jun 2020 11:45:42 +0200 Subject: [PATCH 004/116] [Account] Login page (with Angular) Co-authored-by: Adil Abed --- generators/client/files-angular.js | 1 - .../register/register.component.html.ejs | 8 +- .../configuration.component.html.ejs | 2 +- .../admin/health/health.component.html.ejs | 2 +- .../app/admin/logs/logs.component.html.ejs | 2 +- .../admin/metrics/metrics.component.html.ejs | 2 +- .../user-management.component.html.ejs | 2 +- .../core/login/login-modal.component.html.ejs | 10 +-- .../layouts/navbar/navbar.component.html.ejs | 12 +-- generators/e2e/files.js | 1 + generators/e2e/templates/cypress.json.ejs | 2 +- .../account/login_page_spec.ts.ejs | 84 +++++++++---------- .../account/register_page_spec.ts.ejs | 15 ++-- .../administration/administration_spec.ts.ejs | 31 ++++--- .../cypress/support/commands.ts.ejs | 83 +++++++++++++----- .../javascript/cypress/support/index.ts.ejs | 5 +- .../javascript/cypress/support/navbar.ts.ejs | 50 +++++++++++ .../test/javascript/cypress/tsconfig.json.ejs | 8 +- 18 files changed, 210 insertions(+), 110 deletions(-) create mode 100644 generators/e2e/templates/src/test/javascript/cypress/support/navbar.ts.ejs diff --git a/generators/client/files-angular.js b/generators/client/files-angular.js index 2e5f15cc8b0c..e1abd4b1adbc 100644 --- a/generators/client/files-angular.js +++ b/generators/client/files-angular.js @@ -23,7 +23,6 @@ const constants = require('../generator-constants'); const MAIN_SRC_DIR = constants.CLIENT_MAIN_SRC_DIR; const TEST_SRC_DIR = constants.CLIENT_TEST_SRC_DIR; const ANGULAR_DIR = constants.ANGULAR_DIR; -const CYPRESS_DIR = 'cypress/'; /** * The default is to use a file path string. It implies use of the template method. diff --git a/generators/client/templates/angular/src/main/webapp/app/account/register/register.component.html.ejs b/generators/client/templates/angular/src/main/webapp/app/account/register/register.component.html.ejs index 6c005afddb24..23a0fb7539af 100644 --- a/generators/client/templates/angular/src/main/webapp/app/account/register/register.component.html.ejs +++ b/generators/client/templates/angular/src/main/webapp/app/account/register/register.component.html.ejs @@ -49,7 +49,7 @@
+ formControlName="login" data-cy=username #login>
+ formControlName="email" data-cy=email>
+ formControlName="password" data-cy=firstPassword>
+ formControlName="confirmPassword" data-cy=secondPassword>
-

Configuration

+

Configuration

Filter (by prefix) diff --git a/generators/client/templates/angular/src/main/webapp/app/admin/health/health.component.html.ejs b/generators/client/templates/angular/src/main/webapp/app/admin/health/health.component.html.ejs index 48eadf6c5b5b..d8a49ac62a9b 100644 --- a/generators/client/templates/angular/src/main/webapp/app/admin/health/health.component.html.ejs +++ b/generators/client/templates/angular/src/main/webapp/app/admin/health/health.component.html.ejs @@ -18,7 +18,7 @@ -%>

- Health Checks + Health Checks + <%_ if (!skipUserManagement) { _%> diff --git a/generators/client/templates/angular/src/main/webapp/app/layouts/navbar/navbar.component.html.ejs b/generators/client/templates/angular/src/main/webapp/app/layouts/navbar/navbar.component.html.ejs index 17e31c8fc26d..36cb7da7711f 100644 --- a/generators/client/templates/angular/src/main/webapp/app/layouts/navbar/navbar.component.html.ejs +++ b/generators/client/templates/angular/src/main/webapp/app/layouts/navbar/navbar.component.html.ejs @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and limitations under the License. -%> -