@@ -40,20 +40,30 @@ export default class ButtonDropdownWrapper extends ComponentWrapper {
40
40
* Finds an item in the open dropdown by item id. Returns null if there is no open dropdown.
41
41
*
42
42
* This utility does not open the dropdown. To find dropdown items, call `openDropdown()` first.
43
+ *
44
+ * @param options
45
+ * * expandToViewport (boolean) - Use this when the component under test is rendered with an `expandToViewport` flag.
43
46
*/
44
- findItemById ( id : string ) : ElementWrapper | null {
47
+ findItemById ( id : string , options = { expandToViewport : false } ) : ElementWrapper | null {
45
48
const itemSelector = `.${ itemStyles [ 'item-element' ] } [data-testid="${ id } "]` ;
46
- return this . findOpenDropdown ( ) ?. find ( itemSelector ) || this . find ( itemSelector ) ;
49
+ return options . expandToViewport
50
+ ? createWrapper ( ) . find ( itemSelector )
51
+ : this . findOpenDropdown ( ) ?. find ( itemSelector ) || this . find ( itemSelector ) ;
47
52
}
48
53
49
54
/**
50
55
* Finds `checked` value of item in the open dropdown by item id. Returns null if there is no open dropdown or the item is not a checkbox item.
51
56
*
52
57
* This utility does not open the dropdown. To find dropdown items, call `openDropdown()` first.
58
+ *
59
+ * @param options
60
+ * * expandToViewport (boolean) - Use this when the component under test is rendered with an `expandToViewport` flag.
53
61
*/
54
- @usesDom findItemCheckedById ( id : string ) : string | null {
62
+ @usesDom findItemCheckedById ( id : string , options = { expandToViewport : false } ) : string | null {
55
63
const itemSelector = `.${ itemStyles [ 'item-element' ] } [data-testid="${ id } "]` ;
56
- const item = this . findOpenDropdown ( ) ?. find ( itemSelector ) || this . find ( itemSelector ) ;
64
+ const item = options . expandToViewport
65
+ ? createWrapper ( ) . find ( itemSelector )
66
+ : this . findOpenDropdown ( ) ?. find ( itemSelector ) || this . find ( itemSelector ) ;
57
67
if ( ! item ) {
58
68
return null ;
59
69
}
@@ -68,36 +78,56 @@ export default class ButtonDropdownWrapper extends ComponentWrapper {
68
78
* Finds an expandable category in the open dropdown by category id. Returns null if there is no open dropdown.
69
79
*
70
80
* This utility does not open the dropdown. To find dropdown items, call `openDropdown()` first.
81
+ *
82
+ * @param options
83
+ * * expandToViewport (boolean) - Use this when the component under test is rendered with an `expandToViewport` flag.
71
84
*/
72
- findExpandableCategoryById ( id : string ) : ElementWrapper | null {
85
+ findExpandableCategoryById ( id : string , options = { expandToViewport : false } ) : ElementWrapper | null {
73
86
const expandableCategorySelector = `.${ categoryStyles . expandable } [data-testid="${ id } "]` ;
74
- return this . findOpenDropdown ( ) ?. find ( expandableCategorySelector ) || this . find ( expandableCategorySelector ) ;
87
+ return options . expandToViewport
88
+ ? createWrapper ( ) . find ( expandableCategorySelector )
89
+ : this . findOpenDropdown ( ) ?. find ( expandableCategorySelector ) || this . find ( expandableCategorySelector ) ;
75
90
}
76
91
77
92
/**
78
93
* Finds the highlighted item in the open dropdown. Returns null if there is no open dropdown.
79
94
*
80
95
* This utility does not open the dropdown. To find dropdown items, call `openDropdown()` first.
96
+ *
97
+ * @param options
98
+ * * expandToViewport (boolean) - Use this when the component under test is rendered with an `expandToViewport` flag.
81
99
*/
82
- findHighlightedItem ( ) : ElementWrapper | null {
100
+ findHighlightedItem ( options = { expandToViewport : false } ) : ElementWrapper | null {
83
101
const highlightedItemSelector = `.${ itemStyles [ 'item-element' ] } .${ itemStyles . highlighted } ` ;
84
- return this . findOpenDropdown ( ) ?. find ( highlightedItemSelector ) || this . find ( highlightedItemSelector ) ;
102
+ return options . expandToViewport
103
+ ? createWrapper ( ) . find ( highlightedItemSelector )
104
+ : this . findOpenDropdown ( ) ?. find ( highlightedItemSelector ) || this . find ( highlightedItemSelector ) ;
85
105
}
86
106
87
107
/**
88
108
* Finds all the items in the open dropdown. Returns empty array if there is no open dropdown.
89
109
*
90
110
* This utility does not open the dropdown. To find dropdown items, call `openDropdown()` first.
111
+ *
112
+ * @param options
113
+ * * expandToViewport (boolean) - Use this when the component under test is rendered with an `expandToViewport` flag.
91
114
*/
92
- findItems ( ) : Array < ElementWrapper > {
93
- return this . findOpenDropdown ( ) ?. findAll ( `.${ itemStyles [ 'item-element' ] } ` ) || [ ] ;
115
+ findItems ( options = { expandToViewport : false } ) : Array < ElementWrapper > {
116
+ return options . expandToViewport
117
+ ? createWrapper ( ) . findAll ( `.${ itemStyles [ 'item-element' ] } ` )
118
+ : this . findOpenDropdown ( ) ?. findAll ( `.${ itemStyles [ 'item-element' ] } ` ) || [ ] ;
94
119
}
95
120
96
121
/**
97
122
* Finds the disabled reason tooltip for a dropdown item. Returns null if no disabled item with `disabledReason` is highlighted.
123
+ *
124
+ * @param options
125
+ * * expandToViewport (boolean) - Use this when the component under test is rendered with an `expandToViewport` flag.
98
126
*/
99
- findDisabledReason ( ) : ElementWrapper | null {
100
- return createWrapper ( ) . find ( `[data-testid="button-dropdown-disabled-reason"]` ) ;
127
+ findDisabledReason ( options = { expandToViewport : false } ) : ElementWrapper | null {
128
+ return options . expandToViewport
129
+ ? createWrapper ( ) . find ( `[data-testid="button-dropdown-disabled-reason"]` )
130
+ : createWrapper ( ) . find ( `[data-testid="button-dropdown-disabled-reason"]` ) ;
101
131
}
102
132
103
133
@usesDom
0 commit comments