diff --git a/.gitignore b/.gitignore index 3af0ccb..2e6c62d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -/data +data +package-lock.json +package.json +node_modules \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8ee65cd --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +.PHONY: test + +node_modules/jest/bin/jest.js: + npm install jest + +node_modules/puppeteer: + npm install puppeteer + +test: node_modules/jest/bin/jest.js node_modules/puppeteer + ./node_modules/jest/bin/jest.js diff --git a/public/js/app.js b/public/js/app.js index 61a6e5d..5dbd4cd 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -104,6 +104,7 @@ loadingTask.promise.then(function(pdf) { } }); var svgButton = document.createElement('label'); + svgButton.id = "label_svg_"+i; svgButton.classList.add('position-relative'); svgButton.classList.add('btn'); svgButton.classList.add('btn-svg'); diff --git a/templates/pdf.html.php b/templates/pdf.html.php index 5da5a36..26ce513 100644 --- a/templates/pdf.html.php +++ b/templates/pdf.html.php @@ -41,17 +41,17 @@
- +
- +
- +
@@ -90,7 +90,6 @@
- + diff --git a/test/files/document.pdf b/test/files/document.pdf new file mode 100644 index 0000000..8be8454 Binary files /dev/null and b/test/files/document.pdf differ diff --git a/test/signature.test.js b/test/signature.test.js new file mode 100644 index 0000000..ea770e8 --- /dev/null +++ b/test/signature.test.js @@ -0,0 +1,78 @@ +const puppeteer = require('puppeteer'); +const cp = require("child_process"); +var headless = true; +if(process.env.SHOW) { + headless = false; +} +var page = null; +var browser = null; +var server = null +var host = "localhost:"+(9000 + Math.floor((Math.random() * 1000))); + +describe("Signature d'un pdf", () => { + beforeAll(async () => { + server = cp.spawn("php", ["-S", host, "-t", "public"]); + browser = await puppeteer.launch({ headless: headless }); + page = await browser.newPage(); + await page.setViewport({ width: 1200, height: 800 }) + await page.goto('http://' + host + '/'); + }); + it('Upload et chargement du pdf', async () => { + await (await page.$("input#input_pdf_upload")).uploadFile(require('path').resolve(__dirname + '/files/document.pdf')); + await page.waitForNavigation() + }); + it("Création d'une signature", async () => { + await page.waitForSelector('#label_svg_signature_add', {visible: true}); + await page.waitForTimeout(300); + await page.click("#label_svg_signature_add") + await page.waitForSelector('#signature-pad', {visible: true}); + await page.waitForTimeout(100); + await page.click('#signature-pad'); + await page.waitForSelector('button#btn_modal_ajouter:not([disabled])'); + await page.waitForTimeout(100); + await page.click('button#btn_modal_ajouter'); + await page.waitForTimeout(300); + }); + it('Ajout de la signature dans le pdf', async () => { + await page.mouse.click(100,100); + await page.waitForTimeout(100); + }); + it('Déplacement de la signature', async () => { + await page.mouse.down(); + await page.waitForTimeout(100); + await page.mouse.move(400,400); + await page.mouse.up(); + await page.waitForTimeout(100); + // Redimensionnement de la signature + await page.mouse.move(460,450); + await page.mouse.down(); + await page.waitForTimeout(100); + await page.mouse.move(500,500); + await page.mouse.up(); + await page.waitForTimeout(100); + // Ajout d'une seconde signature + await page.click("#label_svg_0"); + await page.waitForTimeout(100); + await page.mouse.click(100,100); + // Suppression de la seconde signature + await page.mouse.click(100,100); + await page.waitForTimeout(100); + await page.keyboard.press('Delete'); + // Suppression de la signature de la liste + await page.click("#label_svg_0 .btn-svg-list-suppression") + await page.waitForTimeout(100); + }); + afterAll(async () => { + await browser.close(); + await server.kill(); + }); +}); + + + + + + + + +