Skip to content

Commit

Permalink
Increase test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
fniessink committed Jun 17, 2020
1 parent 8d1719b commit 704d589
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions components/frontend/src/source/SourceEntities.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ const data_model = {
metric_type:
{
name: "entity name",
attributes: [{ key: "integer", type: "integer" }, { key: "float", type: "float" }]
attributes: [
{ key: "integer", type: "integer" }, { key: "float", type: "float" }, { key: "text", type: "text" }
]
}
}
}
Expand All @@ -31,17 +33,20 @@ const source = {
{
key: "1",
integer: "1",
float: "0.3"
float: "0.3",
text: "C"
},
{
key: "2",
integer: "3",
float: "0.2"
float: "0.2",
text: "B"
},
{
key: "3",
integer: "2",
float: "0.1"
float: "0.1",
text: "A"
}
]
}
Expand All @@ -54,23 +59,26 @@ describe('<SourceEntities />', () => {
it('sorts', () => {
function expectSorting(columnIndex, ascending, attributes) {
expect(wrapper.find("TableHeaderCell").at(columnIndex).prop("sorted")).toBe(ascending ? "ascending" : "descending");
Object.entries(attributes).forEach(([index, value]) =>
{
expect(wrapper.find("SourceEntityAttribute").at(index).text()).toBe(value);
}
Object.entries(attributes).forEach(([index, value]) => {
expect(wrapper.find("SourceEntityAttribute").at(index).text()).toBe(value);
}
);
}
function sortColumn(columnIndex) {
wrapper.find("TableHeaderCell").at(columnIndex).simulate("click");
}
const wrapper = mount(<SourceEntities datamodel={data_model} metric={metric} source={source} />);
sortColumn(2);
expectSorting(2, true, {0: "1", 2: "2", 4: "3"});
expectSorting(2, true, { 0: "1", 3: "2", 6: "3" });
sortColumn(2);
expectSorting(2, false, {0: "3", 2: "2", 4: "1"});
expectSorting(2, false, { 0: "3", 3: "2", 6: "1" });
sortColumn(3);
expectSorting(3, false, {1: "0.3", 3: "0.2", 5: "0.1"});
expectSorting(3, false, { 1: "0.3", 4: "0.2", 7: "0.1" });
sortColumn(3);
expectSorting(3, true, {1: "0.1", 3: "0.2", 5: "0.3"});
expectSorting(3, true, { 1: "0.1", 4: "0.2", 7: "0.3" });
sortColumn(4);
expectSorting(4, true, { 2: "A", 5: "B", 8: "C" });
sortColumn(4);
expectSorting(4, false, { 2: "C", 5: "B", 8: "A" });
})
});

0 comments on commit 704d589

Please sign in to comment.