From 6faf98964a025f318443f66d41489ceeb26ff31a Mon Sep 17 00:00:00 2001 From: Alexandre Hajjar Date: Thu, 27 May 2021 19:52:43 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Split=20Cypress=20simulateur=20test?= =?UTF-8?q?s=20&=20some=20improvements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * modularize generic simulateurs tests * split salarié * improve perf (mostly: remove cy.wait calls) * ignore downloads folder --- mon-entreprise/.gitignore | 1 + .../integration/mon-entreprise/iframe.js | 1 - .../mon-entreprise/localisation-field.js | 19 +++ .../mon-entreprise/partage-simulation.js | 35 +++++ .../mon-entreprise/persistence-simulation.js | 34 +++++ .../mon-entreprise/simulateur-ae.js | 28 ++++ .../mon-entreprise/simulateur-salarie.js | 41 ++++++ .../simulateurs-generic/auto-entrepreneur.js | 3 + .../simulateurs-generic/dirigeant-sasu.js | 3 + .../simulateurs-generic/indépendant.js | 3 + .../profession-liberale.js | 3 + .../profession-liberale/auxiliaire-medical.js | 3 + .../chirurgien-dentiste.js | 3 + .../profession-liberale/medecin.js | 3 + .../profession-liberale/sage-femme.js | 3 + .../simulateurs-generic/salarié.js | 3 + .../integration/mon-entreprise/simulateurs.js | 125 ------------------ .../cypress/integration/publi.codes/index.js | 1 - mon-entreprise/cypress/support/simulateur.js | 68 ++++++++++ 19 files changed, 253 insertions(+), 127 deletions(-) create mode 100644 mon-entreprise/cypress/integration/mon-entreprise/localisation-field.js create mode 100644 mon-entreprise/cypress/integration/mon-entreprise/partage-simulation.js create mode 100644 mon-entreprise/cypress/integration/mon-entreprise/persistence-simulation.js create mode 100644 mon-entreprise/cypress/integration/mon-entreprise/simulateur-ae.js create mode 100644 mon-entreprise/cypress/integration/mon-entreprise/simulateur-salarie.js create mode 100644 mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/auto-entrepreneur.js create mode 100644 mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/dirigeant-sasu.js create mode 100644 mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/indépendant.js create mode 100644 mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/profession-liberale.js create mode 100644 mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/profession-liberale/auxiliaire-medical.js create mode 100644 mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/profession-liberale/chirurgien-dentiste.js create mode 100644 mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/profession-liberale/medecin.js create mode 100644 mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/profession-liberale/sage-femme.js create mode 100644 mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/salarié.js create mode 100644 mon-entreprise/cypress/support/simulateur.js diff --git a/mon-entreprise/.gitignore b/mon-entreprise/.gitignore index d0deaa9b6..8cb3d3668 100644 --- a/mon-entreprise/.gitignore +++ b/mon-entreprise/.gitignore @@ -3,3 +3,4 @@ source/data/* !source/data/versement-transport.json cypress/videos cypress/screenshots +cypress/downloads diff --git a/mon-entreprise/cypress/integration/mon-entreprise/iframe.js b/mon-entreprise/cypress/integration/mon-entreprise/iframe.js index 86b694f5e..fa926412f 100644 --- a/mon-entreprise/cypress/integration/mon-entreprise/iframe.js +++ b/mon-entreprise/cypress/integration/mon-entreprise/iframe.js @@ -5,7 +5,6 @@ describe('Iframe integration test', function () { 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/mon-entreprise/cypress/integration/mon-entreprise/localisation-field.js b/mon-entreprise/cypress/integration/mon-entreprise/localisation-field.js new file mode 100644 index 000000000..43ec586b9 --- /dev/null +++ b/mon-entreprise/cypress/integration/mon-entreprise/localisation-field.js @@ -0,0 +1,19 @@ +const fr = Cypress.env('language') === 'fr' +const inputSelector = 'input.currencyInput__input:not([name$="charges"])' + +describe('Champs localisation (simulateur salarié)', () => { + if (!fr) { + return + } + before(() => cy.visit(encodeURI('/simulateurs/salarié'))) + + it('should not crash when selecting localisation', function () { + cy.get(inputSelector).first().type('{selectall}42') + cy.contains('Commune').click({ force: true }) + cy.get('fieldset input[type="search"]').type('Steenvoorde') + cy.contains('Steenvoorde (59114)').click({ force: true }) + cy.contains('Suivant').click({ force: true }) + cy.contains('Voir mes paramètres').click({ force: true }) + cy.contains('Steenvoorde') + }) +}) diff --git a/mon-entreprise/cypress/integration/mon-entreprise/partage-simulation.js b/mon-entreprise/cypress/integration/mon-entreprise/partage-simulation.js new file mode 100644 index 000000000..729ff5e66 --- /dev/null +++ b/mon-entreprise/cypress/integration/mon-entreprise/partage-simulation.js @@ -0,0 +1,35 @@ +const fr = Cypress.env('language') === 'fr' + +describe('Partage (simulateur salarié)', () => { + const brutInputSelector = + 'input.currencyInput__input[name="contrat salarié . rémunération . brut de base"]' + const simulatorUrl = '/simulateurs/salaire-brut-net' + const searchParams = new URLSearchParams({ + 'contrat salarié': "'CDD'", + 'salaire-brut': '1539€/mois', + }) + searchParams.set('utm_source', 'sharing') + + const urlWithState = `${simulatorUrl}?${searchParams.toString()}` + if (!fr) { + return + } + it('should set input value from URL', function () { + cy.visit(urlWithState) + cy.get(brutInputSelector).first().invoke('val').should('eq', '1 539') + + cy.contains('Voir mes paramètres').click() + cy.get('span.answerContent').first().contains('CDD') + }) + it('should set URL from input value', function () { + cy.visit(simulatorUrl) + cy.get(brutInputSelector).first().type('{selectall}1539') + cy.contains('De quel type de contrat').should('be.visible') + cy.get('.step').contains('CDD').should('be.visible').click() + cy.get('button').contains('Suivant').should('be.visible') + cy.contains('Générer un lien').click() + cy.get('.shareableLink') + .invoke('val') + .should('eq', Cypress.config().baseUrl + urlWithState) + }) +}) diff --git a/mon-entreprise/cypress/integration/mon-entreprise/persistence-simulation.js b/mon-entreprise/cypress/integration/mon-entreprise/persistence-simulation.js new file mode 100644 index 000000000..24d7504c8 --- /dev/null +++ b/mon-entreprise/cypress/integration/mon-entreprise/persistence-simulation.js @@ -0,0 +1,34 @@ +const fr = Cypress.env('language') === 'fr' +const inputSelector = 'input.currencyInput__input:not([name$="charges"])' + +describe('Persistence (simulateur salarié)', () => { + if (!fr) { + return + } + before(() => cy.visit(encodeURI('/simulateurs/salarié'))) + beforeEach(() => { + cy.clearLocalStorage() + }) + + it('should persist the current simulation (persistSimulation)', function () { + cy.get(inputSelector).first().type('{selectall}42') + cy.contains('Passer').click() + cy.contains('Passer').click() + cy.contains('Passer').click() + cy.get('body').should(() => { + expect( + window.localStorage.getItem( + 'mon-entreprise::persisted-simulation::v5::/simulateurs/salaire-brut-net' + ) + ).to.be.not.null + }) + cy.visit('/simulateurs/auto-entrepreneur') + cy.get(inputSelector).first().type('{selectall}007') + cy.contains('Passer').click() + cy.contains('Passer').click() + cy.contains('Passer').click() + cy.visit(encodeURI('/simulateurs/salarié')) + cy.contains('Retrouver ma simulation').click() + cy.get(inputSelector).first().invoke('val').should('match', /42/) + }) +}) diff --git a/mon-entreprise/cypress/integration/mon-entreprise/simulateur-ae.js b/mon-entreprise/cypress/integration/mon-entreprise/simulateur-ae.js new file mode 100644 index 000000000..708a7ad89 --- /dev/null +++ b/mon-entreprise/cypress/integration/mon-entreprise/simulateur-ae.js @@ -0,0 +1,28 @@ +const fr = Cypress.env('language') === 'fr' +const inputSelector = 'input.currencyInput__input:not([name$="charges"])' + +describe('Simulateur auto-entrepreneur', () => { + if (!fr) { + return + } + before(() => cy.visit('/simulateurs/auto-entrepreneur')) + + it('should allow to enter the date of creation', () => { + cy.get(inputSelector).first().type('{selectall}50000') + cy.contains('Passer').click() + cy.contains('Passer').click() + cy.contains('Début 2021').click() + cy.contains('ACRE') + }) + it('should not have negative value', () => { + cy.contains('Mensuel').click() + cy.wait(100) + cy.get(inputSelector).first().type('{selectall}5000') + cy.get(inputSelector).each(($input) => { + cy.wrap($input).should(($i) => { + const val = +$i.val().replace(/[\s,.]/g, '') + expect(val).not.to.be.below(4000) + }) + }) + }) +}) diff --git a/mon-entreprise/cypress/integration/mon-entreprise/simulateur-salarie.js b/mon-entreprise/cypress/integration/mon-entreprise/simulateur-salarie.js new file mode 100644 index 000000000..e41934b31 --- /dev/null +++ b/mon-entreprise/cypress/integration/mon-entreprise/simulateur-salarie.js @@ -0,0 +1,41 @@ +const fr = Cypress.env('language') === 'fr' + +describe('Simulateur salarié', () => { + if (!fr) { + return + } + before(() => cy.visit(encodeURI('/simulateurs/salarié'))) + + describe('part time contract', () => { + before(() => { + cy.visit(encodeURI('/simulateurs/salarié')) + cy.get('input[name$="brut de base"]').click() + cy.get('button').contains('SMIC').click() + cy.contains('Voir mes paramètres').click() + cy.contains('Temps partiel').click() + cy.get('input[value="oui"]').parent().click() + cy.wait(100) + }) + + it('should permit selecting the smic before part-time contrat', () => { + cy.get('input[name$="brut de base"]').should(($input) => { + expect(+$input.val().replace(/[\s,.]/g, '')) + .to.be.above(1300) + .and.to.be.below(1500) + }) + }) + + it('should permit customizing the number of worked hours and clear the input value', () => { + cy.contains('Suivant').click() + cy.get('fieldset input[type="text"]').type(25) + cy.get('input[name$="net après impôt"]').should(($input) => { + expect(+$input.val().replace(/[\s,.]/g, '')).to.be.below(1000) + }) + + cy.get('fieldset input[type="text"]').clear() + cy.get('input[name$="net après impôt"]').should(($input) => { + expect(+$input.val().replace(/[\s,.]/g, '')).to.be.above(1000) + }) + }) + }) +}) diff --git a/mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/auto-entrepreneur.js b/mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/auto-entrepreneur.js new file mode 100644 index 000000000..a0650b464 --- /dev/null +++ b/mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/auto-entrepreneur.js @@ -0,0 +1,3 @@ +import { runSimulateurTest } from '../../../support/simulateur' + +runSimulateurTest('auto-entrepreneur') diff --git a/mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/dirigeant-sasu.js b/mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/dirigeant-sasu.js new file mode 100644 index 000000000..b8fa0adc2 --- /dev/null +++ b/mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/dirigeant-sasu.js @@ -0,0 +1,3 @@ +import { runSimulateurTest } from '../../../support/simulateur' + +runSimulateurTest('dirigeant-sasu') diff --git a/mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/indépendant.js b/mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/indépendant.js new file mode 100644 index 000000000..820cb22be --- /dev/null +++ b/mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/indépendant.js @@ -0,0 +1,3 @@ +import { runSimulateurTest } from '../../../support/simulateur' + +runSimulateurTest('indépendant') diff --git a/mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/profession-liberale.js b/mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/profession-liberale.js new file mode 100644 index 000000000..58242a1fb --- /dev/null +++ b/mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/profession-liberale.js @@ -0,0 +1,3 @@ +import { runSimulateurTest } from '../../../support/simulateur' + +runSimulateurTest('profession-liberale') diff --git a/mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/profession-liberale/auxiliaire-medical.js b/mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/profession-liberale/auxiliaire-medical.js new file mode 100644 index 000000000..6ba1f1489 --- /dev/null +++ b/mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/profession-liberale/auxiliaire-medical.js @@ -0,0 +1,3 @@ +import { runSimulateurTest } from '../../../../support/simulateur' + +runSimulateurTest('profession-liberale/auxiliaire-medical') diff --git a/mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/profession-liberale/chirurgien-dentiste.js b/mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/profession-liberale/chirurgien-dentiste.js new file mode 100644 index 000000000..567d874a1 --- /dev/null +++ b/mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/profession-liberale/chirurgien-dentiste.js @@ -0,0 +1,3 @@ +import { runSimulateurTest } from '../../../../support/simulateur' + +runSimulateurTest('profession-liberale/chirurgien-dentiste') diff --git a/mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/profession-liberale/medecin.js b/mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/profession-liberale/medecin.js new file mode 100644 index 000000000..aaba909a2 --- /dev/null +++ b/mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/profession-liberale/medecin.js @@ -0,0 +1,3 @@ +import { runSimulateurTest } from '../../../../support/simulateur' + +runSimulateurTest('profession-liberale/medecin') diff --git a/mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/profession-liberale/sage-femme.js b/mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/profession-liberale/sage-femme.js new file mode 100644 index 000000000..9674099db --- /dev/null +++ b/mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/profession-liberale/sage-femme.js @@ -0,0 +1,3 @@ +import { runSimulateurTest } from '../../../../support/simulateur' + +runSimulateurTest('profession-liberale/sage-femme') diff --git a/mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/salarié.js b/mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/salarié.js new file mode 100644 index 000000000..ea222411d --- /dev/null +++ b/mon-entreprise/cypress/integration/mon-entreprise/simulateurs-generic/salarié.js @@ -0,0 +1,3 @@ +import { runSimulateurTest } from '../../../support/simulateur' + +runSimulateurTest('salarié') diff --git a/mon-entreprise/cypress/integration/mon-entreprise/simulateurs.js b/mon-entreprise/cypress/integration/mon-entreprise/simulateurs.js index 5a10c0b35..968731d52 100644 --- a/mon-entreprise/cypress/integration/mon-entreprise/simulateurs.js +++ b/mon-entreprise/cypress/integration/mon-entreprise/simulateurs.js @@ -76,128 +76,3 @@ describe('Simulateurs', function () { }) ) }) -describe('Simulateur auto-entrepreneur', () => { - if (!fr) { - return - } - before(() => cy.visit('/simulateurs/auto-entrepreneur')) - - it('should allow to enter the date of creation', () => { - cy.get(inputSelector).first().type('{selectall}50000') - cy.contains('Passer').click() - cy.contains('Passer').click() - cy.contains('Début 2021').click() - cy.contains('ACRE') - }) - it('should not have negative value', () => { - cy.contains('Mensuel').click() - cy.wait(100) - cy.get(inputSelector).first().type('{selectall}5000') - cy.wait(800) - cy.get(inputSelector).each(($input) => { - const val = +$input.val().replace(/[\s,.]/g, '') - expect(val).not.to.be.below(4000) - }) - }) -}) - -describe('Simulateur salarié mode partagé', () => { - const brutInputSelector = - 'input.currencyInput__input[name="contrat salarié . rémunération . brut de base"]' - const simulatorUrl = '/simulateurs/salaire-brut-net' - const searchParams = new URLSearchParams({ - 'contrat salarié': "'CDD'", - 'salaire-brut': '1539€/mois', - }) - searchParams.set('utm_source', 'sharing') - - const urlWithState = `${simulatorUrl}?${searchParams.toString()}` - if (!fr) { - return - } - it('should set input value from URL', function () { - cy.visit(urlWithState) - cy.wait(800) - cy.get(brutInputSelector).first().invoke('val').should('eq', '1 539') - - cy.contains('Voir mes paramètres').click() - cy.get('span.answerContent').first().contains('CDD') - }) - it('should set URL from input value', function () { - cy.visit(simulatorUrl) - cy.get(brutInputSelector).first().type('{selectall}1539') - cy.wait(1000) - cy.get('.step').find('input[value="\'CDD\'"]').click({ force: true }) - cy.wait(1000) - cy.contains('Générer un lien').click() - cy.get('.shareableLink') - .invoke('val') - .should('eq', Cypress.config().baseUrl + urlWithState) - }) -}) - -describe('Simulateur salarié', () => { - if (!fr) { - return - } - before(() => cy.visit(encodeURI('/simulateurs/salarié'))) - - it('should persist the current simulation (persistSimulation)', function () { - cy.get(inputSelector).first().type('{selectall}42') - cy.contains('Passer').click() - cy.contains('Passer').click() - cy.contains('Passer').click() - cy.wait(1600) - cy.visit('/simulateurs/auto-entrepreneur') - cy.get(inputSelector).first().type('{selectall}007') - cy.contains('Passer').click() - cy.contains('Passer').click() - cy.contains('Passer').click() - cy.wait(1600) - cy.visit(encodeURI('/simulateurs/salarié')) - cy.contains('Retrouver ma simulation').click() - cy.get(inputSelector).first().invoke('val').should('match', /42/) - }) - - it('should not crash when selecting localisation', function () { - cy.contains('Commune').click() - cy.get('fieldset input[type="search"]').type('Steenvoorde') - cy.contains('Steenvoorde (59114)').click() - cy.contains('Suivant').click() - cy.contains('Voir mes paramètres').click() - cy.contains('Steenvoorde') - }) - - describe('part time contract', () => { - before(() => { - cy.visit(encodeURI('/simulateurs/salarié')) - cy.get('input[name$="brut de base"]').click() - cy.get('button').contains('SMIC').click() - cy.contains('Voir mes paramètres').click() - cy.contains('Temps partiel').click() - cy.get('input[value="oui"]').parent().click() - cy.wait(100) - }) - - it('should permit selecting the smic before part-time contrat', () => { - cy.get('input[name$="brut de base"]').should(($input) => { - expect(+$input.val().replace(/[\s,.]/g, '')) - .to.be.above(1300) - .and.to.be.below(1500) - }) - }) - - it('should permit customizing the number of worked hours and clear the input value', () => { - cy.contains('Suivant').click() - cy.get('fieldset input[type="text"]').type(25) - cy.get('input[name$="net après impôt"]').should(($input) => { - expect(+$input.val().replace(/[\s,.]/g, '')).to.be.below(1000) - }) - - cy.get('fieldset input[type="text"]').clear() - cy.get('input[name$="net après impôt"]').should(($input) => { - expect(+$input.val().replace(/[\s,.]/g, '')).to.be.above(1000) - }) - }) - }) -}) diff --git a/mon-entreprise/cypress/integration/publi.codes/index.js b/mon-entreprise/cypress/integration/publi.codes/index.js index ba756f0c4..ffe07863d 100644 --- a/mon-entreprise/cypress/integration/publi.codes/index.js +++ b/mon-entreprise/cypress/integration/publi.codes/index.js @@ -9,7 +9,6 @@ describe('Navigation', function () { }) it('bac à sable should work', function () { cy.contains('Bac à sable').click() - cy.wait(5000) cy.contains('Dépenses primeur') cy.contains('11,50') }) diff --git a/mon-entreprise/cypress/support/simulateur.js b/mon-entreprise/cypress/support/simulateur.js new file mode 100644 index 000000000..b98bcca05 --- /dev/null +++ b/mon-entreprise/cypress/support/simulateur.js @@ -0,0 +1,68 @@ +const inputSelector = 'input.currencyInput__input:not([name$="charges"])' +const chargeInputSelector = 'input.currencyInput__input[name$="charges"]' +const fr = Cypress.env('language') === 'fr' + +export const runSimulateurTest = (simulateur) => { + if (!fr) return + + describe(`Simulateur ${simulateur}`, () => { + before(() => cy.visit(encodeURI(`/simulateurs/${simulateur}`))) + it('should not crash', function () { + cy.get(inputSelector) + }) + + it('should display a result when entering a value in any of the currency input', () => { + cy.contains('Annuel').click() + if (['indépendant', 'profession-liberale'].includes(simulateur)) { + cy.get(chargeInputSelector).type(1000) + } + cy.get(inputSelector).each(($testedInput) => { + cy.wrap($testedInput) + .type('{selectall}60111') + .and(($i) => + expect($i.val().replace(/[\s,.]/g, '')).to.match(/[1-9][\d]{3,6}$/) + ) + cy.get(inputSelector).each(($input) => { + if ($testedInput.get(0) === $input.get(0)) return + cy.wrap($input).and(($i) => { + const val = $i.val().replace(/[\s,.]/g, '') + expect(val).not.to.be.eq('60111') + expect(val).to.match(/[1-9][\d]{3,6}$/) + }) + }) + cy.contains('Cotisations') + }) + }) + + it('should allow to change period', function () { + cy.contains('Annuel').click() + cy.get(inputSelector).first().type('{selectall}12000') + if (['indépendant', 'profession-liberale'].includes(simulateur)) { + cy.get(chargeInputSelector).type('{selectall}6000') + } + cy.get(inputSelector).eq(1).invoke('val').should('not.be.empty') + cy.contains('Mensuel').click() + cy.get(inputSelector) + .first() + .invoke('val') + .should('match', /1[\s]000/) + if (['indépendant', 'profession-liberale'].includes(simulateur)) { + cy.get(chargeInputSelector).first().invoke('val').should('eq', '500') + } + cy.contains('Annuel').click() + }) + + it('should allow to navigate to a documentation page', function () { + cy.get(inputSelector).first().type('{selectall}2000') + 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('eq', '2 000') + }) + }) +}