Skip to content

Commit

Permalink
unit testing for addStyle
Browse files Browse the repository at this point in the history
  • Loading branch information
NB10328 authored and NB10328 committed Nov 13, 2020
1 parent 3382d16 commit 58d4918
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/ascii-table3.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,29 @@ describe('Styling', () => {
assert.strictEqual(asciiTable.getAlign(2), AsciiTable3.RIGHT);
assert.strictEqual(asciiTable.getAlign(3), AsciiTable3.AUTO);
});

it('addStyle', () => {
const roundedStyle = {
name: "rounded",
borders: {
top: {
left: ".", center: "-", right: ".", colSeparator: "."
},
middle: {
left: ":", center: "-", right: ":", colSeparator: "+"
},
bottom: {
left: "'", center: "-", right: "'", colSeparator: "'"
},
data : {
left: "|", center: " ", right: "|", colSeparator: "|"
}
}
};

asciiTable.addStyle(roundedStyle);
assert.notStrictEqual(asciiTable.getStyle("roundStyle"), roundedStyle);
});
});

describe('Rendering', () => {
Expand Down Expand Up @@ -291,6 +314,27 @@ describe('Rendering', () => {
);
});

it ('toString (new style)', () => {
// back to default
asciiTable.setWidths();
asciiTable.setCellMargin(1);

asciiTable.setStyle("rounded");
assert.strictEqual(
asciiTable.toString(),
'.----------------------------.\n' +
'| Dummy title |\n' +
':---------.-------.----------:\n' +
'| Title | Count | Rate (%) |\n' +
':---------+-------+----------:\n' +
'| Dummy 1 | 10 | 2.3 |\n' +
'| Dummy 2 | 5 | 3.1 |\n' +
'| Dummy 3 | 100 | 3.14 |\n' +
'| Dummy 4 | 0 | 1 |\n' +
"'---------'-------'----------'\n"
);
});

it ('toString (cell margins)', () => {
asciiTable.setWidths();
asciiTable.setStyle('ramac');
Expand Down

0 comments on commit 58d4918

Please sign in to comment.