@@ -60,38 +60,64 @@ describe("Table - Rendering", () => {
60
60
} ) ;
61
61
62
62
describe ( "Table - Popin Mode" , ( ) => {
63
- beforeEach ( ( ) => {
63
+ function checkPopinState ( expectedState : { poppedIn : string [ ] , hidden : string [ ] } ) {
64
+ cy . get ( "ui5-table-header-cell" ) . each ( ( $cell , index ) => {
65
+ const id = $cell . attr ( "id" ) ?? "" ;
66
+ const shouldBePoppedIn = expectedState . poppedIn . includes ( id ) ;
67
+ const shouldBeHidden = expectedState . hidden . includes ( id ) ;
68
+ const roleCondition = shouldBePoppedIn || shouldBeHidden ? "not.have.attr" : "have.attr" ;
69
+
70
+ cy . wrap ( $cell )
71
+ . should ( roleCondition , "role" , ROLE_COLUMN_HEADER ) ;
72
+ cy . get ( "ui5-table-header-row" )
73
+ . shadow ( )
74
+ . find ( `slot[name=default-${ index + 1 } ]` )
75
+ . should ( shouldBePoppedIn || shouldBeHidden ? "not.exist" : "exist" ) ;
76
+ } ) ;
77
+
78
+ cy . get ( "ui5-table-row" ) . each ( $row => {
79
+ cy . wrap ( $row ) . find ( "ui5-table-cell" ) . each ( ( $cell , index ) => {
80
+ const id = $cell . attr ( "id" ) ?? "NOT_FOUND" ;
81
+ const shouldBeHidden = expectedState . hidden . some ( hiddenId => id . includes ( hiddenId ) ) ;
82
+ cy . wrap ( $row ) . shadow ( ) . find ( `slot[name=default-${ index + 1 } ]` )
83
+ . should ( shouldBeHidden ? "not.exist" : "exist" ) ;
84
+ } ) ;
85
+ } ) ;
86
+ }
87
+
88
+ function mounTable ( popinHidden = false ) {
64
89
cy . mount (
65
90
< Table id = "table" overflowMode = "Popin" >
66
91
< TableHeaderRow slot = "headerRow" >
67
92
< TableHeaderCell id = "colA" minWidth = "300px" > < span > ColumnA</ span > </ TableHeaderCell >
68
93
< TableHeaderCell id = "colB" minWidth = "200px" > Column B</ TableHeaderCell >
69
94
< TableHeaderCell id = "colC" minWidth = "200px" > Column C</ TableHeaderCell >
70
- < TableHeaderCell id = "colD" minWidth = "150px" popinText = "Column ?" > Column D</ TableHeaderCell >
95
+ < TableHeaderCell id = "colD" minWidth = "150px" popinText = "Column ?" popinHidden = { popinHidden } > Column D</ TableHeaderCell >
71
96
</ TableHeaderRow >
72
97
< TableRow >
73
- < TableCell > < Label > Cell A</ Label > </ TableCell >
74
- < TableCell > < Label > Cell B</ Label > </ TableCell >
75
- < TableCell > < Label > Cell C</ Label > </ TableCell >
76
- < TableCell > < Label > Cell D</ Label > </ TableCell >
98
+ < TableCell id = "row-1-colA" > < Label > Cell A</ Label > </ TableCell >
99
+ < TableCell id = "row-1-colB" > < Label > Cell B</ Label > </ TableCell >
100
+ < TableCell id = "row-1-colC" > < Label > Cell C</ Label > </ TableCell >
101
+ < TableCell id = "row-1-colD" > < Label > Cell D</ Label > </ TableCell >
77
102
</ TableRow >
78
103
< TableRow >
79
- < TableCell > < Label > Cell A</ Label > </ TableCell >
80
- < TableCell > < Label > Cell B</ Label > </ TableCell >
81
- < TableCell > < Label > Cell C</ Label > </ TableCell >
82
- < TableCell > < Label > Cell D</ Label > </ TableCell >
104
+ < TableCell id = "row-2-colA" > < Label > Cell A</ Label > </ TableCell >
105
+ < TableCell id = "row-2-colB" > < Label > Cell B</ Label > </ TableCell >
106
+ < TableCell id = "row-2-colC" > < Label > Cell C</ Label > </ TableCell >
107
+ < TableCell id = "row-2-colD" > < Label > Cell D</ Label > </ TableCell >
83
108
</ TableRow >
84
109
< TableRow >
85
- < TableCell > < Label > Cell A</ Label > </ TableCell >
86
- < TableCell > < Label > Cell B</ Label > </ TableCell >
87
- < TableCell > < Label > Cell C</ Label > </ TableCell >
88
- < TableCell > < Label > Cell D</ Label > </ TableCell >
110
+ < TableCell id = "row-3-colA" > < Label > Cell A</ Label > </ TableCell >
111
+ < TableCell id = "row-3-colB" > < Label > Cell B</ Label > </ TableCell >
112
+ < TableCell id = "row-3-colC" > < Label > Cell C</ Label > </ TableCell >
113
+ < TableCell id = "row-3-colD" > < Label > Cell D</ Label > </ TableCell >
89
114
</ TableRow >
90
115
</ Table >
91
116
) ;
92
- } ) ;
117
+ }
93
118
94
119
it ( "no pop-in width 'optimal' table width" , ( ) => {
120
+ mounTable ( ) ;
95
121
cy . get ( "ui5-table" ) . then ( $table => {
96
122
$table . css ( "width" , "850px" ) ;
97
123
} ) ;
@@ -103,17 +129,11 @@ describe("Table - Popin Mode", () => {
103
129
cy . get ( "ui5-table-header-cell" )
104
130
. should ( "have.length" , 4 ) ;
105
131
106
- cy . get ( "ui5-table-header-cell" ) . each ( ( $cell , index ) => {
107
- cy . wrap ( $cell )
108
- . should ( "have.attr" , "role" , ROLE_COLUMN_HEADER ) ;
109
- cy . get ( "ui5-table-header-row" )
110
- . shadow ( )
111
- . find ( `slot[name=default-${ index + 1 } ]` )
112
- . should ( "exist" ) ;
113
- } ) ;
132
+ checkPopinState ( { poppedIn : [ ] , hidden : [ ] } ) ;
114
133
} ) ;
115
134
116
135
it ( "test with one by one popping in" , ( ) => {
136
+ mounTable ( ) ;
117
137
const testWidths = [
118
138
{ width : 850 , poppedIn : [ ] } ,
119
139
{ width : 700 , poppedIn : [ "colD" ] } ,
@@ -127,22 +147,12 @@ describe("Table - Popin Mode", () => {
127
147
$table . css ( "width" , `${ width } px` ) ;
128
148
} ) ;
129
149
130
- cy . get ( "ui5-table-header-cell" ) . each ( ( $cell , index ) => {
131
- const id = $cell . attr ( "id" ) ?? "" ;
132
- const shouldBePoppedIn = poppedIn . includes ( id ) ;
133
- const roleCondition = shouldBePoppedIn ? "not.have.attr" : "have.attr" ;
134
-
135
- cy . wrap ( $cell )
136
- . should ( roleCondition , "role" , ROLE_COLUMN_HEADER ) ;
137
- cy . get ( "ui5-table-header-row" )
138
- . shadow ( )
139
- . find ( `slot[name=default-${ index + 1 } ]` )
140
- . should ( shouldBePoppedIn ? "not.exist" : "exist" ) ;
141
- } ) ;
150
+ checkPopinState ( { poppedIn, hidden : [ ] } ) ;
142
151
} ) ;
143
152
} ) ;
144
153
145
154
it ( "test with one by one popping out" , ( ) => {
155
+ mounTable ( ) ;
146
156
const testWidths = [
147
157
{ width : 150 , poppedIn : [ "colD" , "colC" , "colB" ] } ,
148
158
{ width : 300 , poppedIn : [ "colD" , "colC" , "colB" ] } ,
@@ -156,22 +166,12 @@ describe("Table - Popin Mode", () => {
156
166
$table . css ( "width" , `${ width } px` ) ;
157
167
} ) ;
158
168
159
- cy . get ( "ui5-table-header-cell" ) . each ( ( $cell , index ) => {
160
- const id = $cell . attr ( "id" ) ?? "" ;
161
- const shouldBePoppedIn = poppedIn . includes ( id ) ;
162
- const roleCondition = shouldBePoppedIn ? "not.have.attr" : "have.attr" ;
163
-
164
- cy . wrap ( $cell )
165
- . should ( roleCondition , "role" , ROLE_COLUMN_HEADER ) ;
166
- cy . get ( "ui5-table-header-row" )
167
- . shadow ( )
168
- . find ( `slot[name=default-${ index + 1 } ]` )
169
- . should ( shouldBePoppedIn ? "not.exist" : "exist" ) ;
170
- } ) ;
169
+ checkPopinState ( { poppedIn, hidden : [ ] } ) ;
171
170
} ) ;
172
171
} ) ;
173
172
174
173
it ( "test with random widths" , ( ) => {
174
+ mounTable ( ) ;
175
175
const expectedStates = [
176
176
{ width : 500 , poppedIn : [ "colD" , "colC" , "colB" ] } ,
177
177
{ width : 700 , poppedIn : [ "colD" , "colC" ] } ,
@@ -187,24 +187,12 @@ describe("Table - Popin Mode", () => {
187
187
} ) ;
188
188
189
189
const expectedState = expectedStates . find ( state => state . width >= randomWidth ) ;
190
- // eslint-disable-next-line cypress/no-unnecessary-waiting, no-loop-func
191
- cy . get ( "ui5-table-header-cell" ) . each ( ( $cell , index ) => {
192
- const id = $cell . attr ( "id" ) ?? "" ;
193
- const shouldBePoppedIn = expectedState ?. poppedIn . includes ( id ) ;
194
- const roleCondition = shouldBePoppedIn ? "not.have.attr" : "have.attr" ;
195
-
196
- cy . wrap ( $cell )
197
- . should ( roleCondition , "role" , ROLE_COLUMN_HEADER ) ;
198
-
199
- cy . get ( "ui5-table-header-row" )
200
- . shadow ( )
201
- . find ( `slot[name=default-${ index + 1 } ]` )
202
- . should ( shouldBePoppedIn ? "not.exist" : "exist" ) ;
203
- } ) ;
190
+ checkPopinState ( { poppedIn : expectedState ?. poppedIn ?? [ ] , hidden : [ ] } ) ;
204
191
}
205
192
} ) ;
206
193
207
194
it ( "should show the popin-text in the popin area" , ( ) => {
195
+ mounTable ( ) ;
208
196
cy . get ( "ui5-table" ) . then ( $table => {
209
197
$table . css ( "width" , "150px" ) ;
210
198
} ) ;
@@ -232,6 +220,40 @@ describe("Table - Popin Mode", () => {
232
220
return popinCellCount && popinCellCount === validPopinTextCount ;
233
221
} ) . should ( "be.true" ) ;
234
222
} ) ;
223
+
224
+ it ( "should hide column in popin if popinHidden is set" , ( ) => {
225
+ mounTable ( true ) ;
226
+
227
+ const testWidths = [
228
+ { width : 150 , poppedIn : [ "colC" , "colB" ] , hidden : [ "colD" ] } ,
229
+ { width : 300 , poppedIn : [ "colC" , "colB" ] , hidden : [ "colD" ] } ,
230
+ { width : 500 , poppedIn : [ "colC" ] , hidden : [ "colD" ] } ,
231
+ { width : 700 , poppedIn : [ ] , hidden : [ "colD" ] } ,
232
+ { width : 850 , poppedIn : [ ] , hidden : [ ] } ,
233
+ ] ;
234
+
235
+ testWidths . forEach ( ( { width, poppedIn, hidden } ) => {
236
+ cy . get ( "ui5-table" ) . then ( $table => {
237
+ $table . css ( "width" , `${ width } px` ) ;
238
+ } ) ;
239
+
240
+ checkPopinState ( { poppedIn, hidden } ) ;
241
+ } ) ;
242
+ } ) ;
243
+
244
+ it ( "should hide popin if popinHidden, shows it if changed on runtime" , ( ) => {
245
+ mounTable ( true ) ;
246
+ cy . get ( "ui5-table" ) . then ( $table => {
247
+ $table . css ( "width" , "150px" ) ;
248
+ } ) ;
249
+
250
+ checkPopinState ( { poppedIn : [ "colC" , "colB" ] , hidden : [ "colD" ] } ) ;
251
+
252
+ cy . get ( "#colD" )
253
+ . invoke ( "removeAttr" , "popin-hidden" ) ;
254
+
255
+ checkPopinState ( { poppedIn : [ "colC" , "colB" , "colD" ] , hidden : [ ] } ) ;
256
+ } ) ;
235
257
} ) ;
236
258
237
259
describe ( "Table - Horizontal alignment of cells" , ( ) => {
0 commit comments