Skip to content

Commit 70b1903

Browse files
committed
feat: migrate on new test utils
1 parent c7cf57f commit 70b1903

File tree

16 files changed

+152
-204
lines changed

16 files changed

+152
-204
lines changed

packages/pluggableWidgets/area-chart-web/src/__tests__/AreaChart.spec.tsx

+11-15
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import { ChartWidget } from "@mendix/shared-charts/common";
2-
import {
3-
dynamicValue,
4-
EditableValueBuilder,
5-
ListAttributeValueBuilder,
6-
ListValueBuilder
7-
} from "@mendix/widget-plugin-test-utils";
2+
import { list, listExp, EditableValueBuilder, ListAttributeValueBuilder } from "@mendix/widget-plugin-test-utils";
83
import Big from "big.js";
94
import { mount, ReactWrapper } from "enzyme";
10-
import { ListExpressionValue } from "mendix";
115
import { createElement } from "react";
126
import { SeriesType } from "../../typings/AreaChartProps";
137
import { AreaChart } from "../AreaChart";
@@ -61,23 +55,29 @@ describe("The AreaChart widget", () => {
6155
});
6256

6357
it("sets the line color on the data series based on the lineColor value", () => {
64-
const areaChart = renderAreaChart([{ staticLineColor: exp("red") }, { staticLineColor: undefined }]);
58+
const areaChart = renderAreaChart([{ staticLineColor: listExp(() => "red") }, { staticLineColor: undefined }]);
6559
const data = areaChart.find(ChartWidget).prop("data");
6660
expect(data).toHaveLength(2);
6761
expect(data[0]).toHaveProperty("line.color", "red");
6862
expect(data[1]).toHaveProperty("line.color", undefined);
6963
});
7064

7165
it("sets the marker color on the data series based on the markerColor value", () => {
72-
const areaChart = renderAreaChart([{ staticMarkerColor: undefined }, { staticMarkerColor: exp("blue") }]);
66+
const areaChart = renderAreaChart([
67+
{ staticMarkerColor: undefined },
68+
{ staticMarkerColor: listExp(() => "blue") }
69+
]);
7370
const data = areaChart.find(ChartWidget).prop("data");
7471
expect(data).toHaveLength(2);
7572
expect(data[0]).toHaveProperty("marker.color", undefined);
7673
expect(data[1]).toHaveProperty("marker.color", "blue");
7774
});
7875

7976
it("sets the area color on the data series based on the fillcolor value", () => {
80-
const areaChart = renderAreaChart([{ staticFillColor: undefined }, { staticFillColor: exp("#393393") }]);
77+
const areaChart = renderAreaChart([
78+
{ staticFillColor: undefined },
79+
{ staticFillColor: listExp(() => "#393393") }
80+
]);
8181
const data = areaChart.find(ChartWidget).prop("data");
8282
expect(data).toHaveLength(2);
8383
expect(data[0]).toHaveProperty("fillcolor", undefined);
@@ -127,12 +127,8 @@ function setupBasicSeries(overwriteConfig: Partial<SeriesType>): SeriesType {
127127
staticLineColor: overwriteConfig.staticLineColor ?? undefined,
128128
staticMarkerColor: overwriteConfig.staticMarkerColor ?? undefined,
129129
staticFillColor: overwriteConfig.staticFillColor ?? undefined,
130-
staticDataSource: ListValueBuilder().simple(),
130+
staticDataSource: list(2),
131131
staticXAttribute: xAttribute,
132132
staticYAttribute: yAttribute
133133
};
134134
}
135-
136-
function exp(value: string): ListExpressionValue<string> {
137-
return { get: () => dynamicValue(value) } as unknown as ListExpressionValue<string>;
138-
}

packages/pluggableWidgets/bar-chart-web/src/__tests__/BarChart.spec.tsx

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import { ChartWidget } from "@mendix/shared-charts/common";
2-
import {
3-
dynamicValue,
4-
EditableValueBuilder,
5-
ListAttributeValueBuilder,
6-
ListValueBuilder
7-
} from "@mendix/widget-plugin-test-utils";
2+
import { EditableValueBuilder, ListAttributeValueBuilder, listExp, list } from "@mendix/widget-plugin-test-utils";
83
import Big from "big.js";
94
import { mount, ReactWrapper } from "enzyme";
10-
import { ListExpressionValue } from "mendix";
115
import { createElement } from "react";
126
import { SeriesType } from "../../typings/BarChartProps";
137
import { BarChart } from "../BarChart";
@@ -45,7 +39,7 @@ describe("The BarChart widget", () => {
4539
});
4640

4741
it("sets the bar color on the data series based on the barColor value", () => {
48-
const barChart = renderBarChart([{ staticBarColor: exp("red") }, { staticBarColor: undefined }]);
42+
const barChart = renderBarChart([{ staticBarColor: listExp(() => "red") }, { staticBarColor: undefined }]);
4943
const data = barChart.find(ChartWidget).prop("data");
5044
expect(data).toHaveLength(2);
5145
expect(data[0]).toHaveProperty("marker.color", "red");
@@ -91,12 +85,8 @@ function setupBasicSeries(overwriteConfig: Partial<SeriesType>): SeriesType {
9185
customSeriesOptions: overwriteConfig.customSeriesOptions ?? "",
9286
aggregationType: overwriteConfig.aggregationType ?? "avg",
9387
staticBarColor: overwriteConfig.staticBarColor ?? undefined,
94-
staticDataSource: ListValueBuilder().simple(),
88+
staticDataSource: list(2),
9589
staticXAttribute: xAttribute,
9690
staticYAttribute: yAttribute
9791
};
9892
}
99-
100-
function exp(value: string): ListExpressionValue<string> {
101-
return { get: () => dynamicValue(value) } as unknown as ListExpressionValue<string>;
102-
}

packages/pluggableWidgets/bubble-chart-web/src/__tests__/BubbleChart.spec.tsx

+6-13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import { ChartWidget } from "@mendix/shared-charts/common";
2-
import {
3-
EditableValueBuilder,
4-
ListAttributeValueBuilder,
5-
ListValueBuilder,
6-
dynamicValue
7-
} from "@mendix/widget-plugin-test-utils";
2+
import { EditableValueBuilder, ListAttributeValueBuilder, list, listExp } from "@mendix/widget-plugin-test-utils";
83
import Big from "big.js";
94
import { ReactWrapper, mount } from "enzyme";
10-
import { ListExpressionValue } from "mendix";
115
import { createElement } from "react";
126
import { LinesType } from "../../typings/BubbleChartProps";
137
import { BubbleChart } from "../BubbleChart";
@@ -45,7 +39,10 @@ describe("The Bubble widget", () => {
4539
});
4640

4741
it("sets the marker color on the data series based on the markerColor value", () => {
48-
const bubbleChart = renderBubbleChart([{ staticMarkerColor: exp("red") }, { staticMarkerColor: undefined }]);
42+
const bubbleChart = renderBubbleChart([
43+
{ staticMarkerColor: listExp(() => "red") },
44+
{ staticMarkerColor: undefined }
45+
]);
4946
const data = bubbleChart.find(ChartWidget).prop("data");
5047
expect(data).toHaveLength(2);
5148
expect(data[0]).toHaveProperty("marker.color", "red");
@@ -91,14 +88,10 @@ function setupBasicSeries(overwriteConfig: Partial<LinesType>): LinesType {
9188
customSeriesOptions: overwriteConfig.customSeriesOptions ?? "",
9289
aggregationType: overwriteConfig.aggregationType ?? "avg",
9390
staticMarkerColor: overwriteConfig.staticMarkerColor ?? undefined,
94-
staticDataSource: ListValueBuilder().simple(),
91+
staticDataSource: list(2),
9592
staticXAttribute: xAttribute,
9693
staticYAttribute: yAttribute,
9794
autosize: true,
9895
sizeref: 10
9996
};
10097
}
101-
102-
function exp(value: string): ListExpressionValue<string> {
103-
return { get: () => dynamicValue(value) } as unknown as ListExpressionValue<string>;
104-
}

packages/pluggableWidgets/column-chart-web/src/__tests__/ColumnChart.spec.tsx

+6-13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import { ChartWidget } from "@mendix/shared-charts/common";
2-
import {
3-
dynamicValue,
4-
EditableValueBuilder,
5-
ListAttributeValueBuilder,
6-
ListValueBuilder
7-
} from "@mendix/widget-plugin-test-utils";
2+
import { EditableValueBuilder, ListAttributeValueBuilder, list, listExp } from "@mendix/widget-plugin-test-utils";
83
import Big from "big.js";
94
import { mount, ReactWrapper } from "enzyme";
10-
import { ListExpressionValue } from "mendix";
115
import { createElement } from "react";
126
import { ColumnChartContainerProps, SeriesType } from "../../typings/ColumnChartProps";
137
import { ColumnChart } from "../ColumnChart";
@@ -49,7 +43,10 @@ describe("The ColumnChart widget", () => {
4943
});
5044

5145
it("sets the bar color on the data series based on the barColor value", () => {
52-
const columnChart = renderColumnChart([{ staticBarColor: exp("red") }, { staticBarColor: undefined }]);
46+
const columnChart = renderColumnChart([
47+
{ staticBarColor: listExp(() => "red") },
48+
{ staticBarColor: undefined }
49+
]);
5350
const data = columnChart.find(ChartWidget).prop("data");
5451
expect(data).toHaveLength(2);
5552
expect(data[0]).toHaveProperty("marker.color", "red");
@@ -101,12 +98,8 @@ function setupBasicSeries(overwriteConfig: Partial<SeriesType>): SeriesType {
10198
customSeriesOptions: overwriteConfig.customSeriesOptions ?? "",
10299
aggregationType: overwriteConfig.aggregationType ?? "avg",
103100
staticBarColor: overwriteConfig.staticBarColor ?? undefined,
104-
staticDataSource: ListValueBuilder().simple(),
101+
staticDataSource: list(2),
105102
staticXAttribute: xAttribute,
106103
staticYAttribute: yAttribute
107104
};
108105
}
109-
110-
function exp(value: string): ListExpressionValue<string> {
111-
return { get: () => dynamicValue(value) } as unknown as ListExpressionValue<string>;
112-
}

packages/pluggableWidgets/combobox-web/src/__tests__/MultiSelection.spec.tsx

+27-34
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import {
2-
dynamicValue,
2+
dynamic,
33
EditableValueBuilder,
44
ListAttributeValueBuilder,
5-
ListValueBuilder,
65
ReferenceSetValueBuilder,
7-
listExp
6+
listExp,
7+
obj,
8+
ListValueBuilder
89
} from "@mendix/widget-plugin-test-utils";
910
import "./__mocks__/intersectionObserverMock";
1011
import "@testing-library/jest-dom";
1112
import { fireEvent, render, RenderResult, waitFor } from "@testing-library/react";
12-
import { ObjectItem, DynamicValue, ListValue } from "mendix";
13+
import { ListValue } from "mendix";
1314
import { createElement } from "react";
1415
import { ComboboxContainerProps, OptionsSourceAssociationCaptionTypeEnum } from "../../typings/ComboboxProps";
1516
import Combobox from "../Combobox";
@@ -26,64 +27,56 @@ describe("Combo box (Association)", () => {
2627
id: "comboBox1",
2728
source: "context",
2829
optionsSourceType: "association",
29-
attributeAssociation: new ReferenceSetValueBuilder().withValue([{ id: "111" }] as ObjectItem[]).build(),
30+
attributeAssociation: new ReferenceSetValueBuilder().withValue([obj("111")]).build(),
3031
attributeEnumeration: new EditableValueBuilder<string>().build(),
3132
attributeBoolean: new EditableValueBuilder<boolean>().build(),
32-
optionsSourceAssociationDataSource: ListValueBuilder().withItems([
33-
{ id: "111" },
34-
{ id: "222" },
35-
{ id: "333" },
36-
{ id: "444" }
37-
] as ObjectItem[]),
33+
optionsSourceAssociationDataSource: new ListValueBuilder()
34+
.withItems([obj("111"), obj("222"), obj("333"), obj("444")])
35+
.build(),
3836
optionsSourceAssociationCaptionType: "expression",
3937
optionsSourceAssociationCaptionAttribute: new ListAttributeValueBuilder<string>().build(),
4038
optionsSourceAssociationCaptionExpression: listExp(() => "$currentObject/CountryName"),
4139
optionsSourceAssociationCustomContentType: "no",
4240
optionsSourceAssociationCustomContent: undefined,
43-
emptyOptionText: dynamicValue("Select an option 111"),
41+
emptyOptionText: dynamic("Select an option 111"),
4442
ariaRequired: true,
4543
clearable: true,
4644
filterType: "contains",
4745
selectedItemsStyle: "text",
4846
readOnlyStyle: "bordered",
4947
lazyLoading: false,
5048
loadingType: "spinner",
51-
noOptionsText: dynamicValue("no options found"),
52-
clearButtonAriaLabel: dynamicValue("Clear selection"),
53-
removeValueAriaLabel: dynamicValue("Remove value"),
49+
noOptionsText: dynamic("no options found"),
50+
clearButtonAriaLabel: dynamic("Clear selection"),
51+
removeValueAriaLabel: dynamic("Remove value"),
5452
selectAllButton: true, // Causes +1 option to be added to the menu
55-
selectAllButtonCaption: dynamicValue("Select All"),
53+
selectAllButtonCaption: dynamic("Select All"),
5654
selectionMethod: "checkbox",
57-
a11ySelectedValue: dynamicValue("Selected value:"),
58-
a11yOptionsAvailable: dynamicValue("Options available:"),
59-
a11yInstructions: dynamicValue("a11yInstructions"),
55+
a11ySelectedValue: dynamic("Selected value:"),
56+
a11yOptionsAvailable: dynamic("Options available:"),
57+
a11yInstructions: dynamic("a11yInstructions"),
6058
showFooter: false,
6159
databaseAttributeString: new EditableValueBuilder<string | Big>().build(),
6260
optionsSourceDatabaseCaptionType: "attribute",
63-
optionsSourceDatabaseDefaultValue: dynamicValue("empty value"),
61+
optionsSourceDatabaseDefaultValue: dynamic("empty value"),
6462
optionsSourceDatabaseCustomContentType: "yes",
6563
staticDataSourceCustomContentType: "no",
6664
staticAttribute: new EditableValueBuilder<string>().build(),
6765
optionsSourceStaticDataSource: [
6866
{
69-
staticDataSourceValue: dynamicValue("value1"),
67+
staticDataSourceValue: dynamic("value1"),
7068
staticDataSourceCustomContent: undefined,
71-
staticDataSourceCaption: dynamicValue("caption1")
69+
staticDataSourceCaption: dynamic("caption1")
7270
},
7371
{
74-
staticDataSourceValue: dynamicValue("value2"),
72+
staticDataSourceValue: dynamic("value2"),
7573
staticDataSourceCustomContent: undefined,
76-
staticDataSourceCaption: dynamicValue("caption2")
74+
staticDataSourceCaption: dynamic("caption2")
7775
}
7876
]
7977
};
8078
if (defaultProps.optionsSourceAssociationCaptionType === "expression") {
81-
defaultProps.optionsSourceAssociationCaptionExpression!.get = i => {
82-
return {
83-
value: `${i.id}`,
84-
status: "available"
85-
} as DynamicValue<string>;
86-
};
79+
defaultProps.optionsSourceAssociationCaptionExpression!.get = i => dynamic(`${i.id}`);
8780
}
8881
});
8982

@@ -127,10 +120,10 @@ describe("Combo box (Association)", () => {
127120
waitFor(() => {
128121
expect(component.queryAllByRole("option")).toHaveLength(4);
129122
});
130-
const option1 = await component.findByText("222");
123+
const option1 = await component.findByText("obj_222");
131124
fireEvent.click(option1);
132125
expect(defaultProps.attributeAssociation?.setValue).toHaveBeenCalled();
133-
expect(defaultProps.attributeAssociation?.value).toEqual([{ id: "111" }, { id: "222" }]);
126+
expect(defaultProps.attributeAssociation?.value).toEqual([{ id: "obj_111" }, { id: "obj_222" }]);
134127
});
135128
it("removes selected item", async () => {
136129
const component = render(<Combobox {...defaultProps} />);
@@ -139,10 +132,10 @@ describe("Combo box (Association)", () => {
139132
await waitFor(() => {
140133
expect(component.queryAllByRole("option")).toHaveLength(4);
141134
});
142-
const option1 = await component.findByText("222");
135+
const option1 = await component.findByText("obj_222");
143136
fireEvent.click(option1);
144137
expect(defaultProps.attributeAssociation?.setValue).toHaveBeenCalled();
145-
expect(defaultProps.attributeAssociation?.value).toEqual([{ id: "111" }, { id: "222" }]);
138+
expect(defaultProps.attributeAssociation?.value).toEqual([{ id: "obj_111" }, { id: "obj_222" }]);
146139

147140
const clearButton = await component.container.getElementsByClassName("widget-combobox-clear-button")[0];
148141
fireEvent.click(clearButton);

0 commit comments

Comments
 (0)