From f958e632d5692726749414156b10472297d7e35a Mon Sep 17 00:00:00 2001 From: Johan Girod Date: Tue, 22 Oct 2019 14:25:06 +0200 Subject: [PATCH] :white_check_mark: Ajoute des tests extensif pour tous les simulateurs --- _redirects | 15 --- circle.yml | 3 +- cypress.json | 2 +- cypress/.eslintrc.yaml | 1 + cypress/integration/mon-entreprise/gérer.js | 33 ++++++ cypress/integration/mon-entreprise/iframe.js | 9 +- cypress/integration/mon-entreprise/landing.js | 8 +- .../integration/mon-entreprise/navigation.js | 19 ++- .../mon-entreprise/simulateur-salarié.js | 46 -------- .../integration/mon-entreprise/simulateurs.js | 111 +++++++++++------- cypress/integration/mon-entreprise/status.js | 20 +--- cypress/support/commands.js | 2 +- netlify.toml | 66 +++++++++++ .../simulationConfigs/assimilé.yaml | 3 - source/locales/en.yaml | 2 +- source/sites/mon-entreprise.fr/App.js | 2 - .../sites/mon-entreprise.fr/layout/Header.js | 2 +- source/webpack.prod.js | 2 +- 18 files changed, 205 insertions(+), 141 deletions(-) delete mode 100644 _redirects create mode 100644 cypress/integration/mon-entreprise/gérer.js delete mode 100644 cypress/integration/mon-entreprise/simulateur-salarié.js diff --git a/_redirects b/_redirects deleted file mode 100644 index 001088aac..000000000 --- a/_redirects +++ /dev/null @@ -1,15 +0,0 @@ -# Redirects following architectural changes on the end of October 2018 -/s%C3%A9curit%C3%A9-sociale /g%C3%A9rer 301 -/d%C3%A9marches-embauche /g%C3%A9rer/embaucher 301 -/s%C3%A9curit%C3%A9-sociale/s%C3%A9lection-du-r%C3%A9gime /simulateurs 301 -/s%C3%A9curit%C3%A9-sociale/* /simulateurs/:splat 301 -/entreprise/cr%C3%A9er-une-* /cr%C3%A9er/:splat 301 -/entreprise/devenir-* /cr%C3%A9er/:splat 301 -/entreprise* /cr%C3%A9er:splat 301 - -/social-security /manage 301 -/social-security/assimilated-salaried /social-security/assimile-salarie 301 -/social-security/* /simulators/:splat 301 -/company/create-a-* /create/:splat 301 -/company/become-* /create/:splat 301 -/company* /create:splat 301 diff --git a/circle.yml b/circle.yml index 3ad4c584d..36dff8e7d 100644 --- a/circle.yml +++ b/circle.yml @@ -27,7 +27,7 @@ commands: type: string default: https://mon-entreprise.fr steps: - - run: CYPRESS_baseUrl=<< parameters.base_url >> yarn run cypress run --record --key 21660df5-36a5-4c49-b23d-801799b0c759 --env language=<< parameters.language >> --config integrationFolder=cypress/integration/<< parameters.integration_folder >> + - run: CYPRESS_baseUrl=<< parameters.base_url >> yarn run cypress run --parallel --record --key 21660df5-36a5-4c49-b23d-801799b0c759 --env language=<< parameters.language >> --config integrationFolder=cypress/integration/<< parameters.integration_folder >> jobs: unit-test: @@ -46,6 +46,7 @@ jobs: - image: cypress/base:8 environment: TERM: xterm + parallelism: 2 steps: - install - run: yarn run compile-dev diff --git a/cypress.json b/cypress.json index 8377ceef0..036d92538 100644 --- a/cypress.json +++ b/cypress.json @@ -6,4 +6,4 @@ }, "integrationFolder": "cypress/integration/mon-entreprise", "chromeWebSecurity": false -} +} \ No newline at end of file diff --git a/cypress/.eslintrc.yaml b/cypress/.eslintrc.yaml index e079cdeab..00d3d5fdd 100644 --- a/cypress/.eslintrc.yaml +++ b/cypress/.eslintrc.yaml @@ -1,4 +1,5 @@ globals: cy: false Cypress: false + expect: false parser: esprima diff --git a/cypress/integration/mon-entreprise/gérer.js b/cypress/integration/mon-entreprise/gérer.js new file mode 100644 index 000000000..38c5807fc --- /dev/null +++ b/cypress/integration/mon-entreprise/gérer.js @@ -0,0 +1,33 @@ + +describe('Manage page test', function () { + const fr = Cypress.env('language') === 'fr' + beforeEach(() => { + cy.visit(fr ? '/gérer' : '/manage') + }) + it('should not crash', function () { + cy.contains( + fr ? 'Gérer mon activité' : 'Manage my business' + ) + }) + it('should allow to retrieve company and show link corresponding to the legal status', function () { + cy.get('button.cta').click() + cy.get('input').first().type('menoz') + cy.contains('834364291').click() + cy.contains('assimilé-salarié').click() + cy.location().should((loc) => { + expect(loc.pathname).to.match(fr ? /assimil%C3%A9-salari%C3%A9$/ : /assimile-salarie$/) + }) + }) + it('should allow auto entrepreneur to access the corresponding income simulator', function () { + cy.get('button.cta').click() + cy.get('input').first().type('gwenael girod') + cy.contains('MONSIEUR').click() + // ask if auto-entrepreneur + cy.contains(fr ? 'Êtes-vous auto-entrepreneur ?' : 'Are you auto-entrepreneur?') + cy.contains(fr ? 'Oui' : 'Yes').click() + cy.contains(fr ? 'simulateur auto-entrepreneur' : 'simulator for auto-entrepreneur').click() + cy.location().should((loc) => { + expect(loc.pathname).to.match(/auto-entrepreneur$/) + }) + }) +}) diff --git a/cypress/integration/mon-entreprise/iframe.js b/cypress/integration/mon-entreprise/iframe.js index f6f0cd8ac..44d53237e 100644 --- a/cypress/integration/mon-entreprise/iframe.js +++ b/cypress/integration/mon-entreprise/iframe.js @@ -1,6 +1,11 @@ -describe('Iframe integration test', function() { - it('should display an iframe of the simulateur', function() { +describe('Iframe integration test', function () { + if (Cypress.env('language') !== 'fr') { + return + } + it('should display an iframe of the simulateur', function () { cy.visit('/dev/integration-test') + cy.contains('Visualiser').click() + cy.wait(1000) cy.get('#simulateurEmbauche') .iframe() .contains('Salaire net') diff --git a/cypress/integration/mon-entreprise/landing.js b/cypress/integration/mon-entreprise/landing.js index 7eaa1e5c8..aeec373db 100644 --- a/cypress/integration/mon-entreprise/landing.js +++ b/cypress/integration/mon-entreprise/landing.js @@ -1,15 +1,15 @@ -describe('Landing test', function() { +describe('Landing test', function () { const fr = Cypress.env('language') === 'fr' - it('should not crash', function() { + it('should not crash', function () { cy.visit('/') cy.get('img[alt="logo mon-entreprise.fr"]').should('be.visible') }) - it('should display urssaf and marianne logo', function() { + it('should display urssaf and marianne logo', function () { cy.visit('/') cy.get('img[alt="logo urssaf"]').should('be.visible') cy.get('img[alt="logo marianne"]').should('be.visible') }) - it('should display actionnable items', function() { + it('should display actionnable items', function () { cy.visit('/') cy.contains(fr ? 'Créer une entreprise' : 'Create a company') cy.contains(fr ? 'Gérer mon activité' : 'Manage my business') diff --git a/cypress/integration/mon-entreprise/navigation.js b/cypress/integration/mon-entreprise/navigation.js index 326ea36f2..1cfedd676 100644 --- a/cypress/integration/mon-entreprise/navigation.js +++ b/cypress/integration/mon-entreprise/navigation.js @@ -1,17 +1,26 @@ -describe('Navigation', function() { +describe('Navigation', function () { const fr = Cypress.env('language') === 'fr' it('should enable switching site language', () => { cy.visit( fr - ? '/entreprise/devenir-auto-entrepreneur' - : '/company/become-auto-entrepreneur' + ? '/créer/auto-entrepreneur' + : '/create/auto-entrepreneur' ) cy.contains(fr ? 'Switch to English' : 'Passer en français').click() cy.url().should( 'include', fr - ? '/company/become-auto-entrepreneur' - : '/entreprise/devenir-auto-entrepreneur' + ? '/create/auto-entrepreneur' + : '/cr%C3%A9er/auto-entrepreneur' + ) + }) + + it('should go back to home when clicking on logo', () => { + cy.visit('/documentation/contrat-salarié') + cy.get('img[alt^="logo mon-entreprise"]').click() + cy.url().should( + 'be', + Cypress.baseUrl ) }) }) diff --git a/cypress/integration/mon-entreprise/simulateur-salarié.js b/cypress/integration/mon-entreprise/simulateur-salarié.js deleted file mode 100644 index 76924cb1c..000000000 --- a/cypress/integration/mon-entreprise/simulateur-salarié.js +++ /dev/null @@ -1,46 +0,0 @@ -const salaryInput = inputTitle => { - const inputContainer = cy - .contains(inputTitle) - .closest('.main') - .find('.targetInputOrValue') - inputContainer.click() - return inputContainer.find('input') -} - -const fr = Cypress.env('language') === 'fr' -if (fr) { - beforeEach(() => { - cy.visit('/sécurité-sociale/salarié') - }) - describe('Basic test', function() { - it('should display the simulateur after loading', function() { - cy.contains('Salaire net') - }) - it('should display cotisation repartition when entering net salary', function() { - salaryInput('Salaire net').type('2000') - cy.get('.distribution-chart__container') - }) - it('should allow to navigate to a documentation page', function() { - salaryInput('Salaire net').type('2000') - cy.contains('Total chargé').click() - cy.contains( - `C'est le total que l'employeur doit verser pour employer un salarié` - ) - }) - }) - - describe('Simulation saving test', function() { - it('should save the current simulation', function() { - salaryInput('Salaire net').type('471') - cy.wait(1000) - cy.contains('Passer').click() - cy.contains('Passer').click() - cy.contains('Passer').click() - // Wanted to use cypress.clock(), but can't because of piwik changing Date prototype (!) - cy.wait(1100) - cy.visit('/sécurité-sociale/salarié') - cy.contains('Retrouver ma simulation').click() - salaryInput('Salaire net').should('have.value', '471') - }) - }) -} diff --git a/cypress/integration/mon-entreprise/simulateurs.js b/cypress/integration/mon-entreprise/simulateurs.js index 02628c1a0..49926efc7 100644 --- a/cypress/integration/mon-entreprise/simulateurs.js +++ b/cypress/integration/mon-entreprise/simulateurs.js @@ -1,46 +1,69 @@ -const salaryInput = inputTitle => { - const inputContainer = cy - .contains(inputTitle) - .closest('.main') - .find('.targetInputOrValue') - inputContainer.click() - return inputContainer.find('input') -} -describe('Simulateurs test', function() { - const fr = Cypress.env('language') === 'fr' +const fr = Cypress.env('language') === 'fr' +const inputSelector = 'input.currencyInput__input:not([name$="charges"])' +describe('Simulateurs', function () { + if (!fr) { return } + ['indépendant', 'assimilé-salarié', 'auto-entrepreneur', 'salarié'].forEach(simulateur => + describe(simulateur, () => { + before(() => cy.visit(`/simulateurs/${simulateur}`)) + it('should not crash', function () { + cy.get(inputSelector) + }) - it('should not crash', function() { - cy.visit(fr ? '/sécurité-sociale' : '/social-security') - cy.contains( - fr ? 'Que souhaitez-vous estimer ?' : 'What do you want to estimate?' - ) - }) - it('should display selection page', function() { - cy.visit(fr ? '/sécurité-sociale' : '/social-security') - cy.contains(fr ? 'Mon revenu' : 'My income').click() - cy.contains( - fr - ? 'Quel régime souhaitez-vous explorer ?' - : 'Which social scheme would you like to explore?' - ) - cy.contains('Indépendant').click({ force: true }) - cy.contains( - fr - ? 'Simulateur de revenus pour indépendants' - : 'Self-employed income simulator' - ) - }) - it('donne une estimation pour le revenu des indépendants', function() { - cy.visit( - fr ? '/sécurité-sociale/indépendant' : '/social-security/self-employed' - ) - salaryInput(fr ? 'Rémunération totale' : 'Director total income').type( - 100000, - { - force: true - } - ) - cy.contains(fr ? 'Cotisations et contributions' : 'All contributions') - }) -}) + it('should display a result when entering a value in any of the currency input', () => { + cy.contains('année').click() + if (['indépendant', 'assimilé-salarié'].includes(simulateur)) { + cy.get('input.currencyInput__input[name$="charges"]').type(1000) + } + cy.get(inputSelector).each((testedInput, i) => { + cy.wrap(testedInput).type('{selectall}60000') + cy.wait(600) + cy.contains('Cotisations') + cy.get(inputSelector).each(($input, j) => { + const val = $input.val().replace(/[\s,.]/g, '') + if (i != j) { + expect(val).not.to.be.eq('60000') + } + expect(val).to.match(/[1-9][\d]*$/) + }) + }) + }) + + it.only('should allow to change period', function () { + cy.contains('année').click() + cy.get(inputSelector).first().type('{selectall}12000') + cy.wait(500) + cy.contains('mois').click() + cy.get(inputSelector).first().invoke('val').should('match', /1[\s]000/) + }) + + it('should allow to navigate to a documentation page', function () { + cy.get(inputSelector).first().type('{selectall}2000') + cy.wait(700) + cy.contains('Cotisations').click() + cy.location().should((loc) => { + expect(loc.pathname).to.match(/\/documentation\/.*\/cotisations/) + }) + }) + + it('should allow to go back to the simulation', function () { + cy.contains('← ').click(); + cy.get(inputSelector).first().invoke('val').should('be', '2 000') + }) + + if (simulateur === 'salarié') { + it('should save the current simulation', function () { + cy.get(inputSelector).first().type('{selectall}2137') + cy.contains('Passer').click() + cy.contains('Passer').click() + cy.contains('Passer').click() + cy.wait(1000) + cy.visit('/simulateurs/salarié') + cy.contains('Retrouver ma simulation').click() + cy.get(inputSelector).first().invoke('val').should('match', /2[\s]137/) + }) + } + + }) + ) +}) \ No newline at end of file diff --git a/cypress/integration/mon-entreprise/status.js b/cypress/integration/mon-entreprise/status.js index 5beb3eb3e..008055248 100644 --- a/cypress/integration/mon-entreprise/status.js +++ b/cypress/integration/mon-entreprise/status.js @@ -1,27 +1,18 @@ -describe('Status guide', function() { +describe('Status guide', function () { const fr = Cypress.env('language') === 'fr' beforeEach(() => { - cy.visit(fr ? '/entreprise' : '/company') - cy.get('a.ui__.button.plain').click() + cy.visit(fr ? '/créer' : '/create') + cy.get('.cta').click() }) - it('should allow to go back clicking on the previous button', function() { - cy.get('.ui__.answer-group') - .contains(fr ? 'Seul' : 'Alone') - .click() - cy.get('.ui__.answer-group') - .contains(fr ? 'Précédent' : 'Previous') - .click() - cy.contains(fr ? 'Seul ou à plusieurs' : 'Number of partners') - }) - it('should allow to go back clicking on the previous answers', function() { + it('should allow to go back clicking on the previous answers', function () { cy.get('.ui__.answer-group') .contains(fr ? 'Seul' : 'Alone') .click() cy.contains(fr ? 'Un seul associé' : 'Only one partner').click() cy.contains(fr ? 'Seul ou à plusieurs' : 'Number of partners') }) - it('should guide thought the SASU status', function() { + it('should guide thought the SASU status', function () { cy.get('.ui__.answer-group') .contains(fr ? 'Seul' : 'Alone') .click() @@ -34,5 +25,6 @@ describe('Status guide', function() { .contains('Assimilé') .click() cy.contains(fr ? 'Créer une SASU' : 'Create a SASU').click() + cy.url().should('match', /\/SASU$/) }) }) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 7636dcaf0..d2e62b78c 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -25,6 +25,6 @@ // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) Cypress.Commands.add('iframe', { prevSubject: 'element' }, $iframe => { return new Cypress.Promise(resolve => { - setTimeout(() => resolve($iframe.contents().find('body')), 5000) + setTimeout(() => resolve($iframe.contents().find('body')), 6000) }) }) diff --git a/netlify.toml b/netlify.toml index b6bad8a30..be6a63881 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,3 +1,69 @@ +# Redirects following architectural changes on the end of October 2018 +[[redirects]] + from="/s%C3%A9curit%C3%A9-sociale" + to="/g%C3%A9rer" + status = 301 + +[[redirects]] + from="/d%C3%A9marches-embauche" + to="/g%C3%A9rer/embaucher" + status = 301 + +[[redirects]] + from="/s%C3%A9curit%C3%A9-sociale/s%C3%A9lection-du-r%C3%A9gime" + to="/simulateurs" + status = 301 + +[[redirects]] + from="/s%C3%A9curit%C3%A9-sociale/*" + to="/simulateurs/:splat" + status = 301 + +[[redirects]] + from="/entreprise/cr%C3%A9er-une-*" + to="/cr%C3%A9er/:splat" + status = 301 + +[[redirects]] + from="/entreprise/devenir-*" + to="/cr%C3%A9er/:splat" + status = 301 + +[[redirects]] + from="/entreprise*" + to="/cr%C3%A9er:splat" + status = 301 + +[[redirects]] + from="/social-security" + to="/manage" + status = 301 + +[[redirects]] + from="/social-security/assimilated-salaried" + to="/social-security/assimile-salarie" + status = 301 + +[[redirects]] + from="/social-security/*" + to="/simulators/:splat" + status = 301 + +[[redirects]] + from="/company/create-a-*" + to="/create/:splat" + status = 301 + +[[redirects]] + from="/company/become-*" + to="/create/:splat" + status = 301 + +[[redirects]] + from="/company*" + to="/create:splat" + status = 301 + # SEO redirect [[redirects]] diff --git a/source/components/simulationConfigs/assimilé.yaml b/source/components/simulationConfigs/assimilé.yaml index 50bb36b3f..8c3ea932e 100644 --- a/source/components/simulationConfigs/assimilé.yaml +++ b/source/components/simulationConfigs/assimilé.yaml @@ -13,9 +13,6 @@ objectifs: - entreprise . charges - entreprise . chiffre d'affaires minimum -objectifs secondaires: - - contrat salarié . cotisations - questions: à l'affiche: ACRE: entreprise . ACRE diff --git a/source/locales/en.yaml b/source/locales/en.yaml index 1612a5d43..a49bfdc81 100644 --- a/source/locales/en.yaml +++ b/source/locales/en.yaml @@ -342,7 +342,7 @@ gérer: <0>Access the official auto-entrepreneur website <1>You will be able to make your turnover declaration, pay your contributions, and more widely find all the information relating to the status of auto-entrepreneur entreprise: - auto: Are you an auto-entrepreneur? + auto: Are you auto-entrepreneur? dirigeant: | <0>Are you the majority director? <1>If you are a majority director or a member of a majority board of directors, you will not have the same social security system as if you are a minority. diff --git a/source/sites/mon-entreprise.fr/App.js b/source/sites/mon-entreprise.fr/App.js index a20f0155f..9404f2c41 100644 --- a/source/sites/mon-entreprise.fr/App.js +++ b/source/sites/mon-entreprise.fr/App.js @@ -118,8 +118,6 @@ const App = compose(withSitePaths)(({ sitePaths }) => { path={sitePaths.documentation.index} component={Documentation} /> - -