|
1 |
| -import { ColumnConfig, ScatterPlotConfig, TableFields } from "@/configurator"; |
| 1 | +import { |
| 2 | + ColumnConfig, |
| 3 | + ComboLineDualConfig, |
| 4 | + ScatterPlotConfig, |
| 5 | + TableFields, |
| 6 | +} from "@/configurator"; |
2 | 7 | import { Dimension, Measure } from "@/domain/data";
|
3 | 8 | import { stringifyComponentId } from "@/graphql/make-component-id";
|
4 | 9 | import { TimeUnit } from "@/graphql/resolver-types";
|
@@ -436,4 +441,62 @@ describe("chart type switch", () => {
|
436 | 441 | oldChartConfig.fields.x.componentId
|
437 | 442 | );
|
438 | 443 | });
|
| 444 | + |
| 445 | + it("should prefer to use components from different cubes if merging cubes, otherwise not", () => { |
| 446 | + const oldChartConfig = { |
| 447 | + chartType: "column", |
| 448 | + cubes: [{ iri: "A" }], |
| 449 | + fields: { |
| 450 | + x: { |
| 451 | + componentId: "A_D1", |
| 452 | + }, |
| 453 | + y: { |
| 454 | + componentId: "A_M1", |
| 455 | + }, |
| 456 | + }, |
| 457 | + } as any as ColumnConfig; |
| 458 | + const dimensions = [ |
| 459 | + { id: "A_D1", cubeIri: "A" }, |
| 460 | + { __typename: "TemporalDimension", id: "B_D1", cubeIri: "B" }, |
| 461 | + ] as any as Dimension[]; |
| 462 | + const measures = [ |
| 463 | + { __typename: "NumericalMeasure", id: "A_M1", cubeIri: "A", unit: "X" }, |
| 464 | + { __typename: "NumericalMeasure", id: "A_M2", cubeIri: "A", unit: "Y" }, |
| 465 | + { __typename: "NumericalMeasure", id: "B_M1", cubeIri: "B", unit: "Z" }, |
| 466 | + ] as any as Measure[]; |
| 467 | + |
| 468 | + const newChartConfigMergingOfCubes = getChartConfigAdjustedToChartType({ |
| 469 | + chartConfig: oldChartConfig, |
| 470 | + newChartType: "comboLineDual", |
| 471 | + dimensions, |
| 472 | + measures, |
| 473 | + isAddingNewCube: true, |
| 474 | + }) as ComboLineDualConfig; |
| 475 | + |
| 476 | + expect( |
| 477 | + newChartConfigMergingOfCubes.fields.y.rightAxisComponentId.startsWith("A") |
| 478 | + ).toEqual(true); |
| 479 | + expect( |
| 480 | + newChartConfigMergingOfCubes.fields.y.leftAxisComponentId.startsWith("B") |
| 481 | + ).toEqual(true); |
| 482 | + |
| 483 | + const newChartConfigNotMergingOfCubes = getChartConfigAdjustedToChartType({ |
| 484 | + chartConfig: oldChartConfig, |
| 485 | + newChartType: "comboLineDual", |
| 486 | + dimensions, |
| 487 | + measures, |
| 488 | + isAddingNewCube: false, |
| 489 | + }) as ComboLineDualConfig; |
| 490 | + |
| 491 | + expect( |
| 492 | + newChartConfigNotMergingOfCubes.fields.y.rightAxisComponentId.startsWith( |
| 493 | + "A" |
| 494 | + ) |
| 495 | + ).toEqual(true); |
| 496 | + expect( |
| 497 | + newChartConfigNotMergingOfCubes.fields.y.leftAxisComponentId.startsWith( |
| 498 | + "A" |
| 499 | + ) |
| 500 | + ).toEqual(true); |
| 501 | + }); |
439 | 502 | });
|
0 commit comments