-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #158 from redbearsam/feature/first-ui-unit-test
Implemented an example UI/D3 based unit test
- Loading branch information
Showing
5 changed files
with
152 additions
and
2 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
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
19 changes: 19 additions & 0 deletions
19
packages/perspective-viewer-d3fc/test/js/jest.unit.config.js
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,19 @@ | ||
/****************************************************************************** | ||
* | ||
* Copyright (c) 2017, the Perspective Authors. | ||
* | ||
* This file is part of the Perspective library, distributed under the terms of | ||
* the Apache License 2.0. The full license can be found in the LICENSE file. | ||
* | ||
*/ | ||
|
||
module.exports = { | ||
roots: ["unit"], | ||
verbose: true, | ||
testURL: "http://localhost/", | ||
automock: false, | ||
transform: { | ||
".js$": "./transform.js" | ||
}, | ||
setupFiles: ["./beforeEachSpec.js"] | ||
}; |
130 changes: 130 additions & 0 deletions
130
packages/perspective-viewer-d3fc/test/js/unit/tooltip.js/generateHTML.spec.js
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,130 @@ | ||
/****************************************************************************** | ||
* | ||
* Copyright (c) 2017, the Perspective Authors. | ||
* | ||
* This file is part of the Perspective library, distributed under the terms of | ||
* the Apache License 2.0. The full license can be found in the LICENSE file. | ||
* | ||
*/ | ||
import {select} from "d3"; | ||
import {generateHtml} from "../../../../src/js/tooltip/generateHTML"; | ||
|
||
describe("tooltip should", () => { | ||
let tooltip = null; | ||
let settings = null; | ||
|
||
beforeEach(() => { | ||
tooltip = select("body") | ||
.append("div") | ||
.classed("tooltip-test", true); | ||
tooltip.append("div").attr("id", "tooltip-values"); | ||
|
||
settings = { | ||
crossValues: [], | ||
splitValues: [], | ||
mainValues: [{name: "main-1", type: "integer"}] | ||
}; | ||
}); | ||
afterEach(() => { | ||
tooltip.remove(); | ||
}); | ||
|
||
const getContent = () => { | ||
const content = []; | ||
tooltip.selectAll("li").each((d, i, nodes) => { | ||
content.push(select(nodes[i]).text()); | ||
}); | ||
return content; | ||
}; | ||
|
||
test("show single mainValue", () => { | ||
const data = { | ||
mainValue: 101 | ||
}; | ||
generateHtml(tooltip, data, settings); | ||
expect(getContent()).toEqual(["main-1: 101"]); | ||
}); | ||
|
||
test("show multiple mainValues", () => { | ||
settings.mainValues.push({name: "main-2", type: "float"}); | ||
const data = { | ||
mainValues: [101, 202.22] | ||
}; | ||
generateHtml(tooltip, data, settings); | ||
expect(getContent()).toEqual(["main-1: 101", "main-2: 202.22"]); | ||
}); | ||
|
||
test("format mainValue as date", () => { | ||
settings.mainValues[0].type = "datetime"; | ||
const testDate = new Date("2019-04-03T15:15Z"); | ||
const data = { | ||
mainValue: testDate.getTime() | ||
}; | ||
generateHtml(tooltip, data, settings); | ||
expect(getContent()).toEqual([`main-1: ${testDate.toLocaleString()}`]); | ||
}); | ||
|
||
test("format mainValue as integer", () => { | ||
settings.mainValues[0].type = "integer"; | ||
const data = { | ||
mainValue: 12345.6789 | ||
}; | ||
generateHtml(tooltip, data, settings); | ||
expect(getContent()).toEqual(["main-1: 12,345"]); | ||
}); | ||
|
||
test("format mainValue as decimal", () => { | ||
settings.mainValues[0].type = "float"; | ||
const data = { | ||
mainValue: 12345.6789 | ||
}; | ||
generateHtml(tooltip, data, settings); | ||
expect(getContent()).toEqual(["main-1: 12,345.679"]); | ||
}); | ||
|
||
test("show with single crossValue", () => { | ||
settings.crossValues.push({name: "cross-1", type: "string"}); | ||
const data = { | ||
crossValue: "tc-1", | ||
mainValue: 101 | ||
}; | ||
|
||
generateHtml(tooltip, data, settings); | ||
expect(getContent()).toEqual(["cross-1: tc-1", "main-1: 101"]); | ||
}); | ||
|
||
test("show with multiple crossValues", () => { | ||
settings.crossValues.push({name: "cross-1", type: "string"}); | ||
settings.crossValues.push({name: "cross-2", type: "integer"}); | ||
const data = { | ||
crossValue: "tc-1|1001", | ||
mainValue: 101 | ||
}; | ||
|
||
generateHtml(tooltip, data, settings); | ||
expect(getContent()).toEqual(["cross-1: tc-1", "cross-2: 1,001", "main-1: 101"]); | ||
}); | ||
|
||
test("show with single splitValue", () => { | ||
settings.splitValues.push({name: "split-1", type: "string"}); | ||
const data = { | ||
key: "ts-1", | ||
mainValue: 101 | ||
}; | ||
|
||
generateHtml(tooltip, data, settings); | ||
expect(getContent()).toEqual(["split-1: ts-1", "main-1: 101"]); | ||
}); | ||
|
||
test("show with multiple splitValues", () => { | ||
settings.splitValues.push({name: "split-1", type: "string"}); | ||
settings.splitValues.push({name: "split-2", type: "integer"}); | ||
const data = { | ||
key: "ts-1|1001", | ||
mainValue: 101 | ||
}; | ||
|
||
generateHtml(tooltip, data, settings); | ||
expect(getContent()).toEqual(["split-1: ts-1", "split-2: 1,001", "main-1: 101"]); | ||
}); | ||
}); |