-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#7 Add some documentation
- Loading branch information
Pawel Siemienik
committed
Mar 26, 2020
1 parent
4498835
commit 3f5f971
Showing
20 changed files
with
153 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,4 @@ | |
/.idea | ||
/coverage/ | ||
/.nyc_output/ | ||
/.idea/ | ||
|
||
|
||
/src/example.ts | ||
*.xlsx | ||
/.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import {Renderer} from "../../src/Renderer"; | ||
import * as fs from "fs"; | ||
import * as path from "path"; | ||
import {Workbook} from "exceljs"; | ||
import * as chai from 'chai' | ||
|
||
|
||
function assertCells(expected: Workbook, result: Workbook, factor: number = 10) { | ||
chai.expect(expected.worksheets.length).eql(result.worksheets.length); | ||
chai.expect(expected.worksheets.map(x => x.name)).eql(result.worksheets.map(x => x.name)); | ||
|
||
for (let wi = 0; wi < expected.worksheets.length; wi++) { | ||
const ws = {e: expected.worksheets[wi], r: result.worksheets[wi]}; | ||
for (let i = 0; i < factor * factor; i++) { | ||
const r = Math.floor(i / factor) + 1; | ||
const c = i % factor + 1; | ||
const cell = { | ||
e: ws.e.getCell(r, c), | ||
r: ws.r.getCell(r, c) | ||
}; | ||
|
||
|
||
if (r === 1) { | ||
chai.expect(ws.e.getColumn(c).width).eql(ws.r.getColumn(c).width); | ||
} | ||
if (c === 1) { | ||
chai.expect(ws.e.getRow(r).height).eql(ws.r.getRow(r).height); | ||
} | ||
|
||
chai.expect(cell.e.style).eql(cell.r.style); | ||
chai.expect(cell.e.text).eql(cell.r.text); | ||
chai.expect(cell.e.value).eql(cell.r.value); | ||
} | ||
} | ||
} | ||
|
||
describe('INTEGRATION:: Test xlsx renderer ', function () { | ||
|
||
describe('Checking if assertCells works ok.', function () { | ||
it('Same - should pass ok', async function () { | ||
const expected = await new Workbook().xlsx.readFile(path.join(__dirname, 'data', 'assertCells', 'main.xlsx')); | ||
const correct = await new Workbook().xlsx.readFile(path.join(__dirname, 'data', 'assertCells', 'correct.xlsx')); | ||
|
||
assertCells(expected, correct, 20); | ||
}); | ||
|
||
it('Different - attempt to broke assertions', async function () { | ||
const expected = await new Workbook().xlsx.readFile(path.join(__dirname, 'data', 'assertCells', 'main.xlsx')); | ||
const failedWorksheetAmount = await new Workbook().xlsx.readFile(path.join(__dirname, 'data', 'assertCells', 'f-ws-amount.xlsx')); | ||
const failedWorksheetNames = await new Workbook().xlsx.readFile(path.join(__dirname, 'data', 'assertCells', 'f-ws-names.xlsx')); | ||
const failedWidth = await new Workbook().xlsx.readFile(path.join(__dirname, 'data', 'assertCells', 'f-width.xlsx')); | ||
const failedHeight = await new Workbook().xlsx.readFile(path.join(__dirname, 'data', 'assertCells', 'f-height.xlsx')); | ||
const failedStyle = await new Workbook().xlsx.readFile(path.join(__dirname, 'data', 'assertCells', 'f-style.xlsx')); | ||
const failedText = await new Workbook().xlsx.readFile(path.join(__dirname, 'data', 'assertCells', 'f-text.xlsx')); | ||
const failedValue = await new Workbook().xlsx.readFile(path.join(__dirname, 'data', 'assertCells', 'f-value.xlsx')); | ||
const failedTable = await new Workbook().xlsx.readFile(path.join(__dirname, 'data', 'assertCells', 'f-table.xlsx')); | ||
|
||
chai.expect(() => assertCells(expected, failedWorksheetAmount, 20)).throw("expected 2 to deeply equal 3"); | ||
chai.expect(() => assertCells(expected, failedWorksheetNames, 20)).throw('expected [ \'Sheet1\', \'Sheet2\' ] to deeply equal [ \'Sheet1\', \'Sheet3\' ]'); | ||
chai.expect(() => assertCells(expected, failedWidth, 20)).throw("expected 13 to deeply equal 7.90625"); | ||
chai.expect(() => assertCells(expected, failedHeight, 20)).throw("expected 15 to deeply equal 34.5"); | ||
chai.expect(() => assertCells(expected, failedStyle, 20)).throw("expected { Object (font, border, ...) } to deeply equal { Object (font, border, ...) }"); | ||
chai.expect(() => assertCells(expected, failedText, 20)).throw('expected \'sadasd\' to deeply equal \'sadas\''); | ||
chai.expect(() => assertCells(expected, failedValue, 20)).throw('expected { Object (formula, result) } to deeply equal \'asdasda\''); | ||
chai.expect(() => assertCells(expected, failedTable, 20)).throw('expected { Object (font, border, ...) } to deeply equal { Object (font, border, ...) }'); | ||
}); | ||
}); | ||
describe('Load examples, render and compare with expected result', function () { | ||
const dataPath = path.normalize(path.join(__dirname, 'data/')); | ||
const sets = fs.readdirSync(path.normalize(dataPath), {withFileTypes: true}) | ||
.filter(i => i.isDirectory()) | ||
.filter(d => /^Renderer[0-9]*-/.test(d.name)); | ||
|
||
|
||
const renderer = new Renderer(); | ||
sets.forEach(s => { | ||
it(`Test for ${s.name}`, async function () { | ||
const result = await renderer.renderFromFile( | ||
path.join(dataPath, s.name, "template.xlsx"), | ||
require(path.join(dataPath, s.name, 'viewModel.json')) | ||
); | ||
|
||
const expected = await new Workbook().xlsx.readFile(path.join(dataPath, s.name, "expected.xlsx")); | ||
|
||
assertCells(expected, result); | ||
}); | ||
|
||
|
||
}) | ||
|
||
}); | ||
}); |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.