From fae7c67164c70f3770497d5608646188aad93875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Girardot?= Date: Thu, 30 Jul 2020 17:49:27 +0200 Subject: [PATCH] Tests : Ajoute de nouveaux tests Cypress Change-Id: Icacc3def0276976f5e04363e2d7245edd59954fa --- .gitlab-ci.yml | 5 +- Jenkinsfile.review | 7 +- appli_sf/src/DataFixtures/UserFixtures.php | 6 +- appli_sf/src/Helper/FixturesHelper.php | 1 + appli_sf/tests/E2E/cypress.json | 5 +- .../E2E/cypress/integration/1-login.spec.js | 51 ++++++++ .../E2E/cypress/integration/2-params.spec.js | 52 ++++++++ .../integration/3-search-empty-db.spec.js | 37 ++++++ .../E2E/cypress/integration/4-search.spec.js | 93 +++++++++++++ .../integration/5-create-users.spec.js | 72 ++++++++++ .../integration/6-create-instructors.spec.js | 123 ++++++++++++++++++ .../E2E/cypress/integration/7-stats.spec.js | 62 +++++++++ .../tests/E2E/cypress/integration/spec.js | 79 ----------- .../tests/E2E/cypress/support/commands.js | 72 ++++++++++ bin/cypress | 5 +- bin/cypress-gui | 3 +- 16 files changed, 586 insertions(+), 87 deletions(-) create mode 100644 appli_sf/tests/E2E/cypress/integration/1-login.spec.js create mode 100644 appli_sf/tests/E2E/cypress/integration/2-params.spec.js create mode 100644 appli_sf/tests/E2E/cypress/integration/3-search-empty-db.spec.js create mode 100644 appli_sf/tests/E2E/cypress/integration/4-search.spec.js create mode 100644 appli_sf/tests/E2E/cypress/integration/5-create-users.spec.js create mode 100644 appli_sf/tests/E2E/cypress/integration/6-create-instructors.spec.js create mode 100644 appli_sf/tests/E2E/cypress/integration/7-stats.spec.js delete mode 100644 appli_sf/tests/E2E/cypress/integration/spec.js diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 61637fd..ec77ca6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -120,12 +120,13 @@ e2e-test: cd $ADU_CI_COMPOSER_PROJECT_DIR bin/console doctrine:schema:update --force bin/console cache:clear - bin/console import:individus imports/individus.csv --use-civil-name=1 --no-interaction bin/console user:add --username=admin --password=P@ssword12345 --email=test@deptnot.test --name=Administrateur --role=ROLE_ADMIN --no-interaction symfony server:start -d cd tests/E2E yarn - cypress run + cypress run --spec "cypress/integration/1-login.spec.js,cypress/integration/2-params.spec.js,cypress/integration/3-search-empty-db.spec.js" + ../../bin/console import:individus imports/individus.csv --no-interaction --quiet + cypress run --spec "cypress/integration/4-search.spec.js,cypress/integration/5-create-users.spec.js,cypress/integration/6-create-instructors.spec.js,cypress/integration/7-stats.spec.js" build-app: stage: build diff --git a/Jenkinsfile.review b/Jenkinsfile.review index 39e8d38..2e6cb1f 100644 --- a/Jenkinsfile.review +++ b/Jenkinsfile.review @@ -94,11 +94,14 @@ pipeline { sh 'bin/console doctrine:schema:drop --force' sh 'bin/console doctrine:schema:update --force' sh 'bin/console cache:clear' - sh 'bin/console import:individus imports/individus.csv --use-civil-name=1 --no-interaction --quiet' sh 'bin/console user:add --username=admin --password=P@ssword12345 --email=test@deptnot.test --name=Administrateur --role=ROLE_ADMIN --no-interaction' dir('tests/E2E') { sh 'yarn' - sh ' cypress run' + sh 'cypress run --spec "cypress/integration/1-login.spec.js,cypress/integration/2-params.spec.js,cypress/integration/3-search-empty-db.spec.js"' + } + sh 'bin/console import:individus imports/individus.csv --no-interaction --quiet' + dir('tests/E2E') { + sh 'cypress run --spec "cypress/integration/4-search.spec.js,cypress/integration/5-create-users.spec.js,cypress/integration/6-create-instructors.spec.js,cypress/integration/7-stats.spec.js"' } } } diff --git a/appli_sf/src/DataFixtures/UserFixtures.php b/appli_sf/src/DataFixtures/UserFixtures.php index a049e24..ad8e152 100644 --- a/appli_sf/src/DataFixtures/UserFixtures.php +++ b/appli_sf/src/DataFixtures/UserFixtures.php @@ -23,7 +23,11 @@ class UserFixtures extends \Doctrine\Bundle\FixturesBundle\Fixture implements Fi public static function getGroups(): array { - return [FixturesHelper::GROUP_USE_NAME, FixturesHelper::GROUP_CIVIL_NAME]; + return [ + FixturesHelper::GROUP_WITHOUT_PERSONS, + FixturesHelper::GROUP_USE_NAME, + FixturesHelper::GROUP_CIVIL_NAME, + ]; } /** diff --git a/appli_sf/src/Helper/FixturesHelper.php b/appli_sf/src/Helper/FixturesHelper.php index b192f68..b7b46ba 100644 --- a/appli_sf/src/Helper/FixturesHelper.php +++ b/appli_sf/src/Helper/FixturesHelper.php @@ -7,4 +7,5 @@ class FixturesHelper const GROUP_USE_NAME = 'use_name'; const GROUP_CIVIL_NAME = 'civil_name'; const GROUP_USERS = 'users'; + const GROUP_WITHOUT_PERSONS = 'without_persons'; } diff --git a/appli_sf/tests/E2E/cypress.json b/appli_sf/tests/E2E/cypress.json index 0db3279..2c9ef54 100644 --- a/appli_sf/tests/E2E/cypress.json +++ b/appli_sf/tests/E2E/cypress.json @@ -1,3 +1,6 @@ { - + "nodeVersion": "system", + "browser": { + "chromeWebSecurity": false + } } diff --git a/appli_sf/tests/E2E/cypress/integration/1-login.spec.js b/appli_sf/tests/E2E/cypress/integration/1-login.spec.js new file mode 100644 index 0000000..445b9bc --- /dev/null +++ b/appli_sf/tests/E2E/cypress/integration/1-login.spec.js @@ -0,0 +1,51 @@ +Cypress.on('uncaught:exception', (err, runnable) => { + // returning false here prevents Cypress from + // failing the test + return false +}) + +describe('Connexion avec CSRF', () => { + const inAdministration = () => { + cy.location('href').should('match', /admin\/?$/) + cy.contains('Mes actions administrateur') + } + + const visitAdministration = () => { + cy.visit('/admin') + inAdministration() + } + + beforeEach(function () { + cy.fixture('user-admin') + .then((user) => { + this.userAdmin = user + }) + }) + + it('Redirection vers la page de login', () => { + cy.visit('/') + + cy.location('href').should('match', /login$/) + cy.contains('Départements et Notaires') + }) + + it('Erreur si pas de CSRF', function () { + cy.loginByCSRF(this.userAdmin.username, this.userAdmin.password, 'invalid-token') + .its('status') + .should('eq', 200) + .location('href').should('match', /login$/) + }) + + it('Connexion en tant qu\'admin', function () { + cy.login(this.userAdmin.username, this.userAdmin.password) + + visitAdministration() + }) + + it('Déconnexion', () => { + cy.logout() + + cy.location('href').should('match', /login$/) + cy.contains('Départements et Notaires') + }) +}) diff --git a/appli_sf/tests/E2E/cypress/integration/2-params.spec.js b/appli_sf/tests/E2E/cypress/integration/2-params.spec.js new file mode 100644 index 0000000..a4bd618 --- /dev/null +++ b/appli_sf/tests/E2E/cypress/integration/2-params.spec.js @@ -0,0 +1,52 @@ +Cypress.on('uncaught:exception', (err, runnable) => { + // returning false here prevents Cypress from + // failing the test + return false +}) + +describe('Paramètres de l\'application', () => { + beforeEach(function () { + cy.fixture('user-admin') + .then((user) => { + this.userAdmin = user + }) + Cypress.Cookies.preserveOnce('PHPSESSID') + }) + + it('Login', function () { + cy.login(this.userAdmin.username, this.userAdmin.password) + }) + + it('Page des paramètres', () => { + cy.visit('/admin/params') + + cy.location('href').should('match', /admin\/params\/?$/) + cy.contains('Paramètres de l\'application') + }) + + it('Définir nom de l\'application', () => { + cy.get('input#settings_appName').type('D&N') + cy.get('form[name=settings]').submit() + + cy.contains('Les paramètres ont été modifiés.') + }) + + it('Ajouter un logo', () => { + cy.fixture('images/logo-rhone-blanc.svg').then(fileContent => { + cy.get('input[type="file"]#settings_appLogo').attachFile({ + fileContent: fileContent.toString(), + fileName: 'logo-rhone-blanc.svg', + mimeType: 'image/svg+xml' + }); + }); + + cy.get('form[name=settings]').submit() + + cy.get('input#settings_appLogo').parent().next().should('have.class', 'image-preview') + cy.get('a.logo-department').children().should('have.length', 1) // le logo s'affiche + }) + + it('Déconnexion', () => { + cy.logout() + }) +}) diff --git a/appli_sf/tests/E2E/cypress/integration/3-search-empty-db.spec.js b/appli_sf/tests/E2E/cypress/integration/3-search-empty-db.spec.js new file mode 100644 index 0000000..719bd9b --- /dev/null +++ b/appli_sf/tests/E2E/cypress/integration/3-search-empty-db.spec.js @@ -0,0 +1,37 @@ +Cypress.on('uncaught:exception', (err, runnable) => { + // returning false here prevents Cypress from + // failing the test + return false +}) + +describe('Recherche avec table individu vide', () => { + beforeEach(function () { + cy.fixture('user-admin') + .then((user) => { + this.userAdmin = user + }) + Cypress.Cookies.preserveOnce('PHPSESSID') + }) + + it('Login', function () { + cy.login(this.userAdmin.username, this.userAdmin.password) + }) + + it('Personne connue, aide récupérable', () => { + cy.visit('/search') + cy.fillSearch({ + deathDate: '10/02/2020', + deathLocation: 'VILLEFRANCHE', + deathCertificateDate: '12/02/2020', + firstName: 'Aimé', + useName: 'OLMO', + birthDate: '06/12/1977' + }) + + cy.contains('Cette personne est inconnue de nos services') + }) + + it('Déconnexion', () => { + cy.logout() + }) +}) diff --git a/appli_sf/tests/E2E/cypress/integration/4-search.spec.js b/appli_sf/tests/E2E/cypress/integration/4-search.spec.js new file mode 100644 index 0000000..fba0a6b --- /dev/null +++ b/appli_sf/tests/E2E/cypress/integration/4-search.spec.js @@ -0,0 +1,93 @@ +Cypress.on('uncaught:exception', (err, runnable) => { + // returning false here prevents Cypress from + // failing the test + return false +}) + +describe('Recherche', () => { + beforeEach(function () { + cy.fixture('user-admin') + .then((user) => { + this.userAdmin = user + }) + Cypress.Cookies.preserveOnce('PHPSESSID') + }) + + it('Login', function () { + cy.login(this.userAdmin.username, this.userAdmin.password) + }) + + it('Personne connue, aide récupérable', () => { + cy.visit('/search') + cy.fillSearch({ + deathDate: '10/02/2020', + deathLocation: 'VILLEFRANCHE', + deathCertificateDate: '12/02/2020', + firstName: 'Aimé', + useName: 'OLMO', + birthDate: '06/12/1977' + }) + + cy.contains('Cette personne est connue de nos services') + }) + + it('Personne connue, aide non récupérable', () => { + cy.visit('/search') + cy.fillSearch({ + deathDate: '10/02/2020', + deathLocation: 'VILLEFRANCHE', + deathCertificateDate: '12/02/2020', + firstName: 'Maesson', + useName: 'ALOUANE', + birthDate: '03/12/1954' + }) + + cy.contains('Cette personne est connue de nos services') + }) + + it('Personne inconnue', () => { + cy.visit('/search') + cy.fillSearch({ + deathDate: '10/02/2020', + deathLocation: 'VILLEFRANCHE', + deathCertificateDate: '12/02/2020', + firstName: 'Mickael', + useName: 'Dupont', + birthDate: '07/08/1986' + }) + + cy.contains('Cette personne est inconnue de nos services') + }) + + it('Personne inconnue, demande en cours d\'instruction', () => { + cy.visit('/search') + cy.fillSearch({ + deathDate: '10/02/2020', + deathLocation: 'VILLEFRANCHE', + deathCertificateDate: '12/02/2020', + firstName: 'Yvette', + useName: 'ROSA', + birthDate: '08/12/1968' + }) + + cy.contains('Cette personne est inconnue de nos services') + }) + + it('Resultat ambigu', () => { + cy.visit('/search') + cy.fillSearch({ + deathDate: '10/02/2020', + deathLocation: 'VILLEFRANCHE', + deathCertificateDate: '12/02/2020', + firstName: 'Clara', + useName: 'BOURDIAU', + birthDate: '01/09/1966' + }) + + cy.contains('Les éléments que vous avez saisis ne permettent pas d\'établir avec certitude l\'identité') + }) + + it('Déconnexion', () => { + cy.logout() + }) +}) diff --git a/appli_sf/tests/E2E/cypress/integration/5-create-users.spec.js b/appli_sf/tests/E2E/cypress/integration/5-create-users.spec.js new file mode 100644 index 0000000..524c1bd --- /dev/null +++ b/appli_sf/tests/E2E/cypress/integration/5-create-users.spec.js @@ -0,0 +1,72 @@ +Cypress.on('uncaught:exception', (err, runnable) => { + // returning false here prevents Cypress from + // failing the test + return false +}) + +describe('Recherche', () => { + beforeEach(function () { + cy.fixture('user-admin') + .then((user) => { + this.userAdmin = user + }) + Cypress.Cookies.preserveOnce('PHPSESSID') + }) + + it('Login', function () { + cy.login(this.userAdmin.username, this.userAdmin.password) + }) + + it('Création d\'un utilisateur avec profil admin', () => { + cy.visit('/admin/user/add') + cy.fillUser({ + role: 'ROLE_ADMIN', + username: 'admin-test', + email: 'admin-test@notaire.fr', + name: 'Compte admin de test' + }) + + cy.contains('Gérer les utilisateurs') + cy.get('table.users-table tr').last().find('td').eq(3).should('have.text', 'admin-test') + cy.get('table.users-table tr').last().find('td').eq(4).contains('admin-test@notaire.fr') + cy.get('table.users-table tr').last().find('td').eq(6).should('have.text', 'Administrateur') + }) + + it('Création d\'un utilisateur avec profil agent', () => { + cy.visit('/admin/user/add') + cy.fillUser({ + role: 'ROLE_AGENT', + username: 'agent-test', + email: 'agent-test@notaire.fr', + name: 'Compte agent de test' + }) + + cy.contains('Gérer les utilisateurs') + cy.get('table.users-table tr').last().find('td').eq(3).should('have.text', 'agent-test') + cy.get('table.users-table tr').last().find('td').eq(4).contains('agent-test@notaire.fr') + cy.get('table.users-table tr').last().find('td').eq(6).should('have.text', 'Agent du département') + }) + + it('Création d\'un utilisateur avec profil notaire', () => { + cy.visit('/admin/user/add') + cy.fillUser({ + role: 'ROLE_NOTARY', + username: '1', + email: 'etude-test@notaire.fr', + name: 'étude', + address: 'Place de la République', + additionalAddress: '2° étage', + postalCode: '34000', + town: 'Montpellier' + }) + + cy.contains('Gérer les utilisateurs') + cy.get('table.users-table tr').last().find('td').eq(3).should('have.text', '1') + cy.get('table.users-table tr').last().find('td').eq(4).contains('etude-test@notaire.fr') + cy.get('table.users-table tr').last().find('td').eq(6).should('have.text', 'Etude notariale') + }) + + it('Déconnexion', () => { + cy.logout() + }) +}) diff --git a/appli_sf/tests/E2E/cypress/integration/6-create-instructors.spec.js b/appli_sf/tests/E2E/cypress/integration/6-create-instructors.spec.js new file mode 100644 index 0000000..01e89e9 --- /dev/null +++ b/appli_sf/tests/E2E/cypress/integration/6-create-instructors.spec.js @@ -0,0 +1,123 @@ +Cypress.on('uncaught:exception', (err, runnable) => { + // returning false here prevents Cypress from + // failing the test + return false +}) + +describe('Recherche', () => { + beforeEach(function () { + cy.fixture('user-admin') + .then((user) => { + this.userAdmin = user + }) + Cypress.Cookies.preserveOnce('PHPSESSID') + }) + + it('Login', function () { + cy.login(this.userAdmin.username, this.userAdmin.password) + }) + + it('Création d\'un premier instructeur', () => { + cy.visit('/admin/instructor/add') + cy.fillInstructor({ + firstName: 'instructeur', + lastName: 'AMBIGU', + email: 'instructeur1@notaire.fr', + phone: '06 06 06 06 06', + responseTypes: [2], + initials: 'A-Z' + }) + + cy.contains('Gérer les instructeurs') + cy.get('table.users-table tr').last().find('td').eq(2).should('have.text', 'instructeur') + cy.get('table.users-table tr').last().find('td').eq(3).should('have.text', 'AMBIGU') + cy.get('table.users-table tr').last().find('td').eq(4).contains('instructeur1@notaire.fr') + cy.get('table.users-table tr').last().find('td').eq(6).contains('Ambigu') + cy.get('table.users-table tr').last().find('td').eq(7).should('have.text', 'A-Z') + }) + + it('Recherche d\'une personne avec résultat ambigu', () => { + cy.visit('/search') + cy.fillSearch({ + deathDate: '10/02/2020', + deathLocation: 'VILLEFRANCHE', + deathCertificateDate: '12/02/2020', + firstName: 'Clara', + useName: 'BOURDIAU', + birthDate: '01/09/1966' + }) + + cy.get('body').should('not.contain', 'Nous n\'avons pas trouvé d\'instructeur associé à votre requête') + }) + + it('Création d\'un second instructeur', () => { + cy.visit('/admin/instructor/add') + cy.fillInstructor({ + firstName: 'instructeur', + lastName: 'RECUPERATION', + email: 'instructeur2@notaire.fr', + phone: '06 06 06 06 06', + responseTypes: [0], + initials: 'A-Z' + }) + + cy.contains('Gérer les instructeurs') + cy.get('table.users-table tr').last().find('td').eq(2).should('have.text', 'instructeur') + cy.get('table.users-table tr').last().find('td').eq(3).should('have.text', 'RECUPERATION') + cy.get('table.users-table tr').last().find('td').eq(4).contains('instructeur2@notaire.fr') + cy.get('table.users-table tr').last().find('td').eq(6).contains('Récupération') + cy.get('table.users-table tr').last().find('td').eq(7).should('have.text', 'A-Z') + }) + + it('Recherche d\'une personne avec récupération', () => { + cy.visit('/search') + cy.fillSearch({ + deathDate: '10/02/2020', + deathLocation: 'VILLEFRANCHE', + deathCertificateDate: '12/02/2020', + firstName: 'Aime', + useName: 'OLMO', + birthDate: '06/12/1977' + }) + + cy.get('body').should('not.contain', 'Nous n\'avons pas trouvé d\'instructeur associé à votre requête') + }) + + it('Création d\'un instructeur multi-réponses et initiales communes avec un autre instructeur', () => { + cy.visit('/admin/instructor/add') + cy.fillInstructor({ + firstName: 'instructeur', + lastName: 'AMBIGU2', + email: 'instructeur3@notaire.fr', + phone: '06 06 06 06 06', + responseTypes: [0,2], + initials: 'M-Z' + }) + + cy.contains('Gérer les instructeurs') + cy.get('table.users-table tr').last().find('td').eq(2).should('have.text', 'instructeur') + cy.get('table.users-table tr').last().find('td').eq(3).should('have.text', 'AMBIGU2') + cy.get('table.users-table tr').last().find('td').eq(4).contains('instructeur3@notaire.fr') + cy.get('table.users-table tr').last().find('td').eq(6).contains('Récupération') + cy.get('table.users-table tr').last().find('td').eq(6).contains('Ambigu') + cy.get('table.users-table tr').last().find('td').eq(7).should('have.text', 'M-Z') + }) + + it('Recherche d\'une personne avec résultat ambigu', () => { + cy.visit('/search') + cy.fillSearch({ + deathDate: '10/02/2020', + deathLocation: 'VILLEFRANCHE', + deathCertificateDate: '12/02/2020', + firstName: 'Clara', + useName: 'BOURDIAU', + birthDate: '01/09/1966' + }) + + cy.get('body').should('not.contain', 'Nous n\'avons pas trouvé d\'instructeur associé à votre requête') + }) + + it('Déconnexion', () => { + cy.logout() + }) +}) diff --git a/appli_sf/tests/E2E/cypress/integration/7-stats.spec.js b/appli_sf/tests/E2E/cypress/integration/7-stats.spec.js new file mode 100644 index 0000000..3a3c852 --- /dev/null +++ b/appli_sf/tests/E2E/cypress/integration/7-stats.spec.js @@ -0,0 +1,62 @@ +Cypress.on('uncaught:exception', (err, runnable) => { + // returning false here prevents Cypress from + // failing the test + return false +}) + +describe('Recherche', () => { + beforeEach(function () { + cy.fixture('user-admin') + .then((user) => { + this.userAdmin = user + }) + Cypress.Cookies.preserveOnce('PHPSESSID') + }) + + it('Login', function () { + cy.login(this.userAdmin.username, this.userAdmin.password) + }) + + it('Affichage 5 derniers mois', () => { + Cypress.moment.locale('fr') + const monthFormat = 'MMMM-YY' + const currentMonth = Cypress.moment().startOf('month') + + cy.visit('/stats') + + // Nombre de mois affichés + cy.get('table.stats-table thead th').eq(1).should('have.text', currentMonth.format(monthFormat)) + cy.get('table.stats-table thead th').eq(2).should('have.text', currentMonth.subtract(1, 'months').format(monthFormat)) + cy.get('table.stats-table thead th').eq(3).should('have.text', currentMonth.subtract(1, 'months').format(monthFormat)) + cy.get('table.stats-table thead th').eq(4).should('have.text', currentMonth.subtract(1, 'months').format(monthFormat)) + cy.get('table.stats-table thead th').eq(5).should('have.text', currentMonth.subtract(1, 'months').format(monthFormat)) + }) + + it('Incrémentation nombre de recherches', () => { + cy.visit('/stats') + + // Nombre de réponses + cy.get('table.stats-table tbody').then((statsTableBody) => { + const nbResponses = parseInt(statsTableBody.find('tr').eq(1).find('td').eq(1).text().trim()) + const nbResponsesRecup = parseInt(statsTableBody.find('tr').eq(2).find('td').eq(1).text().trim()) + + cy.visit('/search') + cy.fillSearch({ + deathDate: '10/02/2020', + deathLocation: 'VILLEFRANCHE', + deathCertificateDate: '12/02/2020', + firstName: 'Aimé', + useName: 'OLMO', + birthDate: '06/12/1977' + }) + + cy.visit('/stats') + cy.get('table.stats-table tbody tr').eq(1).find('td').eq(1).contains(nbResponses + 1) + cy.get('table.stats-table tbody tr').eq(2).find('td').eq(1).contains(nbResponsesRecup + 1) + }) + }) + + it('Déconnexion', () => { + cy.logout() + }) +}) diff --git a/appli_sf/tests/E2E/cypress/integration/spec.js b/appli_sf/tests/E2E/cypress/integration/spec.js deleted file mode 100644 index b2cc30d..0000000 --- a/appli_sf/tests/E2E/cypress/integration/spec.js +++ /dev/null @@ -1,79 +0,0 @@ -Cypress.on('uncaught:exception', (err, runnable) => { - // returning false here prevents Cypress from - // failing the test - return false -}) - -describe('Connexion avec CSRF', () => { - const inAdministration = () => { - cy.location('href').should('match', /admin\/?$/) - cy.contains('Mes actions administrateur') - } - - const visitAdministration = () => { - cy.visit('/admin') - inAdministration() - } - - beforeEach(function () { - cy.fixture('user-admin') - .then((user) => { - this.userAdmin = user - }) - }) - - it('Redirection vers la page de login', () => { - cy.visit('/') - - cy.location('href').should('match', /login$/) - cy.contains('Départements et Notaires') - }) - - it('Erreur si pas de CSRF', function () { - cy.loginByCSRF(this.userAdmin.username, this.userAdmin.password, 'invalid-token') - .its('status') - .should('eq', 200) - .location('href').should('match', /login$/) - }) - - it('Connexion en tant qu\'admin', function () { - cy.request('/login') - .its('body') - .then((body) => { - const $html = Cypress.$(body) - const csrf = $html.find('input[name=_csrf_token]').val() - - cy.loginByCSRF(this.userAdmin.username, this.userAdmin.password, csrf) - .then((resp) => { - expect(resp.status).to.eq(200) - expect(resp.body).to.include('

Mes actions administrateur

') - }) - }) - - visitAdministration() - Cypress.Cookies.preserveOnce('PHPSESSID') - }) - - -}) - -describe('Ajout d\'un logo', () => { - it('Modification paramètres application', function () { - cy.visit('/admin/params') - cy.location('href').should('match', /admin\/params\/?$/) - cy.contains('Paramètres de l\'application') - cy.get('input#settings_appName').type('D&N') - cy.fixture('images/logo-rhone-blanc.svg').then(fileContent => { - cy.get('input[type="file"]#settings_appLogo').attachFile({ - fileContent: fileContent.toString(), - fileName: 'logo-rhone-blanc.svg', - mimeType: 'image/svg+xml' - }); - }); - cy.get('form[name=settings]').submit() - - cy.contains('Les paramètres ont été modifiés.') - cy.get('input#settings_appLogo').parent().next().should('have.class', 'image-preview') - cy.get('a.logo-department').children().should('have.length', 1) // le logo s'affiche - }) -}) diff --git a/appli_sf/tests/E2E/cypress/support/commands.js b/appli_sf/tests/E2E/cypress/support/commands.js index 4895f50..52ab21b 100644 --- a/appli_sf/tests/E2E/cypress/support/commands.js +++ b/appli_sf/tests/E2E/cypress/support/commands.js @@ -36,3 +36,75 @@ Cypress.Commands.add('loginByCSRF', (username, password, csrfToken) => { }, }) }) + +Cypress.Commands.add('login', (username, password) => { + cy.request('/login') + .its('body') + .then((body) => { + const $html = Cypress.$(body) + const csrf = $html.find('input[name=_csrf_token]').val() + + cy.loginByCSRF(username, password, csrf) + .then((resp) => { + expect(resp.status).to.eq(200) + expect(resp.body).to.include('

Mes actions administrateur

') + }) + }) + + Cypress.Cookies.preserveOnce('PHPSESSID') +}) + +Cypress.Commands.add('logout', () => { + cy.visit('/logout') +}) + +Cypress.Commands.add('fillSearch', (values) => { + cy.get('input#search_deathDate').type(values.deathDate) + cy.get('input#search_deathLocation').type(values.deathLocation) + cy.get('input#search_deathCertificateDate').type(values.deathCertificateDate) + cy.get('input#search_firstName').type(values.firstName) + cy.get('input#search_useName').type(values.useName) + cy.get('input#search_birthDate').type(values.birthDate) + cy.get('form[name=search]').submit() +}) + +Cypress.Commands.add('fillUser', (values) => { + cy.get('select#user_roles').select(values.role) + cy.wait(2000) + cy.get('input#user_username').type(values.username) + cy.get('input#user_email').type(values.email) + cy.get('input#user_name').type(values.name) + if (values.address) { + cy.get('input#user_address').type(values.address) + } + if (values.additionalAddress) { + cy.get('input#user_additionalAddress').type(values.additionalAddress) + } + if (values.postalCode) { + cy.get('input#user_postalCode').type(values.postalCode) + } + if (values.town) { + cy.get('input#user_town').type(values.town) + } + if (values.service) { + cy.get('input#user_service').type(values.service) + } + cy.get('form[name=user]').submit() +}) + +Cypress.Commands.add('fillInstructor', (values) => { + cy.get('input#instructor_firstName').type(values.firstName) + cy.get('input#instructor_lastName').type(values.lastName) + cy.get('input#instructor_email').type(values.email) + if (values.phone) { + cy.get('input#instructor_phone').type(values.phone) + } + values.responseTypes.forEach((responseType) => { + cy.get('input#instructor_responseType_' + responseType).check().should('be.checked') + }) + if (values.initials) { + cy.get('input#instructor_initials').type(values.initials) + } + + cy.get('form[name=instructor]').submit() +}) diff --git a/bin/cypress b/bin/cypress index 2155c07..90dc0b0 100755 --- a/bin/cypress +++ b/bin/cypress @@ -1,6 +1,9 @@ #!/bin/bash +set -e xhost + +bin/console doctrine:fixture:load --group=without_persons --no-interaction +docker-compose run --rm --entrypoint "cypress run --project /e2e --spec \"/e2e/cypress/integration/1-login.spec.js,/e2e/cypress/integration/2-params.spec.js,/e2e/cypress/integration/3-search-empty-db.spec.js\"" e2e bin/console doctrine:fixture:load --group=use_name --no-interaction -docker-compose run --entrypoint "cypress run --project /e2e" e2e +docker-compose run --rm --no-deps --entrypoint "cypress run --project /e2e --spec \"/e2e/cypress/integration/4-search.spec.js,/e2e/cypress/integration/5-create-users.spec.js,/e2e/cypress/integration/6-create-instructors.spec.js,/e2e/cypress/integration/7-stats.spec.js\"" e2e xhost - diff --git a/bin/cypress-gui b/bin/cypress-gui index 506487c..fac21d8 100755 --- a/bin/cypress-gui +++ b/bin/cypress-gui @@ -1,6 +1,7 @@ #!/bin/bash +set -e xhost + bin/console doctrine:fixture:load --group=use_name --no-interaction -docker-compose run --entrypoint "cypress open --project /e2e" e2e +docker-compose run --rm --entrypoint "cypress open --project /e2e" e2e xhost - -- GitLab