1
1
import {
2
- dynamicValue ,
2
+ dynamic ,
3
3
EditableValueBuilder ,
4
4
ListAttributeValueBuilder ,
5
- ListValueBuilder ,
6
5
ReferenceSetValueBuilder ,
7
- listExp
6
+ listExp ,
7
+ obj ,
8
+ ListValueBuilder
8
9
} from "@mendix/widget-plugin-test-utils" ;
9
10
import "./__mocks__/intersectionObserverMock" ;
10
11
import "@testing-library/jest-dom" ;
11
12
import { fireEvent , render , RenderResult , waitFor } from "@testing-library/react" ;
12
- import { ObjectItem , DynamicValue , ListValue } from "mendix" ;
13
+ import { ListValue } from "mendix" ;
13
14
import { createElement } from "react" ;
14
15
import { ComboboxContainerProps , OptionsSourceAssociationCaptionTypeEnum } from "../../typings/ComboboxProps" ;
15
16
import Combobox from "../Combobox" ;
@@ -26,64 +27,56 @@ describe("Combo box (Association)", () => {
26
27
id : "comboBox1" ,
27
28
source : "context" ,
28
29
optionsSourceType : "association" ,
29
- attributeAssociation : new ReferenceSetValueBuilder ( ) . withValue ( [ { id : "111" } ] as ObjectItem [ ] ) . build ( ) ,
30
+ attributeAssociation : new ReferenceSetValueBuilder ( ) . withValue ( [ obj ( "111" ) ] ) . build ( ) ,
30
31
attributeEnumeration : new EditableValueBuilder < string > ( ) . build ( ) ,
31
32
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 ( ) ,
38
36
optionsSourceAssociationCaptionType : "expression" ,
39
37
optionsSourceAssociationCaptionAttribute : new ListAttributeValueBuilder < string > ( ) . build ( ) ,
40
38
optionsSourceAssociationCaptionExpression : listExp ( ( ) => "$currentObject/CountryName" ) ,
41
39
optionsSourceAssociationCustomContentType : "no" ,
42
40
optionsSourceAssociationCustomContent : undefined ,
43
- emptyOptionText : dynamicValue ( "Select an option 111" ) ,
41
+ emptyOptionText : dynamic ( "Select an option 111" ) ,
44
42
ariaRequired : true ,
45
43
clearable : true ,
46
44
filterType : "contains" ,
47
45
selectedItemsStyle : "text" ,
48
46
readOnlyStyle : "bordered" ,
49
47
lazyLoading : false ,
50
48
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" ) ,
54
52
selectAllButton : true , // Causes +1 option to be added to the menu
55
- selectAllButtonCaption : dynamicValue ( "Select All" ) ,
53
+ selectAllButtonCaption : dynamic ( "Select All" ) ,
56
54
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" ) ,
60
58
showFooter : false ,
61
59
databaseAttributeString : new EditableValueBuilder < string | Big > ( ) . build ( ) ,
62
60
optionsSourceDatabaseCaptionType : "attribute" ,
63
- optionsSourceDatabaseDefaultValue : dynamicValue ( "empty value" ) ,
61
+ optionsSourceDatabaseDefaultValue : dynamic ( "empty value" ) ,
64
62
optionsSourceDatabaseCustomContentType : "yes" ,
65
63
staticDataSourceCustomContentType : "no" ,
66
64
staticAttribute : new EditableValueBuilder < string > ( ) . build ( ) ,
67
65
optionsSourceStaticDataSource : [
68
66
{
69
- staticDataSourceValue : dynamicValue ( "value1" ) ,
67
+ staticDataSourceValue : dynamic ( "value1" ) ,
70
68
staticDataSourceCustomContent : undefined ,
71
- staticDataSourceCaption : dynamicValue ( "caption1" )
69
+ staticDataSourceCaption : dynamic ( "caption1" )
72
70
} ,
73
71
{
74
- staticDataSourceValue : dynamicValue ( "value2" ) ,
72
+ staticDataSourceValue : dynamic ( "value2" ) ,
75
73
staticDataSourceCustomContent : undefined ,
76
- staticDataSourceCaption : dynamicValue ( "caption2" )
74
+ staticDataSourceCaption : dynamic ( "caption2" )
77
75
}
78
76
]
79
77
} ;
80
78
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 } ` ) ;
87
80
}
88
81
} ) ;
89
82
@@ -127,10 +120,10 @@ describe("Combo box (Association)", () => {
127
120
waitFor ( ( ) => {
128
121
expect ( component . queryAllByRole ( "option" ) ) . toHaveLength ( 4 ) ;
129
122
} ) ;
130
- const option1 = await component . findByText ( "222 " ) ;
123
+ const option1 = await component . findByText ( "obj_222 " ) ;
131
124
fireEvent . click ( option1 ) ;
132
125
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 " } ] ) ;
134
127
} ) ;
135
128
it ( "removes selected item" , async ( ) => {
136
129
const component = render ( < Combobox { ...defaultProps } /> ) ;
@@ -139,10 +132,10 @@ describe("Combo box (Association)", () => {
139
132
await waitFor ( ( ) => {
140
133
expect ( component . queryAllByRole ( "option" ) ) . toHaveLength ( 4 ) ;
141
134
} ) ;
142
- const option1 = await component . findByText ( "222 " ) ;
135
+ const option1 = await component . findByText ( "obj_222 " ) ;
143
136
fireEvent . click ( option1 ) ;
144
137
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 " } ] ) ;
146
139
147
140
const clearButton = await component . container . getElementsByClassName ( "widget-combobox-clear-button" ) [ 0 ] ;
148
141
fireEvent . click ( clearButton ) ;
0 commit comments