Skip to content

Commit 173d1a6

Browse files
authored
refactor(test-utils): migrate dynamic helpers usage (#2307)
2 parents 4948b71 + b6f8b26 commit 173d1a6

42 files changed

Lines changed: 433 additions & 403 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/pluggableWidgets/barcode-generator-web/src/__tests__/BarcodeGenerator.spec.tsx

Lines changed: 91 additions & 91 deletions
Large diffs are not rendered by default.

packages/pluggableWidgets/calendar-web/src/__tests__/Calendar.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ const customViewProps: CalendarContainerProps = {
7272
view: "custom",
7373
defaultViewStandard: "month",
7474
defaultViewCustom: "work_week",
75-
editable: dynamic(true),
76-
showEventDate: dynamic(true),
75+
editable: dynamic.available(true),
76+
showEventDate: dynamic.available(true),
7777
widthUnit: "percentage",
7878
width: 100,
7979
heightUnit: "pixels",

packages/pluggableWidgets/checkbox-radio-selection-web/src/CheckboxRadioSelection.editorPreview.tsx

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
import { generateUUID } from "@mendix/widget-plugin-platform/framework/generate-uuid";
1+
import type { DynamicValue } from "mendix";
22
import { ReactElement, useMemo } from "react";
3+
import { generateUUID } from "@mendix/widget-plugin-platform/framework/generate-uuid";
34
import { CheckboxRadioSelectionPreviewProps } from "../typings/CheckboxRadioSelectionProps";
5+
import { CheckboxSelection } from "./components/CheckboxSelection/CheckboxSelection";
46
import { RadioSelection } from "./components/RadioSelection/RadioSelection";
5-
import { dynamic } from "@mendix/widget-plugin-test-utils";
6-
import { MultiSelector, SelectionBaseProps, SingleSelector } from "./helpers/types";
7-
import { StaticPreviewSelector } from "./helpers/Static/Preview/StaticPreviewSelector";
7+
import { AssociationPreviewSelector } from "./helpers/Association/Preview/AssociationPreviewSelector";
88
import {
99
DatabaseMultiPreviewSelector,
1010
DatabasePreviewSelector
1111
} from "./helpers/Database/Preview/DatabasePreviewSelector";
12-
import { AssociationPreviewSelector } from "./helpers/Association/Preview/AssociationPreviewSelector";
12+
import { StaticPreviewSelector } from "./helpers/Static/Preview/StaticPreviewSelector";
13+
import { MultiSelector, SelectionBaseProps, SingleSelector } from "./helpers/types";
1314
import "./ui/CheckboxRadioSelection.scss";
1415
import "./ui/CheckboxRadioSelectionPreview.scss";
15-
import { CheckboxSelection } from "./components/CheckboxSelection/CheckboxSelection";
16+
17+
const available = <T,>(value: T): DynamicValue<T> =>
18+
({
19+
status: "available",
20+
value
21+
}) as DynamicValue<T>;
1622

1723
export const preview = (props: CheckboxRadioSelectionPreviewProps): ReactElement => {
1824
const id = generateUUID().toString();
@@ -21,9 +27,9 @@ export const preview = (props: CheckboxRadioSelectionPreviewProps): ReactElement
2127
inputId: id,
2228
labelId: `${id}-label`,
2329
readOnlyStyle: props.readOnlyStyle,
24-
ariaRequired: dynamic(false),
25-
ariaLabel: dynamic(""),
26-
groupName: dynamic(`${id}-group`),
30+
ariaRequired: available(false),
31+
ariaLabel: available(""),
32+
groupName: available(`${id}-group`),
2733
noOptionsText: "No options available"
2834
};
2935

packages/pluggableWidgets/combobox-web/AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ Uses `@mendix/widget-plugin-test-utils` builders:
297297
- `ReferenceValueBuilder` — mocks ReferenceValue (single association)
298298
- `ReferenceSetValueBuilder` — mocks ReferenceSetValue (multi association)
299299
- `ListValueBuilder` — mocks ListValue datasource with `.withItems()`, `.withHasMore()`
300-
- `dynamic(value?)` — wraps in DynamicValue
300+
- `dynamic.[available|loading|unavailable](value?)` — wraps in DynamicValue
301301
- `obj(id?)` — creates mock ObjectItem
302302
- `list(items)` — creates mock ListValue
303303
- `setupIntersectionObserverStub()` — stubs browser IntersectionObserver

packages/pluggableWidgets/combobox-web/src/Combobox.editorPreview.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
import { generateUUID } from "@mendix/widget-plugin-platform/framework/generate-uuid";
1+
import type { DynamicValue } from "mendix";
22
import { ReactElement, useMemo } from "react";
3+
import { generateUUID } from "@mendix/widget-plugin-platform/framework/generate-uuid";
34
import { ComboboxPreviewProps } from "../typings/ComboboxProps";
45
import { SingleSelection } from "./components/SingleSelection/SingleSelection";
5-
import { dynamic } from "@mendix/widget-plugin-test-utils";
6-
import { SelectionBaseProps, SingleSelector } from "./helpers/types";
76
import "./ui/Combobox.scss";
87
import { AssociationPreviewSelector } from "./helpers/Association/Preview/AssociationPreviewSelector";
9-
import { StaticPreviewSelector } from "./helpers/Static/Preview/StaticPreviewSelector";
108
import { DatabasePreviewSelector } from "./helpers/Database/Preview/DatabasePreviewSelector";
9+
import { StaticPreviewSelector } from "./helpers/Static/Preview/StaticPreviewSelector";
10+
import { SelectionBaseProps, SingleSelector } from "./helpers/types";
11+
12+
const available = <T,>(value: T): DynamicValue<T> =>
13+
({
14+
status: "available",
15+
value
16+
}) as DynamicValue<T>;
1117

1218
export const preview = (props: ComboboxPreviewProps): ReactElement => {
1319
const id = generateUUID().toString();
@@ -16,7 +22,7 @@ export const preview = (props: ComboboxPreviewProps): ReactElement => {
1622
inputId: id,
1723
labelId: `${id}-label`,
1824
readOnlyStyle: props.readOnlyStyle,
19-
ariaRequired: dynamic(false),
25+
ariaRequired: available(false),
2026
a11yConfig: {
2127
ariaLabels: {
2228
clearSelection: props.clearButtonAriaLabel,

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,23 @@ describe("Combo box (Association)", () => {
4040
optionsSourceAssociationCaptionExpression: listExpression(() => "$currentObject/CountryName"),
4141
optionsSourceAssociationCustomContentType: "no",
4242
optionsSourceAssociationCustomContent: undefined,
43-
emptyOptionText: dynamic("Select an option 111"),
44-
ariaRequired: dynamic(true),
43+
emptyOptionText: dynamic.available("Select an option 111"),
44+
ariaRequired: dynamic.available(true),
4545
clearable: true,
4646
filterType: "contains",
4747
selectedItemsStyle: "text",
4848
readOnlyStyle: "bordered",
4949
lazyLoading: false,
5050
loadingType: "spinner",
51-
noOptionsText: dynamic("no options found"),
52-
clearButtonAriaLabel: dynamic("Clear selection"),
53-
removeValueAriaLabel: dynamic("Remove value"),
51+
noOptionsText: dynamic.available("no options found"),
52+
clearButtonAriaLabel: dynamic.available("Clear selection"),
53+
removeValueAriaLabel: dynamic.available("Remove value"),
5454
selectAllButton: true, // Causes +1 option to be added to the menu
55-
selectAllButtonCaption: dynamic("Select All"),
55+
selectAllButtonCaption: dynamic.available("Select All"),
5656
selectionMethod: "checkbox",
57-
a11ySelectedValue: dynamic("Selected value:"),
58-
a11yOptionsAvailable: dynamic("Options available:"),
59-
a11yInstructions: dynamic("a11yInstructions"),
57+
a11ySelectedValue: dynamic.available("Selected value:"),
58+
a11yOptionsAvailable: dynamic.available("Options available:"),
59+
a11yInstructions: dynamic.available("a11yInstructions"),
6060
showFooter: false,
6161
databaseAttributeString: new EditableValueBuilder<string | Big>().build(),
6262
optionsSourceDatabaseCaptionType: "attribute",
@@ -65,23 +65,23 @@ describe("Combo box (Association)", () => {
6565
staticAttribute: new EditableValueBuilder<string>().build(),
6666
optionsSourceStaticDataSource: [
6767
{
68-
staticDataSourceValue: dynamic("value1"),
68+
staticDataSourceValue: dynamic.available("value1"),
6969
staticDataSourceCustomContent: undefined,
70-
staticDataSourceCaption: dynamic("caption1")
70+
staticDataSourceCaption: dynamic.available("caption1")
7171
},
7272
{
73-
staticDataSourceValue: dynamic("value2"),
73+
staticDataSourceValue: dynamic.available("value2"),
7474
staticDataSourceCustomContent: undefined,
75-
staticDataSourceCaption: dynamic("caption2")
75+
staticDataSourceCaption: dynamic.available("caption2")
7676
}
7777
],
7878
selectedItemsSorting: "none",
7979
customEditability: "default",
80-
customEditabilityExpression: dynamic(false),
80+
customEditabilityExpression: dynamic.available(false),
8181
filterInputDebounceInterval: 200
8282
};
8383
if (defaultProps.optionsSourceAssociationCaptionType === "expression") {
84-
defaultProps.optionsSourceAssociationCaptionExpression!.get = i => dynamic(`${i.id}`);
84+
defaultProps.optionsSourceAssociationCaptionExpression!.get = i => dynamic.available(`${i.id}`);
8585
}
8686
});
8787

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,22 @@ describe("Combo box (Association)", () => {
5050
optionsSourceAssociationCaptionExpression: listExpression(() => "$currentObject/CountryName"),
5151
optionsSourceAssociationCustomContentType: "no",
5252
optionsSourceAssociationCustomContent: undefined,
53-
emptyOptionText: dynamic("Select an option 111"),
54-
ariaRequired: dynamic(true),
53+
emptyOptionText: dynamic.available("Select an option 111"),
54+
ariaRequired: dynamic.available(true),
5555
clearable: true,
5656
filterType: "contains",
5757
selectedItemsStyle: "text",
5858
readOnlyStyle: "bordered",
5959
lazyLoading: false,
6060
loadingType: "spinner",
61-
clearButtonAriaLabel: dynamic("Clear selection"),
62-
removeValueAriaLabel: dynamic("Remove value"),
63-
selectAllButtonCaption: dynamic("Select All"),
61+
clearButtonAriaLabel: dynamic.available("Clear selection"),
62+
removeValueAriaLabel: dynamic.available("Remove value"),
63+
selectAllButtonCaption: dynamic.available("Select All"),
6464
selectAllButton: false,
6565
selectionMethod: "checkbox",
66-
a11ySelectedValue: dynamic("Selected value:"),
67-
a11yOptionsAvailable: dynamic("Options available:"),
68-
a11yInstructions: dynamic("a11yInstructions"),
66+
a11ySelectedValue: dynamic.available("Selected value:"),
67+
a11yOptionsAvailable: dynamic.available("Options available:"),
68+
a11yInstructions: dynamic.available("a11yInstructions"),
6969
showFooter: false,
7070
databaseAttributeString: new EditableValueBuilder<string | Big>().build(),
7171
optionsSourceDatabaseCaptionType: "attribute",
@@ -74,23 +74,23 @@ describe("Combo box (Association)", () => {
7474
staticAttribute: new EditableValueBuilder<string>().build(),
7575
optionsSourceStaticDataSource: [
7676
{
77-
staticDataSourceValue: dynamic("value1"),
77+
staticDataSourceValue: dynamic.available("value1"),
7878
staticDataSourceCustomContent: undefined,
79-
staticDataSourceCaption: dynamic("caption1")
79+
staticDataSourceCaption: dynamic.available("caption1")
8080
},
8181
{
82-
staticDataSourceValue: dynamic("value2"),
82+
staticDataSourceValue: dynamic.available("value2"),
8383
staticDataSourceCustomContent: undefined,
84-
staticDataSourceCaption: dynamic("caption2")
84+
staticDataSourceCaption: dynamic.available("caption2")
8585
}
8686
],
8787
selectedItemsSorting: "none",
8888
customEditability: "default",
89-
customEditabilityExpression: dynamic(false),
89+
customEditabilityExpression: dynamic.available(false),
9090
filterInputDebounceInterval: 200
9191
};
9292
if (defaultProps.optionsSourceAssociationCaptionType === "expression") {
93-
defaultProps.optionsSourceAssociationCaptionExpression!.get = i => dynamic(`${i.id}`);
93+
defaultProps.optionsSourceAssociationCaptionExpression!.get = i => dynamic.available(`${i.id}`);
9494
}
9595
});
9696
it("renders combobox widget", () => {

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,22 @@ describe("Combo box (Static values)", () => {
5050
optionsSourceAssociationCaptionExpression: listExpression(() => "$currentObject/CountryName"),
5151
optionsSourceAssociationCustomContentType: "no",
5252
optionsSourceAssociationCustomContent: undefined,
53-
emptyOptionText: dynamic("Select an option 111"),
54-
ariaRequired: dynamic(true),
53+
emptyOptionText: dynamic.available("Select an option 111"),
54+
ariaRequired: dynamic.available(true),
5555
clearable: true,
5656
filterType: "contains",
5757
selectedItemsStyle: "text",
5858
readOnlyStyle: "bordered",
5959
lazyLoading: false,
6060
loadingType: "spinner",
61-
clearButtonAriaLabel: dynamic("Clear selection"),
62-
removeValueAriaLabel: dynamic("Remove value"),
63-
selectAllButtonCaption: dynamic("Select All"),
61+
clearButtonAriaLabel: dynamic.available("Clear selection"),
62+
removeValueAriaLabel: dynamic.available("Remove value"),
63+
selectAllButtonCaption: dynamic.available("Select All"),
6464
selectAllButton: false,
6565
selectionMethod: "checkbox",
66-
a11ySelectedValue: dynamic("Selected value:"),
67-
a11yOptionsAvailable: dynamic("Options available:"),
68-
a11yInstructions: dynamic("a11yInstructions"),
66+
a11ySelectedValue: dynamic.available("Selected value:"),
67+
a11yOptionsAvailable: dynamic.available("Options available:"),
68+
a11yInstructions: dynamic.available("a11yInstructions"),
6969
showFooter: false,
7070
databaseAttributeString: new EditableValueBuilder<string | Big>().build(),
7171
optionsSourceDatabaseCaptionType: "attribute",
@@ -74,23 +74,23 @@ describe("Combo box (Static values)", () => {
7474
staticAttribute: new EditableValueBuilder<string>().withValue("value1").build(),
7575
optionsSourceStaticDataSource: [
7676
{
77-
staticDataSourceValue: dynamic("value1"),
77+
staticDataSourceValue: dynamic.available("value1"),
7878
staticDataSourceCustomContent: undefined,
79-
staticDataSourceCaption: dynamic("caption1")
79+
staticDataSourceCaption: dynamic.available("caption1")
8080
},
8181
{
82-
staticDataSourceValue: dynamic("value2"),
82+
staticDataSourceValue: dynamic.available("value2"),
8383
staticDataSourceCustomContent: undefined,
84-
staticDataSourceCaption: dynamic("caption2")
84+
staticDataSourceCaption: dynamic.available("caption2")
8585
}
8686
],
8787
selectedItemsSorting: "none",
8888
customEditability: "default",
89-
customEditabilityExpression: dynamic(false),
89+
customEditabilityExpression: dynamic.available(false),
9090
filterInputDebounceInterval: 200
9191
};
9292
if (defaultProps.optionsSourceAssociationCaptionType === "expression") {
93-
defaultProps.optionsSourceAssociationCaptionExpression!.get = i => dynamic(`${i.id}`);
93+
defaultProps.optionsSourceAssociationCaptionExpression!.get = i => dynamic.available(`${i.id}`);
9494
}
9595
});
9696
it("renders combobox widget", () => {

packages/pluggableWidgets/combobox-web/src/helpers/Database/__tests__/DatabaseSingleSelectionSelector.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function buildProps({ items, values, targetValue, selection }: PropsOverrides):
4040
optionsSourceDatabaseCaptionAttribute: captionAttr,
4141
optionsSourceDatabaseValueAttribute: valueAttr,
4242
databaseAttributeString: targetAttr as any,
43-
emptyOptionText: dynamic("Select..."),
43+
emptyOptionText: dynamic.available("Select..."),
4444
optionsSourceDatabaseCustomContentType: "no",
4545
optionsSourceAssociationCustomContentType: "no",
4646
staticDataSourceCustomContentType: "no",
@@ -50,14 +50,14 @@ function buildProps({ items, values, targetValue, selection }: PropsOverrides):
5050
lazyLoading: false,
5151
loadingType: "spinner",
5252
customEditability: "default",
53-
customEditabilityExpression: dynamic(false),
53+
customEditabilityExpression: dynamic.available(false),
5454
filterInputDebounceInterval: 200,
5555
selectedItemsStyle: "text",
5656
readOnlyStyle: "bordered",
5757
selectionMethod: "checkbox",
5858
selectAllButton: false,
59-
selectAllButtonCaption: dynamic("Select All"),
60-
ariaRequired: dynamic(true),
59+
selectAllButtonCaption: dynamic.available("Select All"),
60+
ariaRequired: dynamic.available(true),
6161
showFooter: false,
6262
selectedItemsSorting: "none",
6363
attributeEnumeration: new EditableValueBuilder<string>().build(),

0 commit comments

Comments
 (0)