Commit b0f8a228 authored by Cédric Girardot's avatar Cédric Girardot

Tests : Ajoute tests Cypress

Change-Id: I23e986975b782d58f465237c909198b9e2702fec
parent 2fce249f
......@@ -19,4 +19,7 @@ trim_trailing_whitespace = false
insert_final_newline = false
[*.yml]
indent_size = 2
\ No newline at end of file
indent_size = 2
[docker-compose.yml]
indent_size = 4
/.idea
.env
appli_sf/tests/E2E/cypress/screenshots/
appli_sf/tests/E2E/cypress/videos/
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 24.1.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Calque_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 372 209" style="enable-background:new 0 0 372 209;" xml:space="preserve">
<style type="text/css">
.st0{fill:#FFFFFF;}
</style>
<g id="g10" transform="matrix(1.25,0,0,-1.25,0,335)">
<g id="g6222" transform="matrix(4.8835797,0,0,4.8835797,-249.14056,-5312.4086)">
<path id="path2020" class="st0" d="M57.3,1132.5c0,1.1-1,1.9-1.9,1.9h-0.7v-3.6h0.8C56.3,1130.8,57.3,1131.5,57.3,1132.5
M60.7,1126.5c-1.5,0-2.4,1-2.6,1.2c-0.2,0.3-1.6,2.4-1.8,2.6c-0.2,0-0.3,0-0.5,0h-0.4h-0.8c0,0,0-2.8,0-3c0-0.3,0.3-0.6,0.6-0.6
v-0.1h-2.1v0.1c0.3,0,0.6,0.2,0.6,0.6v6.9c0,0.1-0.1,0.6-0.6,0.6v0.1h2.4h0.3c1.3,0,2.3-1,2.3-2.3c0-0.8-0.4-1.4-1-1.9
c0.3-0.5,1.9-3,2.1-3.2C59.5,1127.4,59.9,1126.7,60.7,1126.5"/>
<g id="path2024">
<path class="st0" d="M64.2,1130.8v-3.4c0-0.3,0.3-0.6,0.6-0.6v-0.1h-2.1v0.1c0.3,0,0.6,0.3,0.6,0.6v6.9c0,0.3-0.3,0.6-0.6,0.6
v0.1h2.1v-0.1c-0.3,0-0.6-0.3-0.6-0.6v-2.9h5.3v2.9c0,0.3-0.3,0.6-0.6,0.6v0.1H71v-0.1c-0.3,0-0.6-0.3-0.6-0.6v-6.9
c0-0.3,0.3-0.6,0.6-0.6v-0.1H69v0.1c0.3,0,0.6,0.3,0.6,0.6v3.5L64.2,1130.8z"/>
</g>
<path id="path2028" class="st0" d="M100.2,1126.5l-6.6,6.8v-5.9c0-0.3,0.3-0.6,0.6-0.6v-0.1h-1.7v0.1c0.3,0,0.6,0.3,0.6,0.6
c0,0,0,7.9,0,7.9l6.6-6.9v5.9c0,0.3-0.3,0.6-0.6,0.6v0.1h1.7v-0.1c-0.3,0-0.6-0.3-0.6-0.6V1126.5"/>
<path id="path2032" class="st0" d="M109.1,1134.4h-2.8v-3.1h2.8c0.4,0,0.5,0.3,0.5,0.6h0.1v-1.7h-0.1c0,0.3-0.2,0.6-0.5,0.6h-2.8
c0,0,0-3.2,0-3.6h2.7c0.8,0,0.9,0.5,1,0.6c0,0,0,0,0.1,0c0-0.1-0.4-0.8-0.6-1.1h-4.7v0.1c0.3,0,0.6,0.3,0.6,0.6c0,0.9,0,6.9,0,6.9
c0,0.3-0.3,0.6-0.6,0.6v0.1h5v-1.1h-0.1C109.7,1134.1,109.4,1134.4,109.1,1134.4"/>
<path id="path2036" class="st0" d="M80.6,1136.9c2.5,0,3.9-1.8,3.9-1.9c-1,0.4-1.5,0.6-2.5,0.6c-2.8,0-5.3-2.2-5.3-5.3
c0-1.3,0.6-2.5,0.7-2.6c-0.4,0-1.9,1.6-1.9,3.9C75.4,1134,77.1,1136.9,80.6,1136.9"/>
<path id="path2040" class="st0" d="M85.6,1136.2c0.4-0.3,3-2.3,2.9-5.8c0-4-3.4-6.9-6.8-6.9c-3.4,0-5.6,2.8-5.8,3.1
c0.7-0.5,2-1.7,4.7-1.7c2.9,0,6.6,2.2,6.6,6.8C87.2,1133.3,86.5,1135.2,85.6,1136.2"/>
<g id="path2044">
<polygon class="st0" points="85,1139.1 84.9,1138.9 81.6,1140.2 78.4,1138.9 78.3,1139.1 81.6,1141.6 85,1139.1 "/>
</g>
</g>
<g id="path2048">
<path class="st0" d="M185.6,109.8h9.2v2.3h-6.7v5.7h6.5v2.3h-6.5v4.1h6.7v2.3h-9.2V109.8z M165.6,124.2h3.9v-14.4h2.5v14.4h3.9
v2.3h-10.2L165.6,124.2L165.6,124.2z M150,118.9h-0.4v5.4h0.3c2.9,0,4.2-0.8,4.2-2.7C154.1,119.7,152.8,118.9,150,118.9
M156.5,121.7c0,1.7-0.9,3.3-2.3,4.1c-1.4,0.8-3.1,0.8-4.4,0.8h-2.7v-16.8h2.5v6.9h0.5c0.1-0.2,4.8-6.9,4.8-6.9h3.1
c0,0-4.9,6.7-5.2,7.2C155,117.5,156.5,119.3,156.5,121.7 M213.5,114.8c-0.4,0.9-5.7,13-5.7,13l-3.5-18h2.6c0,0,1.6,9,1.8,10.2
c0.5-1.2,4.8-10.9,4.8-10.9s4.3,9.8,4.8,10.9c0.2-1.3,1.8-10.2,1.8-10.2h2.6l-3.5,18C219.2,127.8,213.9,115.8,213.5,114.8
M127,116.3c0.2,0.6,2.2,4.9,2.5,5.7c0.4-0.8,2.3-5.2,2.5-5.7H127z M121.4,109.8h2.7c0,0,1.7,3.8,1.9,4.1h7.2
c0.1-0.3,1.9-4.1,1.9-4.1h2.7l-8.2,17.8L121.4,109.8L121.4,109.8z M264.6,114.9c-0.8,0.8-12.2,12.8-12.2,12.8v-17.9h2.5v11.8
c0.8-0.8,12.2-12.8,12.2-12.8v17.8h-2.5L264.6,114.9L264.6,114.9z M232.7,109.8h9.2v2.3h-6.7v5.7h6.5v2.3h-6.5v4.1h6.7v2.3h-9.2
L232.7,109.8L232.7,109.8z M276.7,126.6v-2.3h3.9v-14.4h2.5v14.4h3.9v2.3H276.7z M85.6,109.8h9.2v2.3h-6.7v5.7h6.5v2.3h-6.5v4.1
h6.7v2.3h-9.2L85.6,109.8L85.6,109.8z M65.4,112.2h-0.5v12.1h0.5c3.4,0,7.5-1.1,7.5-6C72.9,113.2,68.8,112.2,65.4,112.2 M66,126.6
h-3.6v-16.8H66c5.8,0,9.4,3.2,9.4,8.5C75.4,123.3,71.7,126.6,66,126.6 M13.2,126.6h-2.5v-16.8h7.5v2.3h-4.9V126.6z M108.5,118.9
h-0.4v5.3h0.3c2.1,0,4.2-0.3,4.2-2.6C112.6,119.8,111.3,118.9,108.5,118.9 M108.2,126.6h-2.6v-16.8h2.5v6.8h0.9
c3.8,0,5.9,1.8,5.9,5C115,125.1,112.9,126.6,108.2,126.6 M27.7,109.8h9.2v2.3h-6.7v5.7h6.5v2.3h-6.5v4.1h6.7v2.3h-9.2V109.8z
M92.9,131.2l-2.3,1.2l-3-4l1.3-0.8L92.9,131.2z"/>
</g>
</g>
</svg>
{
"username": "admin",
"password": "P@ssword12345"
}
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('<h1>Mes actions administrateur</h1>')
})
})
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
})
})
/// <reference types="cypress" />
// ***********************************************************
// 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
}
// ***********************************************
// 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) => { ... })
Cypress.Commands.add('loginByCSRF', (username, password, csrfToken) => {
cy.request({
method: 'POST',
url: '/login',
failOnStatusCode: false, // dont fail so we can make assertions
form: true, // we are submitting a regular form body
body: {
username: username,
password: password,
_csrf_token: csrfToken, // insert this as part of form body
},
})
})
// ***********************************************************
// This example 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 'cypress-file-upload';
// Import commands.js using ES2015 syntax:
import './commands'
// Alternatively you can use CommonJS syntax:
// require('./commands')
{
"dependencies": {
"cypress-file-upload": "^4.0.7"
}
}
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
cypress-file-upload@^4.0.7:
version "4.0.7"
resolved "https://registry.yarnpkg.com/cypress-file-upload/-/cypress-file-upload-4.0.7.tgz#1136139bb3c660b9c39a69f231ac1da7785acaae"
integrity sha512-rFFmnoZ2bWyWFpSV09AhkSUgYEiVy70pcQ6nf/mGTMTrVHvKCCCIfRu3TbgVYHbgBq+0hqjfjQrtz4IbgH7qZA==
dependencies:
mime "^2.4.4"
mime@^2.4.4:
version "2.4.6"
resolved "https://registry.yarnpkg.com/mime/-/mime-2.4.6.tgz#e5b407c90db442f2beb5b162373d07b69affa4d1"
integrity sha512-RZKhC3EmpBchfTGBVb8fb+RL2cWyw/32lshnsETttkBAyAUXSGHxbEJWWRXc751DrIxG1q04b8QwMbAwkRPpUA==
#!/bin/bash
xhost +
bin/console doctrine:fixture:load --group=use_name --no-interaction
docker-compose run --entrypoint "cypress run --project /e2e" e2e
xhost -
#!/bin/bash
xhost +
bin/console doctrine:fixture:load --group=use_name --no-interaction
docker-compose run --entrypoint "cypress open --project /e2e" e2e
xhost -
......@@ -66,6 +66,20 @@ services:
volumes:
- ./appli_sf/:/srv/
e2e:
build:
context: ./docker/cypress
depends_on:
- http
- database
- mail
environment:
- CYPRESS_baseUrl=http://${HTTP_HOSTNAME}
- DISPLAY=unix$DISPLAY
working_dir: /e2e
volumes:
- ./appli_sf/tests/E2E/:/e2e
- /tmp/.X11-unix:/tmp/.X11-unix
networks:
default:
......
FROM cypress/included:4.11.0
RUN npm install -g cypress-file-upload
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment