@gooddata/gooddata-js
Version:
GoodData JavaScript SDK
286 lines (247 loc) • 9.14 kB
text/typescript
// (C) 2007-2020 GoodData Corporation
import {
simpleMeasure,
simpleMeasureWithFormat,
simpleMeasureWithIdentifiers,
simpleMeasureWithTextFilter,
renamedMeasure,
filteredMeasure,
measureWithAbsoluteDate,
measureWithRelativeDate,
popMeasure,
popMeasureWithSorting,
showInPercent,
showInPercentWithDate,
measureWithSorting,
categoryWithSorting,
factBasedMeasure,
factBasedRenamedMeasure,
attributeBasedMeasure,
attributeBasedRenamedMeasure,
stackingAttribute,
stackingRenamedAttribute,
attributeFilter,
attributeTextFilter,
attributeFilterWithAll,
dateFilter,
dateFilterWithoutInterval,
measureValueFilter,
measureValueFilterWithoutCondition,
oneMeasureOneAttribute,
oneMeasureOneAttributeWithIdentifiers,
reducedMultipleSorts,
nativeSubTotals,
nativeSubtotalsInTwoDimensions,
} from "./fixtures/Afm.fixtures";
import {
charts,
tables,
visualizationObjectWithLocationAttribute,
visualizationObjectWithLocationAliasAttribute,
} from "./fixtures/VisObj.fixtures";
import { toAfmResultSpec } from "../toAfmResultSpec";
describe("toAfmResultSpec", () => {
it("should convert simple measures", () => {
expect(toAfmResultSpec(charts.simpleMeasure)).toEqual({
...simpleMeasure,
});
});
it("should convert simple measures with identifiers", () => {
expect(toAfmResultSpec(charts.simpleMeasureWithIdentifiers)).toEqual({
...simpleMeasureWithIdentifiers,
});
});
it("should convert simple measure with format", () => {
expect(toAfmResultSpec(charts.simpleMeasureWithFormat)).toEqual({
...simpleMeasureWithFormat,
});
});
it("should convert simple measure with text filter", () => {
expect(toAfmResultSpec(charts.simpleMeasureWithTextFilter)).toEqual({
...simpleMeasureWithTextFilter,
});
});
it("should convert simple renamed measures", () => {
expect(toAfmResultSpec(charts.renamedMeasure)).toEqual({
...renamedMeasure,
});
});
it("should convert filtered measures", () => {
expect(toAfmResultSpec(charts.filteredMeasure)).toEqual({
...filteredMeasure,
});
});
it("should convert relative date filtered measures", () => {
expect(toAfmResultSpec(charts.measureWithRelativeDate)).toEqual({
...measureWithRelativeDate,
});
});
it("should convert absolute date filtered measures", () => {
expect(toAfmResultSpec(charts.measureWithAbsoluteDate)).toEqual({
...measureWithAbsoluteDate,
});
});
it("should convert fact based measures", () => {
expect(toAfmResultSpec(charts.factBasedMeasure)).toEqual({
...factBasedMeasure,
});
});
it("should convert fact based renamed measures", () => {
expect(toAfmResultSpec(charts.factBasedRenamedMeasure)).toEqual({
...factBasedRenamedMeasure,
});
});
it("should convert attribute based measures", () => {
expect(toAfmResultSpec(charts.attributeBasedMeasure)).toEqual({
...attributeBasedMeasure,
});
});
it("should convert attribute based measures and add its default format #,##0", () => {
expect(toAfmResultSpec(charts.attributeBasedMeasureWithoutFormat)).toEqual({
...attributeBasedMeasure,
});
});
it("should convert attribute based renamed measures", () => {
expect(toAfmResultSpec(charts.attributeBasedRenamedMeasure)).toEqual({
...attributeBasedRenamedMeasure,
});
});
it("should convert measure with show in percent with attribute", () => {
expect(toAfmResultSpec(charts.showInPercent)).toEqual({
...showInPercent,
});
});
it("should convert measure with show in percent and add its default format #,##0.00%", () => {
expect(toAfmResultSpec(charts.showInPercentWithoutFormat)).toEqual({
...showInPercent,
});
});
it("should convert measure with show in percent with date", () => {
expect(toAfmResultSpec(charts.showInPercentWithDate)).toEqual({
...showInPercentWithDate,
});
});
it("should convert measure with sorting", () => {
expect(toAfmResultSpec(charts.measureWithSorting)).toEqual({
...measureWithSorting,
});
});
it("should convert pop measure", () => {
expect(toAfmResultSpec(charts.popMeasure)).toEqual({
...popMeasure,
});
});
it("should convert pop measure with sorting", () => {
expect(toAfmResultSpec(charts.popMeasureWithSorting)).toEqual({
...popMeasureWithSorting,
});
});
it("should convert category with sorting", () => {
expect(toAfmResultSpec(charts.categoryWithSorting)).toEqual({
...categoryWithSorting,
});
});
it("should convert attribute filter", () => {
expect(toAfmResultSpec(charts.attributeFilter)).toEqual({
...attributeFilter,
});
});
it("should convert attribute filter", () => {
expect(toAfmResultSpec(charts.attributeTextFilter)).toEqual({
...attributeTextFilter,
});
});
it("should convert date filter", () => {
expect(toAfmResultSpec(charts.dateFilter)).toEqual({
...dateFilter,
});
});
it("should convert date filter with from/to as strings", () => {
expect(toAfmResultSpec(charts.dateFilterWithStrings)).toEqual({
...dateFilter,
});
});
it("should skip filter when date filter from/to is undefined for relative (alltime)", () => {
expect(toAfmResultSpec(charts.dateFilterWithUndefs)).toEqual({
...dateFilterWithoutInterval,
});
});
it("should convert measure value filter", () => {
expect(toAfmResultSpec(charts.measureValueFilter)).toEqual({
...measureValueFilter,
});
});
it("should convert measure value filter when condition is undefined", () => {
expect(toAfmResultSpec(charts.measureValueFilterWithoutCondition)).toEqual({
...measureValueFilterWithoutCondition,
});
});
it("should convert stacking renamed attribute", () => {
expect(toAfmResultSpec(charts.stackingRenamedAttribute)).toEqual({
...stackingRenamedAttribute,
});
});
it("should skip attribute filter with ALL", () => {
expect(toAfmResultSpec(charts.attributeFilterWithAll)).toEqual({
...attributeFilterWithAll,
});
});
it("should convert stacking attribute as normal attribute, conversion has no semantic for buckets", () => {
expect(toAfmResultSpec(charts.stackingAttribute)).toEqual({
...stackingAttribute,
});
});
it("should convert table as generic chart, conversion has no semantic for buckets", () => {
expect(toAfmResultSpec(tables.oneMeasureOneAttribute)).toEqual({
...oneMeasureOneAttribute,
});
});
it("should convert table with identifiers", () => {
expect(toAfmResultSpec(tables.oneMeasureOneAttributeWithIdentifiers)).toEqual({
...oneMeasureOneAttributeWithIdentifiers,
});
});
it("should convert only one sort item", () => {
expect(toAfmResultSpec(tables.multipleSorts)).toEqual({
...reducedMultipleSorts,
});
});
it("should convert native subtotals", () => {
expect(toAfmResultSpec(tables.twoAttributesAndNativeSubtotals)).toEqual(nativeSubTotals);
});
it("should convert native subtotals from multiple dimensions", () => {
expect(toAfmResultSpec(tables.twoDimensionsAndNativeSubtotals)).toEqual(
nativeSubtotalsInTwoDimensions,
);
});
it("should convert geo attribute for tooltip text", () => {
expect(toAfmResultSpec(visualizationObjectWithLocationAttribute).afm).toEqual({
attributes: [
{
displayForm: { uri: "/gdc/md/pid/obj/87" },
localIdentifier: "a1",
},
{
displayForm: { uri: "/gdc/md/pid/obj/88" },
localIdentifier: "tooltipText",
},
],
});
});
it("should convert geo attribute for tooltip text with alias", () => {
expect(toAfmResultSpec(visualizationObjectWithLocationAliasAttribute).afm).toEqual({
attributes: [
{
displayForm: { uri: "/gdc/md/pid/obj/87" },
localIdentifier: "a1",
alias: "location alias",
},
{
displayForm: { uri: "/gdc/md/pid/obj/88" },
localIdentifier: "tooltipText",
alias: "location alias",
},
],
});
});
});