-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests for visualization manifests (#987)
* tests for visualization manifests * refactor tests
- Loading branch information
1 parent
fc92d6c
commit 7dee346
Showing
3 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/common/visualization-manifests/bar-chart/bar-chart.mocha.ts
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,33 @@ | ||
/* | ||
* Copyright 2017-2022 Allegro.pl | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { expect, use } from "chai"; | ||
import { VisStrategy } from "../../models/essence/essence"; | ||
import { numberSplitCombine } from "../../models/split/split.fixtures"; | ||
import { totals, visualizationManifestResolvers } from "../test-utils"; | ||
|
||
use(visualizationManifestResolvers); | ||
|
||
describe("Bar Chart Manifest", () => { | ||
it("should switch to bar chart with single number split", () => { | ||
const essence = totals.addSplit( | ||
numberSplitCombine("commentLength"), | ||
VisStrategy.FairGame | ||
); | ||
|
||
expect(essence).to.be.resolvedTo("bar-chart"); | ||
}); | ||
}); |
78 changes: 78 additions & 0 deletions
78
src/common/visualization-manifests/line-chart/line-chart.mocha.ts
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,78 @@ | ||
/* | ||
* Copyright 2017-2022 Allegro.pl | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { expect, use } from "chai"; | ||
import { VisStrategy } from "../../models/essence/essence"; | ||
import { measureSeries } from "../../models/series/series.fixtures"; | ||
import { numberSplitCombine, timeSplitCombine } from "../../models/split/split.fixtures"; | ||
import { totals, visualizationManifestResolvers } from "../test-utils"; | ||
import { LINE_CHART_MANIFEST } from "./line-chart"; | ||
|
||
use(visualizationManifestResolvers); | ||
|
||
const emptyLineChart = totals | ||
.set("visualization", LINE_CHART_MANIFEST as any) | ||
.addSeries(measureSeries("added")); | ||
|
||
const timeLineChart = totals | ||
.addSeries(measureSeries("added")) | ||
.addSplit(timeSplitCombine("time"), VisStrategy.FairGame); | ||
|
||
describe("Visualization Manifests", () => { | ||
describe("Line Chart", () => { | ||
describe("Starting from Totals", () => { | ||
it("should switch to line chart with single time split", () => { | ||
const essence = totals.addSplit( | ||
timeSplitCombine("time"), | ||
VisStrategy.FairGame | ||
); | ||
|
||
expect(essence).to.be.resolvedTo("line-chart"); | ||
}); | ||
}); | ||
|
||
describe("Starting from Line Chart", () => { | ||
it("should stick to line chart with change to number split", () => { | ||
const essence = timeLineChart.changeSplit( | ||
numberSplitCombine("commentLength"), | ||
VisStrategy.FairGame | ||
); | ||
|
||
expect(essence).to.be.resolvedTo("line-chart"); | ||
}); | ||
}); | ||
|
||
describe("Starting from unresolved Line Chart", () => { | ||
it("should stick to line chart with single time split", () => { | ||
const essence = emptyLineChart.addSplit( | ||
timeSplitCombine("time"), | ||
VisStrategy.FairGame | ||
); | ||
|
||
expect(essence).to.be.resolvedTo("line-chart"); | ||
}); | ||
|
||
it("should stick to line chart with single number split", () => { | ||
const essence = emptyLineChart.addSplit( | ||
numberSplitCombine("commentLength"), | ||
VisStrategy.FairGame | ||
); | ||
|
||
expect(essence).to.be.resolvedTo("line-chart"); | ||
}); | ||
}); | ||
}); | ||
}); |
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,47 @@ | ||
/* | ||
* Copyright 2017-2022 Allegro.pl | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import * as Chai from "chai"; | ||
import { Essence } from "../../models/essence/essence"; | ||
import { EssenceFixtures } from "../../models/essence/essence.fixtures"; | ||
import { measureSeries } from "../../models/series/series.fixtures"; | ||
import { Visualization } from "../../models/visualization-manifest/visualization-manifest"; | ||
|
||
export const totals = EssenceFixtures | ||
.wikiTotals() | ||
.addSeries(measureSeries("added")); | ||
|
||
export function visualizationManifestResolvers(chai: typeof Chai) { | ||
chai.Assertion.addMethod("resolvedTo", function(visualization: Visualization) { | ||
const essence = this._obj as Essence; | ||
this.assert( | ||
essence.visResolve.state === "ready" && essence.visualization.name === visualization, | ||
`expected Essence to resolve to ${visualization}`, | ||
`expected Essence not to resolve to ${visualization}`, | ||
visualization, | ||
essence.visualization.name, | ||
false | ||
); | ||
}); | ||
} | ||
|
||
declare global { | ||
namespace Chai { | ||
interface Assertion { | ||
resolvedTo(visualization: Visualization): Assertion; | ||
} | ||
} | ||
} |