Skip to content

Commit

Permalink
refactored tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yairEO committed Aug 28, 2019
1 parent 70bfa37 commit 34d445d
Show file tree
Hide file tree
Showing 5 changed files with 849 additions and 34 deletions.
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,9 @@ <h3>JAVASCRIPT</h3>
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"
}
})


Expand Down
7 changes: 7 additions & 0 deletions jest-puppeteer.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
launch: {
slowMo : 80,
headless: true,
},
browserContext: 'default',
}
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"scripts": {
"test": "jest"
},
"jest": {
"preset": "jest-puppeteer"
},
"author": {
"name": "Yair Even-Or",
"email": "[email protected]"
Expand All @@ -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",
Expand All @@ -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",
Expand Down
71 changes: 39 additions & 32 deletions test/tagify.test.js
Original file line number Diff line number Diff line change
@@ -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 : {
Expand All @@ -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);
})

Expand All @@ -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')
Expand All @@ -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);
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -245,7 +252,7 @@ describe("mixed-mode", () => {
expect(tagifyInput).toEqual(expectedTagifyInput);
expect(textareaValue).toEqual(expectedTextareaValue);
done()
}, 100)
}, 400)
}, 0)
})

Expand Down
Loading

0 comments on commit 34d445d

Please sign in to comment.