Skip to content

Commit

Permalink
#6 #3 Test (and examples) for VariableCell and EndRowCell
Browse files Browse the repository at this point in the history
#7 Update documentation
update .gitignore
  • Loading branch information
Pawel Siemienik committed Mar 26, 2020
1 parent 3f5f971 commit 0b5f2df
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 25 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
/.idea
/coverage/
/.nyc_output/
/.idea/
/.idea/

test-output.xlsx
~$*.xlsx
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ const viewModel = new MyAwesomeReportVm(); //or something else
|----------|-----:|-------|--------|-------------|:---------|
| - | [BaseCell](./src/cell/BaseCell.ts) | n/o | n/o | All Cell\`s definition classes extend it. | **abstract** |
| Content | [NormalCell](./src/cell/NormalCell.ts) | 1 | not started by `##` or `#!` | This one copy all styles, width, properties and value form template. | **default** |
| Content | [VariableCell](./src/cell/VariableCell.ts) | 3 | `## pathToVariable ` | Write variable from `ViewModel`. <br/> Paths to object's property or array item are allowed. | **Examples:** <br/> `simplePath` <br/> `someObject.property` <br/> `array.0.field` <br/> `items.1.path.to.object.prop`|
| Content | [VariableCell](./src/cell/VariableCell.ts) | 3 | `## pathToVariable ` | Write variable from `ViewModel`. <br/> Paths to object's property or array item are allowed.<br/> When asking about undefined variable it returns empty string. | **Paths examples:** <br/> `simplePath` <br/> `someObject.property` <br/> `array.0.field` <br/> `items.1.path.to.object.prop`|
| Content | **TODO: describe it!** [HyperlinkCell](./src/cell/HyperlinkCell.ts) | | | | |
| Content | **TODO: describe it!** [FormulaCell](./src/cell/FormulaCell.ts) | | | | |
| Navigation | **TODO: describe it!** [EndRowCell](./src/cell/EndRowCell.ts) | | | | |
| Navigation | [EndRowCell](./src/cell/EndRowCell.ts) | 2 | `#! END_ROW` | Go to the beginning of next row | |
| Worksheet<br/>Navigation<br/>Loop | [FinishCell](./src/cell/FinishCell.ts) | 7 | `#! FINISH conditionPath` | Finish rendering for current worksheet and: <br/> 1) go to next worksheet if `conditionPath===true`<br/> 2) repeat this template worksheet again (`conditionPath === false`) - looping through worksheets <br/> 3) finished whole rendering when this worksheet is the last one. | **Examples:**<br/> `#! FINISHED ` or `#! FINISHED itemFromLoop.__iterated` |
| Worksheet | **TODO: describe it!** [WsNameCell](./src/cell/WsNameCell.ts) | | | | |
| View Model | **TODO: describe it!** [DeleteCell](./src/cell/DeleteCell.ts) | | | | |
Expand Down
12 changes: 0 additions & 12 deletions tests/Renderer.test.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ function assertCells(expected: Workbook, result: Workbook, factor: number = 10)


if (r === 1) {
chai.expect(ws.e.getColumn(c).width).eql(ws.r.getColumn(c).width);
chai.expect(ws.r.getColumn(c).width).eql(ws.e.getColumn(c).width);
}
if (c === 1) {
chai.expect(ws.e.getRow(r).height).eql(ws.r.getRow(r).height);
chai.expect(ws.r.getRow(r).height).eql(ws.e.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);

// console.log(r,c);
chai.expect(cell.r.style).eql(cell.e.style);
chai.expect(cell.r.text).eql(cell.e.text);
chai.expect(cell.r.value).eql(cell.e.value);
}
}
}
Expand Down Expand Up @@ -57,11 +58,11 @@ describe('INTEGRATION:: Test xlsx renderer ', function () {

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, failedWidth, 20)).throw("expected 7.90625 to deeply equal 13");
chai.expect(() => assertCells(expected, failedHeight, 20)).throw("expected 34.5 to deeply equal 15");
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, failedText, 20)).throw('expected \'sadas\' to deeply equal \'sadasd\'');
chai.expect(() => assertCells(expected, failedValue, 20)).throw('expected \'asdasda\' to deeply equal { Object (formula, result) }');
chai.expect(() => assertCells(expected, failedTable, 20)).throw('expected { Object (font, border, ...) } to deeply equal { Object (font, border, ...) }');
});
});
Expand All @@ -82,6 +83,10 @@ describe('INTEGRATION:: Test xlsx renderer ', function () {

const expected = await new Workbook().xlsx.readFile(path.join(dataPath, s.name, "expected.xlsx"));

try{
await result.xlsx.writeFile(path.join(dataPath, s.name, 'test-output.xlsx'));
}catch(e){}

assertCells(expected, result);
});

Expand Down
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions tests/integration/data/Renderer001-EndRow/viewModel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Binary file not shown.
Binary file not shown.
44 changes: 44 additions & 0 deletions tests/integration/data/Renderer002-Variable/viewModel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"firstName": "Paweł",
"secondName": "Siemienik",
"email": "[email protected]",
"address": {
"streetName": "Al.. Siemienika",
"city": {
"name": "BB",
"province": {
"name": "Silesia",
"country": {
"name": "Poland"
}
}
}
},
"tags": [
"ziom",
"fullStack"
],
"achievements": [
{
"name": "open source maintainer",
"description": "bla bla blaaa"
},
{
"name": "some Other",
"description": "some other bla bla"
}
],
"friends": [
{
"firstName": "anyone"
},
{
"firstName": "my body",
"achievements": [
{
"name": "type scriper"
}
]
}
]
}

0 comments on commit 0b5f2df

Please sign in to comment.