diff --git a/.gitignore b/.gitignore index 4cee2dc132860a815a76083f293e1f1f101f71d9..b0e4b82d7b8c3b946ae77edf3f21f20fe8d2a1b8 100755 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ apps/maarch_entreprise/xml/mailevaConfig.xml apps/maarch_entreprise/xml/log4php.xml *.log test/unitTests/build/ +cypress/ modules/visa/xml/remoteSignatoryBooks.xml dist/ node_modules/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c54d83dc41c6f6c5b18613d2bdcdc1591109cde3..685ea573be0070f80023096a03c433303e19ce6a 100755 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -47,22 +47,13 @@ job_e2e: image: php:7.4-apache stage: test script: - - service apache2 start - - touch installed.lck - - chown -R www-data. /opt/maarch/ - - chown -R www-data. /var/www/html/ - - chmod -R 775 /opt/maarch/ - - chmod -R 775 /var/www/html/ - curl -sL https://deb.nodesource.com/setup_14.x | bash - > /dev/null - apt-get install -yqq nodejs > /dev/null - npm install npm@latest -g - node -v - npm set registry https://registry.npmjs.org/ - npm install > /dev/null - - npm run build-prod - - curl -o /dev/null --silent --head --write-out '%{http_code}\n' http://127.0.0.1/MaarchCourrier - - firefox --version - - npm run ee-launch + - npm run cypress:run artifacts: paths: - queries_error.log diff --git a/package.json b/package.json index e50b1fb5052aea08cfb7d55de789eea9923aac72..6dfe82a64ce546257dc4704c29e0462e6a764d8c 100755 --- a/package.json +++ b/package.json @@ -12,10 +12,8 @@ "upgrade": "ncu -u", "create-component": "echo Component name ? && read varname && ng g c $varname --module app --style=scss", "create-component-admin": "echo Component name ? && read varname && ng g c administration/$varname --module administration --style=scss", - "ee-launch": "webdriver-manager update && webdriver-manager start --detach && protractor test/e2e/conf.js && webdriver-manager shutdown && fuser -k 4444/tcp", - "ee-update": "webdriver-manager update", - "ee-start-server": "webdriver-manager start", - "ee-test": "protractor test/e2e/conf.js" + "cypress:open": "cypress open --config-file test/e2e/cypress-config.json", + "cypress:run": "cypress run --browser firefox --headless --config-file test/e2e/cypress-config.json" }, "keywords": [], "author": "Maarch", @@ -53,6 +51,7 @@ "bootstrap": "^3.4.1", "chosen-js": "^1.8.7", "codelyzer": "^6.0.1", + "cypress": "^6.2.1", "flat-to-nested": "^1.1.0", "hammerjs": "^2.0.8", "html-minifier": "^4.0.0", @@ -71,7 +70,6 @@ "npm-check-updates": "^9.2.4", "pdfjs-dist": "2.5.207", "photoswipe": "^4.1.3", - "protractor": "^7.0.0", "rxjs": "^6.6.3", "tinymce": "^5.6.1", "tinymce-i18n": "^20.12.25", diff --git a/test/e2e/about-us-spec.js b/test/e2e/about-us-spec.js deleted file mode 100644 index 6ee5a359c0ddb204990e96b07f603ff10e62e083..0000000000000000000000000000000000000000 --- a/test/e2e/about-us-spec.js +++ /dev/null @@ -1,9 +0,0 @@ -describe('about-us page', function() { - it('test page', function() { - browser.sleep(2000); - element(by.css('[title="Accueil"]')).click(); - - browser.sleep(2000); - }); -}); - diff --git a/test/e2e/conf.js b/test/e2e/conf.js deleted file mode 100644 index d75fd5b729b343a978d320ac0df85a476c2fd0d3..0000000000000000000000000000000000000000 --- a/test/e2e/conf.js +++ /dev/null @@ -1,31 +0,0 @@ -exports.config = { - baseUrl: 'http://127.0.0.1/MaarchCourrier', - seleniumAddress: 'http://localhost:4444/wd/hub', - specs: [ - 'login-spec.js', - 'index-resource-spec.js', - //'about-us-spec.js' - ], - multiCapabilities: [ - { - 'browserName': 'chrome', - 'chromeOptions': { - 'args': ["--no-sandbox", "--headless", "--disable-gpu", "--window-size=1920,1080"] - }, - }, - { - 'browserName': 'firefox', - 'moz:firefoxOptions': { - 'args': ["--headless", "--width=1920", "--height=1080"] - } - } - ], - chromeDriver: '/usr/bin/chromedriver', - maxSessions: 1, - - onPrepare: () => { - browser.driver.getCapabilities().then(function(caps){ - browser.browserName = caps.get('browserName'); - }); - } -}; diff --git a/test/e2e/cypress-config.json b/test/e2e/cypress-config.json new file mode 100644 index 0000000000000000000000000000000000000000..2b2af4e7ac739244eb8b5b84b618c808e9df5da2 --- /dev/null +++ b/test/e2e/cypress-config.json @@ -0,0 +1,6 @@ +{ + "baseUrl": "https://demo.maarchcourrier.com/dist/index.html#/", + "integrationFolder" : "test/e2e", + "testFiles" : "**/*.spec.ts", + "supportFile" : "test/e2e/support" +} \ No newline at end of file diff --git a/test/e2e/index-resource-spec.js b/test/e2e/index-resource-spec.js deleted file mode 100644 index 4cd380da70b9801e5d200b45b5dde3b0dc154f87..0000000000000000000000000000000000000000 --- a/test/e2e/index-resource-spec.js +++ /dev/null @@ -1,60 +0,0 @@ -var ScreenshotReporter = require('./screenshotReporter.js'); - -afterEach(function() { - if (browser.browserName === 'chrome') { - browser.manage().logs().get('browser').then(function(browserLog) { - console.log('log: ' + require('util').inspect(browserLog)); - }); - } -}); - -describe('index resource page', function () { - it('index a document whitout file', function () { - browser.sleep(2000); - expect(browser.getCurrentUrl()).toEqual(browser.baseUrl + "/dist/index.html#/home"); - browser.takeScreenshot().then(function (png) { - ScreenshotReporter(png, 'test/e2e/screenshots/home_' + browser.browserName); - }); - element(by.id('indexing')).click(); - browser.sleep(500); - browser.takeScreenshot().then(function (png) { - ScreenshotReporter(png, 'test/e2e/screenshots/index_a_document_' + browser.browserName); - }); - element(by.id('doctype')).click(); - browser.sleep(500); - element(by.css('[title="Demande de renseignements"]')).click(); - browser.sleep(500); - element(by.id('priority')).click(); - browser.sleep(500); - element(by.css('[title="Normal"]')).click(); - browser.sleep(500); - element(by.id('documentDate')).click(); - browser.sleep(500); - element(by.css('.mat-calendar-body-active')).click(); - browser.sleep(500); - element(by.id('subject')).sendKeys('test ee'); - browser.sleep(500); - element(by.id('senders')).sendKeys('pascon'); - browser.sleep(1000); - element(by.id('senders-6')).click(); - browser.sleep(500); - element(by.id('destination')).click(); - browser.sleep(500); - element(by.css('[title="Pôle Jeunesse et Sport"]')).click(); - browser.sleep(500); - element(by.cssContainingText('.mat-button-wrapper', 'Valider')).click(); - browser.sleep(500); - element(by.cssContainingText('.mat-button-wrapper', 'Ok')).click(); - browser.sleep(500); - element(by.css('[placeholder="Ajouter une annotation"]')).sendKeys('test ee'); - browser.sleep(500); - element(by.cssContainingText('.mat-dialog-content-container .mat-button-wrapper', 'Valider')).click(); - browser.sleep(100); - browser.takeScreenshot().then(function (png) { - ScreenshotReporter(png, 'test/e2e/screenshots/validate_indexation_' + browser.browserName); - }); - browser.sleep(500); - expect(browser.getCurrentUrl()).toContain('/resources/'); - browser.sleep(4000); - }); -}); diff --git a/test/e2e/indexing.spec.ts b/test/e2e/indexing.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..75af659f3471fd76425b8c6cdd655c6bcc1179f5 --- /dev/null +++ b/test/e2e/indexing.spec.ts @@ -0,0 +1,49 @@ +describe('Indexing document EE', () => { + it('Record incoming mail', () => { + cy.login(); + cy.visit('home') + cy.wait(500) + cy.get('#indexing') + .click() + cy.get('#doctype') + .click() + cy.wait(500) + cy.get('[title="Demande de renseignements"]') + .click({force: true}); + cy.get('#priority') + .click() + cy.get('[title="Normal"]') + .click({force: true}) + cy.get('#documentDate') + .click() + cy.get('.mat-calendar-body-active') + .click(); + cy.get('#subject') + .type('test ee') + cy.get('#senders') + .type('pascon') + cy.get('#senders-6') + .click() + cy.get('#destination') + .click() + cy.wait(500) + cy.get('[title="Pôle Jeunesse et Sport"]') + .click({force: true}); + cy.wait(500) + cy.get('.mat-button-wrapper') + .contains('Valider') + .click() + cy.wait(500) + cy.get('.mat-button-wrapper') + .contains('Ok') + .click() + cy.wait(500) + cy.get('[placeholder="Ajouter une annotation"]') + .type('test ee') + cy.get('.mat-dialog-content-container .mat-button-wrapper') + .contains('Valider') + .click() + cy.wait(500) + cy.url().should('include', '/resources/') + }) +}) \ No newline at end of file diff --git a/test/e2e/login-spec.js b/test/e2e/login-spec.js deleted file mode 100644 index b669a6983ddfcec8ab8da8e9075f60e1c59df380..0000000000000000000000000000000000000000 --- a/test/e2e/login-spec.js +++ /dev/null @@ -1,61 +0,0 @@ -var ScreenshotReporter = require('./screenshotReporter.js'); - -afterEach(function() { - if (browser.browserName === 'chrome') { - browser.manage().logs().get('browser').then(function(browserLog) { - console.log('log: ' + require('util').inspect(browserLog)); - }); - } -}); - -describe('Login to app', function() { - it('login to app', function () { - browser.waitForAngularEnabled(true); - browser.get(browser.baseUrl + '/dist/index.html#/login'); - browser.sleep(500); - browser.takeScreenshot().then(function (png) { - ScreenshotReporter(png, 'test/e2e/screenshots/login_to_app_' + browser.browserName); - }); - var alertComponent = element(by.id('alertComponentClose')); - alertComponent.isPresent().then(function(result) { - if (result) { - element(by.id('alertComponentClose')).click(); - browser.sleep(500); - } - }); - element(by.id('login')).sendKeys('bblier'); - browser.sleep(500); - element(by.id('password')).sendKeys('maarch'); - browser.sleep(500); - element(by.id('submit')).click(); - browser.sleep(100); - browser.takeScreenshot().then(function (png) { - ScreenshotReporter(png, 'test/e2e/screenshots/submitLogin_' + browser.browserName); - }); - }); -}); - -// it('should add a todo', function() { -// browser.waitForAngularEnabled(false); -// browser.get('http://127.0.0.1/maarch_trunk/apps/maarch_entreprise/index.php?display=true&page=login'); - -// element(by.id('login')).sendKeys('bbain'); -// element(by.id('pass')).sendKeys('maarch'); -// element(by.css('[name="submit"]')).click(); - -// // var todoList = element.all(by.repeater('todo in todoList.todos')); -// // expect(todoList.count()).toEqual(3); -// // expect(todoList.get(2).getText()).toEqual('write first protractor test'); -// // -// // // You wrote your first test, cross it off the list -// // todoList.get(2).element(by.css('input')).click(); -// // var completedAmount = element.all(by.css('.done-true')); -// // expect(completedAmount.count()).toEqual(2); -// }); - -// it('test 2', function() { -// var nbHeader = element.all(by.css('[class="bg-head-content"]')); -// expect(nbHeader.count()).toEqual(1); - -// element(by.css('[routerLink="/about-us"]')).click(); -// }); \ No newline at end of file diff --git a/test/e2e/screenshotReporter.js b/test/e2e/screenshotReporter.js deleted file mode 100644 index 9bd54ac1c9ed4263a292152b05d2220f98a279df..0000000000000000000000000000000000000000 --- a/test/e2e/screenshotReporter.js +++ /dev/null @@ -1,17 +0,0 @@ -var fs = require('fs'); - -var ScreenshotReporter = function writeScreenShot(data, filename, mode = 'base64') { - if (mode === 'base64') { - var stream = fs.createWriteStream(filename+'.png'); - stream.write(new Buffer.from(data, 'base64')); - stream.end(); - } else if (mode === 'txt') { - var stream = fs.createWriteStream(filename+'.txt'); - stream.write(data); - stream.end(); - } else if (mode === 'console') { - console.log(data); - } -} - -module.exports = ScreenshotReporter; \ No newline at end of file diff --git a/test/e2e/screenshots/.gitkeep b/test/e2e/screenshots/.gitkeep deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/test/e2e/support/commands.js b/test/e2e/support/commands.js new file mode 100644 index 0000000000000000000000000000000000000000..ac0a344744f78805ad27951d13511c7e694eb808 --- /dev/null +++ b/test/e2e/support/commands.js @@ -0,0 +1,37 @@ +// *********************************************** +// 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("login", () => { + cy.visit('/') + cy.wait(1000) + cy.get('#alertComponentClose') + .click() + cy.get('#login') + .type('bblier') + cy.get('#password') + .type('maarch') + cy.get('#submit') + .click() +}) \ No newline at end of file diff --git a/test/e2e/support/index.js b/test/e2e/support/index.js new file mode 100644 index 0000000000000000000000000000000000000000..d68db96df2697e0835f5c490db0c2cc81673f407 --- /dev/null +++ b/test/e2e/support/index.js @@ -0,0 +1,20 @@ +// *********************************************************** +// 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 commands.js using ES2015 syntax: +import './commands' + +// Alternatively you can use CommonJS syntax: +// require('./commands') diff --git a/test/e2e/tsconfig.json b/test/e2e/tsconfig.json new file mode 100644 index 0000000000000000000000000000000000000000..447666f2279d2b2514587d025a6f668f211e5e25 --- /dev/null +++ b/test/e2e/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "strict": true, + "baseUrl": "../node_modules", + "target": "es5", + "lib": ["es5", "dom"], + "types": ["cypress"] + }, + "include": [ + "**/*.ts" + ] + } \ No newline at end of file