Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianmroz-allegro committed May 31, 2021
1 parent c1b89aa commit c4d0428
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 159 deletions.
4 changes: 2 additions & 2 deletions src/common/models/dimension/dimension.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
51 changes: 0 additions & 51 deletions src/common/models/dimension/dimension.mocha.ts

This file was deleted.

66 changes: 26 additions & 40 deletions src/common/models/dimension/dimensions.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -24,25 +24,15 @@ export class DimensionsFixtures {
return {
name: "dummyName",
dimensions: [
// DimensionFixtures.wikiTimeJS()
]
};
}

static withTitleInferredJS(): DimensionGroupJS {
return {
name: "dummyName",
title: "Dummy Name",
dimensions: [
// DimensionFixtures.wikiTimeJS()
...DimensionsFixtures.dimensions()
]
};
}

static noNameJS(): DimensionGroupJS {
return {
dimensions: [
// DimensionFixtures.wikiTimeJS()
...DimensionsFixtures.dimensions()
]
} as DimensionGroupJS;
}
Expand All @@ -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 {
Expand All @@ -111,15 +97,15 @@ export class DimensionsFixtures {
articleName: DimensionFixtures.articleName(),
page: DimensionFixtures.page(),
page_last_author: DimensionFixtures.pageLastAuthor(),
userCharts: DimensionFixtures.userCharts()
userChars: DimensionFixtures.userChars()
};

return {
tree: ["time", "country", "channel", {
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
};
}
Expand Down
26 changes: 3 additions & 23 deletions src/common/models/dimension/dimensions.mocha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand All @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion src/common/models/dimension/dimensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
42 changes: 0 additions & 42 deletions src/common/models/essence/essence.mocha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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", () => {
Expand Down
1 change: 1 addition & 0 deletions src/common/view-definitions/test/dimension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit c4d0428

Please sign in to comment.