Skip to content

Commit

Permalink
Merge pull request gooddata#4912 from scavnickyj/jsc-repeater-tests
Browse files Browse the repository at this point in the history
Repeater storybook and api regression tests

Reviewed-by: https://github.com/kandl
  • Loading branch information
gdgate authored Apr 16, 2024
2 parents f360dcf + b74d077 commit d037496
Show file tree
Hide file tree
Showing 54 changed files with 12,661 additions and 13 deletions.
11 changes: 10 additions & 1 deletion libs/sdk-model/src/execution/objectFactoryNotation/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// (C) 2019-2022 GoodData Corporation
// (C) 2019-2024 GoodData Corporation
import compact from "lodash/compact.js";
import flow from "lodash/flow.js";
import isNil from "lodash/isNil.js";
Expand Down Expand Up @@ -43,6 +43,8 @@ import {
IArithmeticMeasureDefinition,
IPoPMeasureDefinition,
IPreviousPeriodMeasureDefinition,
isInlineMeasureDefinition,
IInlineMeasureDefinition,
} from "../measure/index.js";
import { isAttribute, IAttribute } from "../attribute/index.js";
import { isTotal, ITotal } from "../base/totals.js";
Expand Down Expand Up @@ -139,6 +141,11 @@ const convertPopMeasure = (measure: IMeasure["measure"], definition: IPoPMeasure
)}, ${builder})`;
};

const convertInlineMeasure = (measure: IMeasure["measure"], definition: IInlineMeasureDefinition) => {
const builder = getBuilder("m => m", baseMeasureDotAdders(measure));
return `newInlineMeasure(${stringify(definition.inlineDefinition.maql)}, ${builder})`;
};

const convertPreviousPeriodMeasure = (
measure: IMeasure["measure"],
definition: IPreviousPeriodMeasureDefinition,
Expand All @@ -165,6 +172,8 @@ const convertMeasure: Converter<IMeasure> = ({ measure }) => {
return convertPopMeasure(measure, definition);
} else if (isPreviousPeriodMeasureDefinition(definition)) {
return convertPreviousPeriodMeasure(measure, definition);
} else if (isInlineMeasureDefinition(definition)) {
return convertInlineMeasure(measure, definition);
}
throw new Error("Unknown measure type");
};
Expand Down
3 changes: 2 additions & 1 deletion libs/sdk-ui-charts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"./internal-tests/CoreSankeyChart": "./esm/charts/sankeyChart/CoreSankeyChart.js",
"./internal-tests/CoreScatterPlot": "./esm/charts/scatterPlot/CoreScatterPlot.js",
"./internal-tests/CoreTreemap": "./esm/charts/treemap/CoreTreemap.js",
"./internal-tests/CoreXirr": "./esm/charts/xirr/CoreXirr.js"
"./internal-tests/CoreXirr": "./esm/charts/xirr/CoreXirr.js",
"./internal-tests/CoreRepeater": "./esm/charts/repeater/CoreRepeater.js"
},
"types": "./esm/index.d.ts",
"sideEffects": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46800,6 +46800,243 @@ export function MyComponent() {
"
`;

exports[`getEmbeddingCode functionality > should generate code for Repeater - canvas - large row height 1`] = `
"import React from "react";
import { IAttribute, IAttributeOrMeasure, idRef, newAttribute, newMeasure } from "@gooddata/sdk-model";
import { IChartConfig, Repeater } from "@gooddata/sdk-ui-charts";

const attribute: IAttribute = newAttribute(idRef("f_city.id.cityname", "displayForm"), a => a.localId("a_f_city.id.cityname"));
const columns: IAttributeOrMeasure[] = [
newAttribute(idRef("f_city.id.cityname", "displayForm"), a => a.localId("a_f_city.id.cityname_1")),
newInlineMeasure("SELECT {metric/of_lost_opps.} BY ALL OTHER EXCEPT {label/f_city.id.cityname}", m => m.localId("m_7bd77a90_inline").title("# of Lost Opps.")),
newMeasure(idRef("of_lost_opps.", "measure"), m => m.localId("m_of_lost_opps."))
];
const viewBy: IAttribute = newAttribute(idRef("attr.f_product.product", "displayForm"), a => a.localId("a_attr.f_product.product"));
const config: IChartConfig = {
inlineVisualizations: {"m_of_lost_opps.": {type: "column"}},
rowHeight: "large",
separators: {decimal: ".", thousand: ","},
legend: {position: "auto"},
dataPoints: {visible: "auto"}
};
const style = {height: 400};

export function MyComponent() {
return (
<div style={style}>
<Repeater
attribute={attribute}
columns={columns}
viewBy={viewBy}
config={config}
/>
</div>
);
}
"
`;

exports[`getEmbeddingCode functionality > should generate code for Repeater - coloring - custom palette 1`] = `
"import React from "react";
import { IAttribute, IAttributeOrMeasure, idRef, newAttribute, newMeasure } from "@gooddata/sdk-model";
import { IChartConfig, Repeater } from "@gooddata/sdk-ui-charts";

const attribute: IAttribute = newAttribute(idRef("f_city.id.cityname", "displayForm"), a => a.localId("a_f_city.id.cityname"));
const columns: IAttributeOrMeasure[] = [
newAttribute(idRef("f_city.id.cityname", "displayForm"), a => a.localId("a_f_city.id.cityname_1")),
newInlineMeasure("SELECT {metric/of_lost_opps.} BY ALL OTHER EXCEPT {label/f_city.id.cityname}", m => m.localId("m_7bd77a90_inline").title("# of Lost Opps.")),
newMeasure(idRef("of_lost_opps.", "measure"), m => m.localId("m_of_lost_opps."))
];
const viewBy: IAttribute = newAttribute(idRef("attr.f_product.product", "displayForm"), a => a.localId("a_attr.f_product.product"));
const config: IChartConfig = {
inlineVisualizations: {"m_of_lost_opps.": {type: "column"}},
separators: {decimal: ".", thousand: ","},
legend: {position: "auto"},
dataPoints: {visible: "auto"}
};
const style = {height: 400};

export function MyComponent() {
return (
<div style={style}>
<Repeater
attribute={attribute}
columns={columns}
viewBy={viewBy}
config={config}
/>
</div>
);
}
"
`;

exports[`getEmbeddingCode functionality > should generate code for Repeater - font 1`] = `
"import React from "react";
import { IAttribute, IAttributeOrMeasure, idRef, newAttribute, newMeasure } from "@gooddata/sdk-model";
import { IChartConfig, Repeater } from "@gooddata/sdk-ui-charts";

const attribute: IAttribute = newAttribute(idRef("f_city.id.cityname", "displayForm"), a => a.localId("a_f_city.id.cityname"));
const columns: IAttributeOrMeasure[] = [
newAttribute(idRef("f_city.id.cityname", "displayForm"), a => a.localId("a_f_city.id.cityname_1")),
newInlineMeasure("SELECT {metric/of_lost_opps.} BY ALL OTHER EXCEPT {label/f_city.id.cityname}", m => m.localId("m_7bd77a90_inline").title("# of Lost Opps.")),
newMeasure(idRef("of_lost_opps.", "measure"), m => m.localId("m_of_lost_opps."))
];
const viewBy: IAttribute = newAttribute(idRef("attr.f_product.product", "displayForm"), a => a.localId("a_attr.f_product.product"));
const config: IChartConfig = {
inlineVisualizations: {"m_of_lost_opps.": {type: "column"}},
separators: {decimal: ".", thousand: ","},
legend: {position: "auto"},
dataPoints: {visible: "auto"}
};
const style = {height: 400};

export function MyComponent() {
return (
<div style={style}>
<Repeater
attribute={attribute}
columns={columns}
viewBy={viewBy}
config={config}
/>
</div>
);
}
"
`;

exports[`getEmbeddingCode functionality > should generate code for Repeater - one attribute 1`] = `
"import React from "react";
import { IAttribute, IAttributeOrMeasure, idRef, newAttribute } from "@gooddata/sdk-model";
import { IChartConfig, Repeater } from "@gooddata/sdk-ui-charts";

const attribute: IAttribute = newAttribute(idRef("f_city.id.cityname", "displayForm"), a => a.localId("a_f_city.id.cityname"));
const columns: IAttributeOrMeasure[] = [
newAttribute(idRef("f_city.id.cityname", "displayForm"), a => a.localId("a_f_city.id.cityname_1"))
];
const config: IChartConfig = {
separators: {decimal: ".", thousand: ","},
legend: {position: "auto"},
dataPoints: {visible: "auto"}
};
const style = {height: 400};

export function MyComponent() {
return (
<div style={style}>
<Repeater
attribute={attribute}
columns={columns}
config={config}
/>
</div>
);
}
"
`;

exports[`getEmbeddingCode functionality > should generate code for Repeater - one attribute and one measure 1`] = `
"import React from "react";
import { IAttribute, IAttributeOrMeasure, idRef, newAttribute, newMeasure } from "@gooddata/sdk-model";
import { IChartConfig, Repeater } from "@gooddata/sdk-ui-charts";

const attribute: IAttribute = newAttribute(idRef("f_city.id.cityname", "displayForm"), a => a.localId("a_f_city.id.cityname"));
const columns: IAttributeOrMeasure[] = [
newAttribute(idRef("f_city.id.cityname", "displayForm"), a => a.localId("a_f_city.id.cityname_1")),
newMeasure(idRef("of_lost_opps.", "measure"), m => m.localId("m_of_lost_opps."))
];
const config: IChartConfig = {
separators: {decimal: ".", thousand: ","},
legend: {position: "auto"},
dataPoints: {visible: "auto"}
};
const style = {height: 400};

export function MyComponent() {
return (
<div style={style}>
<Repeater
attribute={attribute}
columns={columns}
config={config}
/>
</div>
);
}
"
`;

exports[`getEmbeddingCode functionality > should generate code for Repeater - one attribute and one visualisation 1`] = `
"import React from "react";
import { IAttribute, IAttributeOrMeasure, idRef, newAttribute, newMeasure } from "@gooddata/sdk-model";
import { IChartConfig, Repeater } from "@gooddata/sdk-ui-charts";

const attribute: IAttribute = newAttribute(idRef("f_city.id.cityname", "displayForm"), a => a.localId("a_f_city.id.cityname"));
const columns: IAttributeOrMeasure[] = [
newAttribute(idRef("f_city.id.cityname", "displayForm"), a => a.localId("a_f_city.id.cityname_1")),
newInlineMeasure("SELECT {metric/of_lost_opps.} BY ALL OTHER EXCEPT {label/f_city.id.cityname}", m => m.localId("m_7bd77a90_inline").title("# of Lost Opps.")),
newMeasure(idRef("of_lost_opps.", "measure"), m => m.localId("m_of_lost_opps."))
];
const viewBy: IAttribute = newAttribute(idRef("attr.f_product.product", "displayForm"), a => a.localId("a_attr.f_product.product"));
const config: IChartConfig = {
inlineVisualizations: {"m_of_lost_opps.": {type: "column"}},
separators: {decimal: ".", thousand: ","},
legend: {position: "auto"},
dataPoints: {visible: "auto"}
};
const style = {height: 400};

export function MyComponent() {
return (
<div style={style}>
<Repeater
attribute={attribute}
columns={columns}
viewBy={viewBy}
config={config}
/>
</div>
);
}
"
`;

exports[`getEmbeddingCode functionality > should generate code for Repeater - themed 1`] = `
"import React from "react";
import { IAttribute, IAttributeOrMeasure, idRef, newAttribute, newMeasure } from "@gooddata/sdk-model";
import { IChartConfig, Repeater } from "@gooddata/sdk-ui-charts";

const attribute: IAttribute = newAttribute(idRef("f_city.id.cityname", "displayForm"), a => a.localId("a_f_city.id.cityname"));
const columns: IAttributeOrMeasure[] = [
newAttribute(idRef("f_city.id.cityname", "displayForm"), a => a.localId("a_f_city.id.cityname_1")),
newInlineMeasure("SELECT {metric/of_lost_opps.} BY ALL OTHER EXCEPT {label/f_city.id.cityname}", m => m.localId("m_7bd77a90_inline").title("# of Lost Opps.")),
newMeasure(idRef("of_lost_opps.", "measure"), m => m.localId("m_of_lost_opps."))
];
const viewBy: IAttribute = newAttribute(idRef("attr.f_product.product", "displayForm"), a => a.localId("a_attr.f_product.product"));
const config: IChartConfig = {
inlineVisualizations: {"m_of_lost_opps.": {type: "column"}},
separators: {decimal: ".", thousand: ","},
legend: {position: "auto"},
dataPoints: {visible: "auto"}
};
const style = {height: 400};

export function MyComponent() {
return (
<div style={style}>
<Repeater
attribute={attribute}
columns={columns}
viewBy={viewBy}
config={config}
/>
</div>
);
}
"
`;

exports[`getEmbeddingCode functionality > should generate code for SankeyChart - 180x154 - Force position TOP, max 1 row, Gradient legend minimized - auto legend 1`] = `
"import React from "react";
import { IAttribute, IAttributeOrMeasure, idRef, newAttribute, newMeasure } from "@gooddata/sdk-model";
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 11 additions & 2 deletions libs/sdk-ui-tests/backstop/scenarios.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// (C) 2007-2019 GoodData Corporation
// (C) 2007-2024 GoodData Corporation

const stories = require("./stories");

Expand All @@ -24,10 +24,19 @@ const stories = require("./stories");
*/

const ScenarioConfig = [
{
/*
* Tests for repeater stories - either created automatically for test scenarios or created manually.
*/
idRegex: /(01).*Repeater.*/g,
config: {
delay: 2500,
},
},
{
// this is for customization stories that generate multiple variants with different config; we have
// a special ready wrapper for these
idRegex: /.*(data labels|coloring|legend)/g,
idRegex: /.*(data labels|coloring|legend|canvas)/g,
config: {
readySelector: ".screenshot-ready-wrapper-done",
},
Expand Down
18 changes: 18 additions & 0 deletions libs/sdk-ui-tests/scenarios/charts/_infra/canvasVariants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// (C) 2024 GoodData Corporation

import { IChartConfig, IBucketChartProps } from "@gooddata/sdk-ui-charts";
import { CustomizedScenario, UnboundVisProps } from "../../../src/index.js";

export const ConfigVariants: Array<[string, IChartConfig]> = [["large row height", { rowHeight: "large" }]];

export function canvasCustomizer<T extends IBucketChartProps>(
baseName: string,
baseProps: UnboundVisProps<T>,
): Array<CustomizedScenario<T>> {
return ConfigVariants.map(([variantName, canvasOverlay]) => {
return [
`${baseName} - ${variantName}`,
{ ...baseProps, config: { ...baseProps.config, ...canvasOverlay } },
];
});
}
4 changes: 3 additions & 1 deletion libs/sdk-ui-tests/scenarios/charts/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// (C) 2007-2019 GoodData Corporation
// (C) 2007-2024 GoodData Corporation

import areaChart from "./areaChart/index.js";
import barChart from "./barChart/index.js";
Expand All @@ -19,6 +19,7 @@ import sankeyChart from "./sankeyChart/index.js";
import xirr from "./xirr/index.js";
import dependencyWheelChart from "./dependencyWheelChart/index.js";
import waterfallChart from "./waterfallChart/index.js";
import repeater from "./repeater/index.js";

export default [
...areaChart,
Expand All @@ -40,4 +41,5 @@ export default [
...dependencyWheelChart,
...xirr,
...waterfallChart,
...repeater,
];
Loading

0 comments on commit d037496

Please sign in to comment.