Skip to content

Commit

Permalink
test(e2e): add cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienLavocat committed Apr 28, 2023
1 parent 9d8184d commit dc48701
Show file tree
Hide file tree
Showing 10 changed files with 677 additions and 40 deletions.
67 changes: 60 additions & 7 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,44 @@
"options": {
"tsConfig": [
"src/tsconfig.app.json",
"src/tsconfig.spec.json"
"src/tsconfig.spec.json",
"cypress/tsconfig.json"
],
"exclude": [
"**/node_modules/**"
]
}
},
"cypress-run": {
"builder": "@cypress/schematic:cypress",
"options": {
"devServerTarget": "acrabadabra:serve"
},
"configurations": {
"production": {
"devServerTarget": "acrabadabra:serve:production"
}
}
},
"cypress-open": {
"builder": "@cypress/schematic:cypress",
"options": {
"watch": true,
"headless": false
}
},
"e2e": {
"builder": "@cypress/schematic:cypress",
"options": {
"devServerTarget": "acrabadabra:serve",
"watch": true,
"headless": false
},
"configurations": {
"production": {
"devServerTarget": "acrabadabra:serve:production"
}
}
}
}
},
Expand All @@ -160,28 +192,49 @@
"prefix": "",
"architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"builder": "@cypress/schematic:cypress",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "acrabadabra:serve"
"devServerTarget": "acrabadabra-e2e:serve",
"watch": true,
"headless": false
},
"configurations": {
"production": {
"devServerTarget": "acrabadabra:serve:production"
"devServerTarget": "acrabadabra-e2e:serve:production"
}
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": "e2e/tsconfig.e2e.json",
"tsConfig": "",
"exclude": [
"**/node_modules/**"
]
}
},
"cypress-run": {
"builder": "@cypress/schematic:cypress",
"options": {
"devServerTarget": "acrabadabra-e2e:serve",
"configFile": "e2e//cypress.config.ts"
},
"configurations": {
"production": {
"devServerTarget": "acrabadabra-e2e:serve:production"
}
}
},
"cypress-open": {
"builder": "@cypress/schematic:cypress",
"options": {
"watch": true,
"headless": false,
"configFile": "e2e//cypress.config.ts"
}
}
}
}
},
"defaultProject": "acrabadabra"
}
}
11 changes: 11 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineConfig } from 'cypress'

export default defineConfig({

e2e: {
'baseUrl': 'http://localhost:4200',
supportFile: false
},


})
34 changes: 34 additions & 0 deletions cypress/e2e/home.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
describe("When browsing the HomePage :", () => {
beforeEach(() => {
cy.visit("/");
});

it("Should display page's title as Acrabadabra", () => {
cy.title().should("eq", "Acrabadabra");
});

it("should display the baseline", () => {
cy.contains("Une solution en ligne pour les SSII").should("exist");
});

it("should have a button to create a new CRA", () => {
cy.get("#consultant").should("exist");
});

it("should have a button to access the SSI's dashboard", () => {
cy.get("#provider").should("exist");
});

it("should redirect to create a CRA page", () => {
cy.get("#consultant").click();
cy.url().then(
(url) => expect(url.endsWith("/timesheet/create")).to.be.true
);
});

it("should open a popup to login to the dashboard", () => {
cy.get("#netlify-identity-widget").should("not.be.visible");
cy.get("#provider").click();
cy.get("#netlify-identity-widget", { timeout: 10000 }).should("be.visible");
});
});
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]"
}

43 changes: 43 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// ***********************************************
// This example namespace declaration will help
// with Intellisense and code completion in your
// IDE or Text Editor.
// ***********************************************
// declare namespace Cypress {
// interface Chainable<Subject = any> {
// customCommand(param: any): typeof customCommand;
// }
// }
//
// function customCommand(param: any): void {
// console.warn(param);
// }
//
// NOTE: You can use it like so:
// Cypress.Commands.add('customCommand', customCommand);
//
// ***********************************************
// 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) => { ... })
17 changes: 17 additions & 0 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ***********************************************************
// This example support/e2e.ts 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
// ***********************************************************

// When a command from ./commands is ready to use, import with `import './commands'` syntax
// import './commands';
8 changes: 8 additions & 0 deletions cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../tsconfig.json",
"include": ["**/*.ts"],
"compilerOptions": {
"sourceMap": false,
"types": ["cypress"]
}
}
11 changes: 11 additions & 0 deletions e2e/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineConfig } from 'cypress'

export default defineConfig({

e2e: {
'baseUrl': 'http://localhost:4200',
supportFile: false
},


})
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
"test": "ENV=dev ng test",
"ci:test": "ng test --no-watch --browsers=CustomChromeHeadless --karma-config=karma.conf.js",
"lint": "ng lint",
"e2e": "ENV=prod node scripts/set-env.js && ng e2e",
"e2e": "ng e2e",
"dev": "ng serve --configuration local",
"bootstrap": "node ./scripts/bootstrap-fauna-database.js"
"bootstrap": "node ./scripts/bootstrap-fauna-database.js",
"cypress:open": "cypress open",
"cypress:run": "cypress run"
},
"private": true,
"dependencies": {
Expand Down Expand Up @@ -50,6 +52,7 @@
"@angular/cli": "^13.3.7",
"@angular/compiler-cli": "^13.3.11",
"@angular/language-service": "^13.3.11",
"@cypress/schematic": "2.4.0",
"@netlify/esbuild-linux-64": "^0.14.25",
"@types/jasmine": "^4.0.3",
"@types/jasminewd2": "^2.0.10",
Expand Down Expand Up @@ -80,7 +83,8 @@
"ts-node": "~10.8.0",
"tslint": "~6.1.3",
"typescript": "4.6.4",
"webpack": "^5.72.1"
"webpack": "^5.72.1",
"cypress": "latest"
},
"proxy": {
"/.netlify/functions": {
Expand Down
Loading

0 comments on commit dc48701

Please sign in to comment.