Skip to content

Commit 7dee346

Browse files
tests for visualization manifests (#987)
* tests for visualization manifests * refactor tests
1 parent fc92d6c commit 7dee346

File tree

3 files changed

+158
-0
lines changed

3 files changed

+158
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2017-2022 Allegro.pl
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { expect, use } from "chai";
18+
import { VisStrategy } from "../../models/essence/essence";
19+
import { numberSplitCombine } from "../../models/split/split.fixtures";
20+
import { totals, visualizationManifestResolvers } from "../test-utils";
21+
22+
use(visualizationManifestResolvers);
23+
24+
describe("Bar Chart Manifest", () => {
25+
it("should switch to bar chart with single number split", () => {
26+
const essence = totals.addSplit(
27+
numberSplitCombine("commentLength"),
28+
VisStrategy.FairGame
29+
);
30+
31+
expect(essence).to.be.resolvedTo("bar-chart");
32+
});
33+
});
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright 2017-2022 Allegro.pl
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { expect, use } from "chai";
18+
import { VisStrategy } from "../../models/essence/essence";
19+
import { measureSeries } from "../../models/series/series.fixtures";
20+
import { numberSplitCombine, timeSplitCombine } from "../../models/split/split.fixtures";
21+
import { totals, visualizationManifestResolvers } from "../test-utils";
22+
import { LINE_CHART_MANIFEST } from "./line-chart";
23+
24+
use(visualizationManifestResolvers);
25+
26+
const emptyLineChart = totals
27+
.set("visualization", LINE_CHART_MANIFEST as any)
28+
.addSeries(measureSeries("added"));
29+
30+
const timeLineChart = totals
31+
.addSeries(measureSeries("added"))
32+
.addSplit(timeSplitCombine("time"), VisStrategy.FairGame);
33+
34+
describe("Visualization Manifests", () => {
35+
describe("Line Chart", () => {
36+
describe("Starting from Totals", () => {
37+
it("should switch to line chart with single time split", () => {
38+
const essence = totals.addSplit(
39+
timeSplitCombine("time"),
40+
VisStrategy.FairGame
41+
);
42+
43+
expect(essence).to.be.resolvedTo("line-chart");
44+
});
45+
});
46+
47+
describe("Starting from Line Chart", () => {
48+
it("should stick to line chart with change to number split", () => {
49+
const essence = timeLineChart.changeSplit(
50+
numberSplitCombine("commentLength"),
51+
VisStrategy.FairGame
52+
);
53+
54+
expect(essence).to.be.resolvedTo("line-chart");
55+
});
56+
});
57+
58+
describe("Starting from unresolved Line Chart", () => {
59+
it("should stick to line chart with single time split", () => {
60+
const essence = emptyLineChart.addSplit(
61+
timeSplitCombine("time"),
62+
VisStrategy.FairGame
63+
);
64+
65+
expect(essence).to.be.resolvedTo("line-chart");
66+
});
67+
68+
it("should stick to line chart with single number split", () => {
69+
const essence = emptyLineChart.addSplit(
70+
numberSplitCombine("commentLength"),
71+
VisStrategy.FairGame
72+
);
73+
74+
expect(essence).to.be.resolvedTo("line-chart");
75+
});
76+
});
77+
});
78+
});
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2017-2022 Allegro.pl
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import * as Chai from "chai";
18+
import { Essence } from "../../models/essence/essence";
19+
import { EssenceFixtures } from "../../models/essence/essence.fixtures";
20+
import { measureSeries } from "../../models/series/series.fixtures";
21+
import { Visualization } from "../../models/visualization-manifest/visualization-manifest";
22+
23+
export const totals = EssenceFixtures
24+
.wikiTotals()
25+
.addSeries(measureSeries("added"));
26+
27+
export function visualizationManifestResolvers(chai: typeof Chai) {
28+
chai.Assertion.addMethod("resolvedTo", function(visualization: Visualization) {
29+
const essence = this._obj as Essence;
30+
this.assert(
31+
essence.visResolve.state === "ready" && essence.visualization.name === visualization,
32+
`expected Essence to resolve to ${visualization}`,
33+
`expected Essence not to resolve to ${visualization}`,
34+
visualization,
35+
essence.visualization.name,
36+
false
37+
);
38+
});
39+
}
40+
41+
declare global {
42+
namespace Chai {
43+
interface Assertion {
44+
resolvedTo(visualization: Visualization): Assertion;
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)