From 01ef09a2dda05e0f65c85b3af37bb7c20ecf3d2d Mon Sep 17 00:00:00 2001 From: Adrian Mroz Date: Mon, 31 May 2021 14:02:44 +0200 Subject: [PATCH] Fix tests --- .../line-chart/utils/splits.mocha.ts | 21 ++++-- .../models/dimension/dimension.fixtures.ts | 4 +- .../models/dimension/dimension.mocha.ts | 51 -------------- .../models/dimension/dimensions.fixtures.ts | 66 ++++++++----------- .../models/dimension/dimensions.mocha.ts | 26 +------- src/common/models/dimension/dimensions.ts | 2 +- src/common/models/essence/essence.mocha.ts | 42 ------------ src/common/view-definitions/test/dimension.ts | 1 + 8 files changed, 47 insertions(+), 166 deletions(-) delete mode 100644 src/common/models/dimension/dimension.mocha.ts diff --git a/src/client/visualizations/line-chart/utils/splits.mocha.ts b/src/client/visualizations/line-chart/utils/splits.mocha.ts index 4541b1ad1..7aa44228a 100644 --- a/src/client/visualizations/line-chart/utils/splits.mocha.ts +++ b/src/client/visualizations/line-chart/utils/splits.mocha.ts @@ -18,7 +18,14 @@ import { expect, use } from "chai"; import { findDimensionByName } from "../../../../common/models/dimension/dimensions"; import { EssenceFixtures } from "../../../../common/models/essence/essence.fixtures"; import equivalent from "../../../utils/test-utils/equivalent"; -import { getContinuousDimension, getContinuousReference, getContinuousSplit, getNominalDimension, getNominalSplit, hasNominalSplit } from "./splits"; +import { + getContinuousDimension, + getContinuousReference, + getContinuousSplit, + getNominalDimension, + getNominalSplit, + hasNominalSplit +} from "./splits"; use(equivalent); @@ -39,7 +46,7 @@ describe("splits", () => { describe("getContinuousDimension", () => { it("should pick continuous dimension", () => { - expect(getContinuousDimension(essenceWithoutNominalSplit)).to.be.equivalent(timeDimension); + expect(getContinuousDimension(essenceWithoutNominalSplit)).to.be.deep.equal(timeDimension); }); }); @@ -77,7 +84,7 @@ describe("splits", () => { describe("getContinuousDimension", () => { it("should pick continuous dimension", () => { - expect(getContinuousDimension(essenceWithNominalSplit)).to.be.equivalent(timeDimension); + expect(getContinuousDimension(essenceWithNominalSplit)).to.be.deep.equal(timeDimension); }); }); @@ -88,19 +95,19 @@ describe("splits", () => { }); describe("getNominalSplit", () => { - it("should return null", () => { + it("should return nominal split", () => { expect(getNominalSplit(essenceWithNominalSplit)).to.be.equivalent(channelSplit); }); }); describe("getNominalDimension", () => { - it("should return null", () => { - expect(getNominalDimension(essenceWithNominalSplit)).to.be.equivalent(channelDimension); + it("should return nominal split", () => { + expect(getNominalDimension(essenceWithNominalSplit)).to.be.deep.equal(channelDimension); }); }); describe("hasNominalSplit", () => { - it("should return false", () => { + it("should return true", () => { expect(hasNominalSplit(essenceWithNominalSplit)).to.be.true; }); }); diff --git a/src/common/models/dimension/dimension.fixtures.ts b/src/common/models/dimension/dimension.fixtures.ts index 33bcbf330..60f2229ce 100644 --- a/src/common/models/dimension/dimension.fixtures.ts +++ b/src/common/models/dimension/dimension.fixtures.ts @@ -89,8 +89,8 @@ export class DimensionFixtures { return createDimension("string", "page", $("page")); } - static userCharts() { - return createDimension("string", "userCharts", $("userCharts")); + static userChars() { + return createDimension("string", "userChars", $("userChars")); } static pageLastAuthor() { diff --git a/src/common/models/dimension/dimension.mocha.ts b/src/common/models/dimension/dimension.mocha.ts deleted file mode 100644 index 5cf51d928..000000000 --- a/src/common/models/dimension/dimension.mocha.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2015-2016 Imply Data, Inc. - * Copyright 2017-2019 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 } from "chai"; -import { Dimension, DimensionKind, fromConfig } from "./dimension"; - -describe("Dimension", () => { - describe("errors", () => { - it("throws on invalid type", () => { - var dimJS = { - name: "mixed_granularities", - title: "Mixed Granularities", - kind: "string" as DimensionKind, - granularities: [5, 50, "P1W", 800, 1000] - }; - - expect(() => { - fromConfig(dimJS); - }).to.throw("granularities must have the same type of actions"); - - var dimJS2 = { - name: "bad type", - title: "Bad Type", - kind: "string", - granularities: [false, true, true, false, false] - }; - - expect(() => { - fromConfig(dimJS2 as any); - }).to.throw("input should be number or Duration"); - - }); - - }); - -}) -; diff --git a/src/common/models/dimension/dimensions.fixtures.ts b/src/common/models/dimension/dimensions.fixtures.ts index 35e63ec73..e9d0e937c 100644 --- a/src/common/models/dimension/dimensions.fixtures.ts +++ b/src/common/models/dimension/dimensions.fixtures.ts @@ -15,7 +15,7 @@ */ import { fromEntries } from "../../utils/object/object"; -import { Dimension } from "./dimension"; +import { Dimension, DimensionJS } from "./dimension"; import { DimensionFixtures } from "./dimension.fixtures"; import { DimensionGroupJS, Dimensions } from "./dimensions"; @@ -24,17 +24,7 @@ export class DimensionsFixtures { return { name: "dummyName", dimensions: [ - // DimensionFixtures.wikiTimeJS() - ] - }; - } - - static withTitleInferredJS(): DimensionGroupJS { - return { - name: "dummyName", - title: "Dummy Name", - dimensions: [ - // DimensionFixtures.wikiTimeJS() + ...DimensionsFixtures.dimensions() ] }; } @@ -42,7 +32,7 @@ export class DimensionsFixtures { static noNameJS(): DimensionGroupJS { return { dimensions: [ - // DimensionFixtures.wikiTimeJS() + ...DimensionsFixtures.dimensions() ] } as DimensionGroupJS; } @@ -60,31 +50,27 @@ export class DimensionsFixtures { } as DimensionGroupJS; } - static commentsJS(): DimensionGroupJS { - return { - name: "comment_group", - title: "Comment Group", - dimensions: [ - { - kind: "string", - name: "comment", - title: "Comment", - formula: "$comment" - }, - { - kind: "number", - name: "commentLength", - title: "Comment Length", - formula: "$commentLength" - }, - { - kind: "boolean", - name: "commentLengthOver100", - title: "Comment Length Over 100", - formula: "$commentLength > 100" - } - ] - }; + static dimensions(): DimensionJS[] { + return [ + { + kind: "string", + name: "comment", + title: "Comment", + formula: "$comment" + }, + { + kind: "number", + name: "commentLength", + title: "Comment Length", + formula: "$commentLength" + }, + { + kind: "boolean", + name: "commentLengthOver100", + title: "Comment Length Over 100", + formula: "$commentLength > 100" + } + ]; } static fromDimensions(dimensions: Dimension[]): Dimensions { @@ -111,7 +97,7 @@ export class DimensionsFixtures { articleName: DimensionFixtures.articleName(), page: DimensionFixtures.page(), page_last_author: DimensionFixtures.pageLastAuthor(), - userCharts: DimensionFixtures.userCharts() + userChars: DimensionFixtures.userChars() }; return { @@ -119,7 +105,7 @@ export class DimensionsFixtures { name: "comment_group", title: "Comment Group", dimensions: ["comment", "commentLength", "commentLengthOver100"] - }, "isRobot", "namespace", "articleName", "page", "page_last_author", "userCharts"], + }, "isRobot", "namespace", "articleName", "page", "page_last_author", "userChars"], byName }; } diff --git a/src/common/models/dimension/dimensions.mocha.ts b/src/common/models/dimension/dimensions.mocha.ts index ae44ff7e9..ad139f89d 100644 --- a/src/common/models/dimension/dimensions.mocha.ts +++ b/src/common/models/dimension/dimensions.mocha.ts @@ -15,27 +15,14 @@ */ import { expect } from "chai"; -import { fromConfig } from "./dimensions"; +import { DimensionsGroup, fromConfig } from "./dimensions"; import { DimensionsFixtures } from "./dimensions.fixtures"; describe("DimensionGroup", () => { - - it("should convert to / from JS", () => { - const dimensionGroup = fromConfig([DimensionsFixtures.commentsJS()]); - - expect(dimensionGroup).to.deep.equal(DimensionsFixtures.commentsJS()); - }); - it("should infer title from name", () => { - const dimensionGroup = fromConfig([DimensionsFixtures.noTitleJS()]); + const { tree } = fromConfig([DimensionsFixtures.noTitleJS()]); - expect(dimensionGroup).to.deep.equal(DimensionsFixtures.withTitleInferredJS()); - }); - - it("should infer title from name", () => { - const dimensionGroup = fromConfig([DimensionsFixtures.noTitleJS()]); - - expect(dimensionGroup).to.deep.equal(DimensionsFixtures.withTitleInferredJS()); + expect((tree[0] as DimensionsGroup).title).to.equal("Dummy Name"); }); it("should throw when no name given", () => { @@ -44,13 +31,6 @@ describe("DimensionGroup", () => { expect(dimensionGroupConversion).to.throw("dimension group requires a name"); }); - it("should throw when no dimensions given", () => { - const groupWithNoDimensions = DimensionsFixtures.noDimensionsJS(); - const dimensionGroupConversion = () => fromConfig([groupWithNoDimensions]); - - expect(dimensionGroupConversion).to.throw(`dimension group '${groupWithNoDimensions.name}' has no dimensions`); - }); - it("should throw when empty dimensions given", () => { const groupWithEmptyDimensions = DimensionsFixtures.emptyDimensionsJS(); const dimensionGroupConversion = () => fromConfig([groupWithEmptyDimensions]); diff --git a/src/common/models/dimension/dimensions.ts b/src/common/models/dimension/dimensions.ts index c5b083ea3..1b62cf61e 100644 --- a/src/common/models/dimension/dimensions.ts +++ b/src/common/models/dimension/dimensions.ts @@ -65,7 +65,7 @@ export function fromConfig(config: DimensionOrGroupJS[]): Dimensions { throw new Error("dimension group requires a name"); } - if (dimensions == null || dimensions.length === 0) { + if (!Array.isArray(dimensions) || dimensions.length === 0) { throw new Error(`dimension group '${name}' has no dimensions`); } return { diff --git a/src/common/models/essence/essence.mocha.ts b/src/common/models/essence/essence.mocha.ts index 70e602cfb..b79fdf6a4 100644 --- a/src/common/models/essence/essence.mocha.ts +++ b/src/common/models/essence/essence.mocha.ts @@ -21,9 +21,7 @@ import { BAR_CHART_MANIFEST } from "../../visualization-manifests/bar-chart/bar- import { LINE_CHART_MANIFEST } from "../../visualization-manifests/line-chart/line-chart"; import { TABLE_MANIFEST } from "../../visualization-manifests/table/table"; import { TOTALS_MANIFEST } from "../../visualization-manifests/totals/totals"; -import { DataCube, Introspection } from "../data-cube/data-cube"; import { twitterClientDataCube } from "../data-cube/data-cube.fixtures"; -import { DimensionKind } from "../dimension/dimension"; import { TimeFilterPeriod } from "../filter-clause/filter-clause"; import { timePeriod } from "../filter-clause/filter-clause.fixtures"; import { Filter } from "../filter/filter"; @@ -37,47 +35,7 @@ import { TimeShift } from "../time-shift/time-shift"; import { Essence, VisStrategy } from "./essence"; import { EssenceFixtures } from "./essence.fixtures"; -// TODO: Implement? Solve "serialization" of data cube inside essence describe("EssenceProps", () => { - var dataCubeJS = { - name: "twitter", - title: "Twitter", - clusterName: "druid", - source: "twitter", - introspection: ("none" as Introspection), - dimensions: [ - { - kind: "time" as DimensionKind, - name: "time", - title: "Time", - formula: "$time" - }, - { - kind: "string" as DimensionKind, - name: "twitterHandle", - title: "Twitter Handle", - formula: "$twitterHandle" - } - ], - measures: [ - { - name: "count", - title: "count", - formula: "$main.count()" - } - ], - timeAttribute: "time", - defaultTimezone: "Etc/UTC", - defaultSplits: "time", - defaultDuration: "P3D", - defaultSortMeasure: "count", - defaultPinnedDimensions: ["twitterHandle"], - refreshRule: { - rule: "fixed", - time: new Date("2015-09-13T00:00:00Z") - } - }; - const dataCube = twitterClientDataCube; describe(".fromDataCube", () => { diff --git a/src/common/view-definitions/test/dimension.ts b/src/common/view-definitions/test/dimension.ts index 6851e5153..cb72f51c5 100644 --- a/src/common/view-definitions/test/dimension.ts +++ b/src/common/view-definitions/test/dimension.ts @@ -25,6 +25,7 @@ export const timeDimension = createDimension("time", "time", $("time")); export const dimensions: Dimensions = DimensionsFixtures.fromDimensions([ timeDimension, + createDimension("number", "numeric", $("numeric")), createDimension("string", "string_a", $("string_a")), createDimension("string", "string_b", $("string_b")), createDimension("boolean", "boolean", $("boolean"))