1
1
import { expect } from '@esm-bundle/chai' ;
2
2
import sinon from 'sinon' ;
3
3
import { fixtureSync , nextFrame } from '@open-wc/testing-helpers' ;
4
- import { PolymerElement , html } from '@polymer/polymer/polymer-element.js' ;
4
+ import { html , PolymerElement } from '@polymer/polymer/polymer-element.js' ;
5
5
import '@polymer/polymer/lib/elements/dom-repeat.js' ;
6
6
import {
7
+ buildDataSet ,
7
8
click ,
8
9
flushGrid ,
9
10
getBodyCellContent ,
10
11
getCellContent ,
11
- getRows ,
12
12
getRowCells ,
13
+ getRows ,
13
14
infiniteDataProvider ,
14
15
scrollToEnd
15
16
} from './helpers.js' ;
@@ -49,6 +50,14 @@ describe('row details', () => {
49
50
let grid ;
50
51
let bodyRows ;
51
52
53
+ function openRowDetails ( index ) {
54
+ grid . openItemDetails ( grid . _cache . items [ index ] ) ;
55
+ }
56
+
57
+ function closeRowDetails ( index ) {
58
+ grid . closeItemDetails ( grid . _cache . items [ index ] ) ;
59
+ }
60
+
52
61
it ( 'should not increase row update count' , ( ) => {
53
62
grid = fixtureSync ( `
54
63
<vaadin-grid style="width: 50px; height: 400px" size="100">
@@ -66,10 +75,6 @@ describe('row details', () => {
66
75
} ) ;
67
76
68
77
describe ( 'simple' , ( ) => {
69
- function openRowDetails ( index ) {
70
- grid . openItemDetails ( grid . _cache . items [ index ] ) ;
71
- }
72
-
73
78
beforeEach ( async ( ) => {
74
79
grid = fixtureSync ( `
75
80
<vaadin-grid style="width: 50px; height: 400px" size="100">
@@ -85,10 +90,6 @@ describe('row details', () => {
85
90
await nextFrame ( ) ;
86
91
} ) ;
87
92
88
- function closeRowDetails ( index ) {
89
- grid . closeItemDetails ( grid . _cache . items [ index ] ) ;
90
- }
91
-
92
93
it ( 'should not activate on click' , ( ) => {
93
94
openRowDetails ( 0 ) ;
94
95
const detailsCellContent = getBodyCellContent ( grid , 0 , 1 ) ;
@@ -157,13 +158,6 @@ describe('row details', () => {
157
158
assertDetailsBounds ( ) ;
158
159
} ) ;
159
160
160
- it ( 'should have state attribute' , ( ) => {
161
- openRowDetails ( 1 ) ;
162
- expect ( bodyRows [ 1 ] . hasAttribute ( 'details-opened' ) ) . to . be . true ;
163
- closeRowDetails ( 1 ) ;
164
- expect ( bodyRows [ 1 ] . hasAttribute ( 'details-opened' ) ) . to . be . false ;
165
- } ) ;
166
-
167
161
it ( 'should have correct bounds when modified after opening' , async ( ) => {
168
162
openRowDetails ( 1 ) ;
169
163
const cells = getRowCells ( bodyRows [ 1 ] ) ;
@@ -297,4 +291,69 @@ describe('row details', () => {
297
291
expect ( row . offsetHeight ) . to . be . above ( 70 ) ;
298
292
} ) ;
299
293
} ) ;
294
+
295
+ describe ( 'details opened attribute' , ( ) => {
296
+ let dataset = [ ] ;
297
+ const dataProvider = ( params , callback ) => callback ( dataset ) ;
298
+
299
+ const countRowsMarkedAsDetailsOpened = ( grid ) => {
300
+ return grid . $ . items . querySelectorAll ( 'tr[details-opened]' ) . length ;
301
+ } ;
302
+
303
+ beforeEach ( async ( ) => {
304
+ dataset = buildDataSet ( 10 ) ;
305
+ grid = fixtureSync ( `
306
+ <vaadin-grid style="width: 50px; height: 400px" size="100">
307
+ <template class="row-details"><span>[[index]]</span>-details</template>
308
+ <vaadin-grid-column>
309
+ <template>[[index]]</template>
310
+ </vaadin-grid-column>
311
+ </vaadin-grid>
312
+ ` ) ;
313
+ grid . dataProvider = dataProvider ;
314
+ flushGrid ( grid ) ;
315
+ bodyRows = getRows ( grid . $ . items ) ;
316
+ await nextFrame ( ) ;
317
+ } ) ;
318
+
319
+ it ( 'should update when opening/closing imperatively' , ( ) => {
320
+ openRowDetails ( 1 ) ;
321
+ expect ( bodyRows [ 1 ] . hasAttribute ( 'details-opened' ) ) . to . be . true ;
322
+ expect ( countRowsMarkedAsDetailsOpened ( grid ) ) . to . equal ( 1 ) ;
323
+ closeRowDetails ( 1 ) ;
324
+ expect ( bodyRows [ 1 ] . hasAttribute ( 'details-opened' ) ) . to . be . false ;
325
+ expect ( countRowsMarkedAsDetailsOpened ( grid ) ) . to . equal ( 0 ) ;
326
+ } ) ;
327
+
328
+ it ( 'should be removed when item is removed' , ( ) => {
329
+ openRowDetails ( 0 ) ;
330
+ dataset . shift ( ) ; // remove opened item
331
+ grid . clearCache ( ) ;
332
+
333
+ expect ( bodyRows [ 0 ] . hasAttribute ( 'details-opened' ) ) . to . be . false ;
334
+ expect ( countRowsMarkedAsDetailsOpened ( grid ) ) . to . equal ( 0 ) ;
335
+ } ) ;
336
+
337
+ it ( 'should be removed when items are replaced' , ( ) => {
338
+ openRowDetails ( 0 ) ;
339
+ dataset = buildDataSet ( 10 ) ; // replace data
340
+ grid . clearCache ( ) ;
341
+
342
+ expect ( bodyRows [ 0 ] . hasAttribute ( 'details-opened' ) ) . to . be . false ;
343
+ expect ( countRowsMarkedAsDetailsOpened ( grid ) ) . to . equal ( 0 ) ;
344
+ } ) ;
345
+
346
+ it ( 'should be removed on all rows when items are replaced' , ( ) => {
347
+ // Open all rows
348
+ dataset . forEach ( ( _ , i ) => {
349
+ openRowDetails ( i ) ;
350
+ } ) ;
351
+ expect ( countRowsMarkedAsDetailsOpened ( grid ) ) . to . equal ( dataset . length ) ;
352
+
353
+ dataset = buildDataSet ( 10 ) ; // replace data
354
+ grid . clearCache ( ) ;
355
+
356
+ expect ( countRowsMarkedAsDetailsOpened ( grid ) ) . to . equal ( 0 ) ;
357
+ } ) ;
358
+ } ) ;
300
359
} ) ;
0 commit comments