From 34d445d03a4e6bb0938da7f71241c3301a88a828 Mon Sep 17 00:00:00 2001 From: Yair Even Or Date: Wed, 28 Aug 2019 22:15:03 +0300 Subject: [PATCH] refactored tests --- index.html | 3 + jest-puppeteer.config.js | 7 + package.json | 7 +- test/tagify.test.js | 71 ++-- test/test.html | 795 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 849 insertions(+), 34 deletions(-) create mode 100644 jest-puppeteer.config.js create mode 100644 test/test.html diff --git a/index.html b/index.html index 9cd15445..3d272903 100644 --- a/index.html +++ b/index.html @@ -439,6 +439,9 @@

JAVASCRIPT

tagify = new Tagify(input, { whitelist : ["A# .NET", "A# (Axiom)", "A-0 System", "A+", "A++", "ABAP", "ABC", "ABC ALGOL", "ABSET", "ABSYS", "ACC", "Accent", "Ace DASL", "ACL2", "Avicsoft", "ACT-III", "Action!", "ActionScript", "Ada", "Adenine", "Agda", "Agilent VEE", "Agora", "AIMMS", "Alef", "ALF", "ALGOL 58", "ALGOL 60", "ALGOL 68", "ALGOL W", "Alice", "Alma-0", "AmbientTalk", "Amiga E", "AMOS", "AMPL", "Apex (Salesforce.com)", "APL", "AppleScript", "Arc", "ARexx", "Argus", "AspectJ", "Assembly language", "ATS", "Ateji PX", "AutoHotkey", "Autocoder", "AutoIt", "AutoLISP / Visual LISP", "Averest", "AWK", "Axum", "Active Server Pages", "ASP.NET", "B", "Babbage", "Bash", "BASIC", "bc", "BCPL", "BeanShell", "Batch (Windows/Dos)", "Bertrand", "BETA", "Bigwig", "Bistro", "BitC", "BLISS", "Blockly", "BlooP", "Blue", "Boo", "Boomerang", "Bourne shell (including bash and ksh)", "BREW", "BPEL", "B", "C--", "C++ – ISO/IEC 14882", "C# – ISO/IEC 23270", "C/AL", "Caché ObjectScript", "C Shell", "Caml", "Cayenne", "CDuce", "Cecil", "Cesil", "Céu", "Ceylon", "CFEngine", "CFML", "Cg", "Ch", "Chapel", "Charity", "Charm", "Chef", "CHILL", "CHIP-8", "chomski", "ChucK", "CICS", "Cilk", "Citrine (programming language)", "CL (IBM)", "Claire", "Clarion", "Clean", "Clipper", "CLIPS", "CLIST", "Clojure", "CLU", "CMS-2", "COBOL – ISO/IEC 1989", "CobolScript – COBOL Scripting language", "Cobra", "CODE", "CoffeeScript", "ColdFusion", "COMAL", "Combined Programming Language (CPL)", "COMIT", "Common Intermediate Language (CIL)", "Common Lisp (also known as CL)", "COMPASS", "Component Pascal", "Constraint Handling Rules (CHR)", "COMTRAN", "Converge", "Cool", "Coq", "Coral 66", "Corn", "CorVision", "COWSEL", "CPL", "CPL", "Cryptol", "csh", "Csound", "CSP", "CUDA", "Curl", "Curry", "Cybil", "Cyclone", "Cython", "Java", "Javascript", "M2001", "M4", "M#", "Machine code", "MAD (Michigan Algorithm Decoder)", "MAD/I", "Magik", "Magma", "make", "Maple", "MAPPER now part of BIS", "MARK-IV now VISION:BUILDER", "Mary", "MASM Microsoft Assembly x86", "MATH-MATIC", "Mathematica", "MATLAB", "Maxima (see also Macsyma)", "Max (Max Msp – Graphical Programming Environment)", "Maya (MEL)", "MDL", "Mercury", "Mesa", "Metafont", "Microcode", "MicroScript", "MIIS", "Milk (programming language)", "MIMIC", "Mirah", "Miranda", "MIVA Script", "ML", "Model 204", "Modelica", "Modula", "Modula-2", "Modula-3", "Mohol", "MOO", "Mortran", "Mouse", "MPD", "Mathcad", "MSIL – deprecated name for CIL", "MSL", "MUMPS", "Mystic Programming L"], blacklist : [".NET", "PHP"], // <-- passed as an attribute in this demo + dropdown : { + classname: "basicDropdown" + } }) diff --git a/jest-puppeteer.config.js b/jest-puppeteer.config.js new file mode 100644 index 00000000..b95a08c7 --- /dev/null +++ b/jest-puppeteer.config.js @@ -0,0 +1,7 @@ +module.exports = { + launch: { + slowMo : 80, + headless: true, + }, + browserContext: 'default', +} \ No newline at end of file diff --git a/package.json b/package.json index e4b9b110..bd224b70 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,9 @@ "scripts": { "test": "jest" }, + "jest": { + "preset": "jest-puppeteer" + }, "author": { "name": "Yair Even-Or", "email": "vsync.design@gmail.com" @@ -28,7 +31,6 @@ "@babel/plugin-transform-destructuring": "^7.5.0", "@babel/preset-env": "^7.5.5", "babel-core": "^6.26.3", - "babel-jest": "^24.8.0", "babel-preset-env": "^1.7.0", "beepbeep": "^1.2.2", "gulp": "^3.9.1", @@ -54,7 +56,8 @@ "gulp-umd": "^2.0.0", "gulp-util": "^3.0.8", "gulp-watch": "^5.0.1", - "jest": "^24.8.0", + "jest": "^24.9.0", + "jest-puppeteer": "^4.3.0", "path": "^0.12.7", "puppeteer": "^1.19.0", "run-sequence": "^2.2.1", diff --git a/test/tagify.test.js b/test/tagify.test.js index 20ede9e9..2621e033 100644 --- a/test/tagify.test.js +++ b/test/tagify.test.js @@ -1,11 +1,11 @@ -const puppeteer = require("puppeteer"); +// const puppeteer = require("puppeteer"); const path = require("path"); -const APP = `file:${path.join(__dirname, '../', 'index.html')}` +const APP = `file:${path.join(__dirname, '/', 'test.html')}` -let page; -let browser; -const width = 1920; -const height = 1080; +// let page; +// let browser; +// const width = 1920; +// const height = 1080; let elmSelectors = { tagify : { @@ -32,19 +32,20 @@ let elmSelectors = { } -beforeAll(async () => { - browser = await puppeteer.launch( - { - headless: false, - slowMo : 80, - args : [`--window-size = ${width},${height}`] - } - ) - - page = await browser.newPage() - await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36') - await page.setViewport({ width, height }) +beforeAll(async () => { + // browser = await puppeteer.launch( + // { + // headless: false, + // slowMo : 80, + // args : [`--window-size = ${width},${height}`] + // } + // ) + + // page = await browser.newPage() + + // await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36') + // await page.setViewport({ width, height }) await page.goto(APP); }) @@ -57,19 +58,24 @@ afterEach(async () => { await page.evaluate(() => { location.reload(true) }) - - // reset the tags - // TODO: use https://www.npmjs.com/package/jest-environment-puppeteer }) -afterAll(() => { - browser.close(); -}) +// afterAll(() => { +// browser.close(); +// }) describe("simple tests", () => { - it("duplicate tags removed", async () => { + // fit("access window object", async () => { + // const performance = JSON.parse(await page.evaluate( + // () => JSON.stringify( window.tagify__basic ) + // )) + + // expect(performance).toEqual(1000) + // }, 200) + + it("duplicate tags removed", async (done) => { // await page.goto(APP); // await page.waitForSelector(".some_class_name"); // await page.waitForSelectorRemoval('.some_class_name tag:last-of-type') @@ -83,11 +89,12 @@ describe("simple tests", () => { let texts = await page.evaluate(getAllTagsTexts, elmSelectors); expect(texts).toEqual(["css", "html", "javascript", "css"]); - await page.waitFor(1000) - - texts = await page.evaluate(getAllTagsTexts, elmSelectors); - expect(texts).toEqual(["css", "html", "javascript"]); - }, 2000); + setTimeout(async ()=> { + texts = await page.evaluate(getAllTagsTexts, elmSelectors); + expect(texts).toEqual(["css", "html", "javascript"]); + done() + }, 1000) + }, 0); it("first tagify input has focus", async () => { await page.waitForSelector(elmSelectors.tagify.scope); @@ -207,7 +214,7 @@ describe("actions", () => { await page.waitForSelector(elmSelectors.tagify.firstTag); // await input.type("ja"); await page.type(elmSelectors.tagify.input, "ja"); - await page.click('.tagify__dropdown__item', { clickCount:1 }); + await page.click('.basicDropdown .tagify__dropdown__item', { clickCount:1 }); function getAllTagsTexts(elmSelectors) { let data = []; @@ -245,7 +252,7 @@ describe("mixed-mode", () => { expect(tagifyInput).toEqual(expectedTagifyInput); expect(textareaValue).toEqual(expectedTextareaValue); done() - }, 100) + }, 400) }, 0) }) diff --git a/test/test.html b/test/test.html new file mode 100644 index 00000000..3b4a2234 --- /dev/null +++ b/test/test.html @@ -0,0 +1,795 @@ + + + + + Tagify - pupetteer tests + + + + + + + + + + + +
+
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ + +
+ +
+ +
+ +
+ + +
+ +
+ +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +