Commit 2a118035 authored by Fred Chasen's avatar Fred Chasen

Jest cleanup

parent f279848e
Pipeline #445 passed with stage
in 5 minutes and 18 seconds
......@@ -3,7 +3,8 @@ module.exports = {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
"node": true,
"jest": true
},
"globals": {
},
......
This diff is collapsed.
const { toMatchImageSnapshot } = require('jest-image-snapshot');
const toMatchPDFSnapshot = require('./pdf_snapshot.js');
const expect = require('expect');
expect.extend({ toMatchImageSnapshot, toMatchPDFSnapshot });
const TIMEOUT = 10000; // Some book might take longer than this to renderer
describe('default', async () => {
let page;
let rendered;
beforeAll(async () => {
page = await loadPage('default/default.html')
return page.rendered;
}, TIMEOUT)
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
})
it('should render text', async () => {
let text = await page.evaluate(() => document.body.textContent);
expect(text).toContain('Chapter 1. Loomings.');
})
it('should render 1 page', async () => {
let pages = await page.$$eval(".pagedjs_page", (r) => r.length);
expect(pages).toBe(5);
})
if (!DEBUG) {
it('should create a pdf', async () => {
let pdf = await page.pdf(PDF_SETTINGS);
expect(pdf).toMatchPDFSnapshot(1);
})
}
}
)
......@@ -15,44 +15,51 @@ describe('element with position: fixed', async () => {
})
it("Page 2 should have a fixed element with a position absolute", async () => {
let text = await page.$eval("#page-2 .fixed", (r) =>
window.getComputedStyle(r).getPropertyValue("position"));
let text = await page.$eval("#page-2 .fixed", (r) =>
window.getComputedStyle(r).getPropertyValue("position"));
expect(text).toEqual("absolute");
});
it("Page 3 should have a fixed element with a position absolute", async () => {
let text = await page.$eval("#page-3 .fixed", (r) =>
window.getComputedStyle(r).getPropertyValue("position"));
let text = await page.$eval("#page-3 .fixed", (r) =>
window.getComputedStyle(r).getPropertyValue("position"));
expect(text).toEqual("absolute");
});
});
it("Page 4 should have a fixed element with a position absolute", async () => {
let text = await page.$eval("#page-4 .fixed", (r) =>
window.getComputedStyle(r).getPropertyValue("position"));
let text = await page.$eval("#page-4 .fixed", (r) =>
window.getComputedStyle(r).getPropertyValue("position"));
expect(text).toEqual("absolute");
});
});
it("Page 5 should have a fixed element with a position absolute", async () => {
let text = await page.$eval("#page-5 .fixed", (r) =>
window.getComputedStyle(r).getPropertyValue("position"));
let text = await page.$eval("#page-5 .fixed", (r) =>
window.getComputedStyle(r).getPropertyValue("position"));
expect(text).toEqual("absolute");
});
});
it("Page 2 should have a fixed element with a position absolute", async () => {
let text = await page.$eval("#page-2 .sub", (r) =>
window.getComputedStyle(r).getPropertyValue("position"));
let text = await page.$eval("#page-2 .sub", (r) =>
window.getComputedStyle(r).getPropertyValue("position"));
expect(text).toEqual("absolute");
});
it("Page 3 should have a fixed element with a position absolute", async () => {
let text = await page.$eval("#page-3 .sub", (r) =>
window.getComputedStyle(r).getPropertyValue("position"));
let text = await page.$eval("#page-3 .sub", (r) =>
window.getComputedStyle(r).getPropertyValue("position"));
expect(text).toEqual("absolute");
});
});
it("Page 4 should have a fixed element with a position absolute", async () => {
let text = await page.$eval("#page-4 .sub", (r) =>
window.getComputedStyle(r).getPropertyValue("position"));
let text = await page.$eval("#page-4 .sub", (r) =>
window.getComputedStyle(r).getPropertyValue("position"));
expect(text).toEqual("absolute");
});
});
it("Page 5 should have a fixed element with a position absolute", async () => {
let text = await page.$eval("#page-5 .sub", (r) =>
window.getComputedStyle(r).getPropertyValue("position"));
let text = await page.$eval("#page-5 .sub", (r) =>
window.getComputedStyle(r).getPropertyValue("position"));
expect(text).toEqual("absolute");
});
});
if (!DEBUG) {
it('should create a pdf', async () => {
let pdf = await page.pdf(PDF_SETTINGS);
expect(pdf).toMatchPDFSnapshot(2);
})
}
}
)
......@@ -2,7 +2,7 @@ const TIMEOUT = 10000; // Some book might take longer than this to renderer
describe("default", async () => {
describe("default", () => {
let page;
let rendered;
beforeAll(async () => {
......@@ -17,21 +17,21 @@ describe("default", async () => {
});
it(`should set the running header as "a '' this " ' aa" on the first page`, async () => {
let text = await page.$eval(".pagedjs_first_page", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabet"));
let text = await page.$eval(".pagedjs_first_page", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabet"));
expect(text).toEqual(`"a ' this \\" ' aa"`);
});
it("should set the running header as \"fff\" on the second page", async () => {
let text = await page.$eval("#page-2", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabet"));
let text = await page.$eval("#page-2", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabet"));
expect(text).toEqual("\"fff\"");
});
});
describe("first", async () => {
describe("first", () => {
let page;
let rendered;
beforeAll(async () => {
......@@ -46,23 +46,23 @@ describe("first", async () => {
});
it("should set the running header as \"aaa\" on the first page", async () => {
let text = await page.$eval(".pagedjs_first_page", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabet"));
let text = await page.$eval(".pagedjs_first_page", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabet"));
expect(text).toEqual("\"aaa\"");
});
it("should set the running header as \"fff\" on the second page", async () => {
let text = await page.$eval("#page-2", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabet"));
let text = await page.$eval("#page-2", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabet"));
expect(text).toEqual("\"fff\"");
});
});
describe("last", async () => {
describe("last", () => {
let page;
let rendered;
beforeAll(async () => {
......@@ -77,25 +77,25 @@ describe("last", async () => {
});
it("should set the running header as \"fff\" on the first page", async () => {
let text = await page.$eval(".pagedjs_first_page", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabet"));
let text = await page.$eval(".pagedjs_first_page", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabet"));
expect(text).toEqual("\"fff\"");
});
it("should set the running header as \"fff\" on the second page", async () => {
let text = await page.$eval("#page-2", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabet"));
let text = await page.$eval("#page-2", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabet"));
expect(text).toEqual("\"fff\"");
});
});
describe("first-except", async () => {
describe("first-except", () => {
let page;
let rendered;
beforeAll(async () => {
......@@ -110,23 +110,23 @@ describe("first-except", async () => {
});
it("should set the running header as nothing on the first page", async () => {
let text = await page.$eval(".pagedjs_first_page", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabet"));
let text = await page.$eval(".pagedjs_first_page", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabet"));
expect(text).toEqual("\"\"");
});
it("should set the running header as \"aaa\" on the second page", async () => {
let text = await page.$eval("#page-2", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabet"));
let text = await page.$eval("#page-2", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabet"));
expect(text).toEqual("\"aaa\"");
});
});
describe("string-start", async () => {
describe("string-start", () => {
let page;
let rendered;
beforeAll(async () => {
......@@ -141,26 +141,26 @@ describe("string-start", async () => {
});
it("should set the running header as nothing on the first page", async () => {
let text = await page.$eval(".pagedjs_first_page", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabet"));
let text = await page.$eval(".pagedjs_first_page", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabet"));
expect(text).toEqual("\"aaa\"");
});
it("should set the running header as \"fff\" on the third page", async () => {
let text = await page.$eval("#page-3", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabet"));
let text = await page.$eval("#page-3", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabet"));
expect(text).toEqual("\"fff\"");
});
it("should set the running header as \"ggg\" on page 4", async () => {
let text = await page.$eval("#page-4", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabet"));
let text = await page.$eval("#page-4", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabet"));
expect(text).toEqual("\"ggg\"");
});
});
describe("string-multiple", async () => {
describe("string-multiple", () => {
let page;
let rendered;
beforeAll(async () => {
......@@ -175,23 +175,23 @@ describe("string-multiple", async () => {
});
it("should set the running header as nothing on the first page", async () => {
let text = await page.$eval("#page-2", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabet"));
let text = await page.$eval("#page-2", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabet"));
expect(text).toEqual("\"aaa\"");
});
it("should set the running header as nothing on the first page", async () => {
let text = await page.$eval("#page-2", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabetbis"));
let text = await page.$eval("#page-2", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabetbis"));
expect(text).toEqual("\"1111\"");
});
it("should set the running header as \"fff\" on the third page", async () => {
let text = await page.$eval("#page-9", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabet"));
let text = await page.$eval("#page-9", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabet"));
expect(text).toEqual("\"bbb\"");
});
it("should set the running header as \"fff\" on the third page", async () => {
let text = await page.$eval("#page-9", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabetbis"));
let text = await page.$eval("#page-9", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabetbis"));
expect(text).toEqual("\"2222\"");
});
});
\ No newline at end of file
});
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