1+ import sinon from 'sinon' ;
12import { expect } from '@esm-bundle/chai' ;
23import { fire , fixtureSync , nextRender } from '@vaadin/testing-helpers' ;
4+ import '@vaadin/vaadin-grid' ;
35import { GridTemplatizer } from '../src/vaadin-template-renderer-grid-templatizer.js' ;
46
57import '../vaadin-template-renderer.js' ;
68
79import './fixtures/mock-grid-host.js' ;
810
11+ describe ( 'grid body template' , ( ) => {
12+ function fixtureGrid ( ) {
13+ return fixtureSync ( `
14+ <vaadin-grid>
15+ <vaadin-grid-column>
16+ <template></template>
17+ </vaadin-grid-column>
18+ </vaadin-grid>
19+ ` ) ;
20+ }
21+
22+ it ( 'should process the template' , ( ) => {
23+ const grid = fixtureGrid ( ) ;
24+ const template = grid . querySelector ( 'template' ) ;
25+
26+ expect ( template . __templatizer ) . to . be . an . instanceof ( GridTemplatizer ) ;
27+ } ) ;
28+
29+ it ( 'should throw when using both a template and a renderer' , ( ) => {
30+ const stub = sinon . stub ( window . Vaadin , 'templateRendererCallback' ) ;
31+ const grid = fixtureGrid ( ) ;
32+ const column = grid . firstElementChild ;
33+ stub . restore ( ) ;
34+
35+ column . renderer = ( ) => { } ;
36+
37+ expect ( ( ) => window . Vaadin . templateRendererCallback ( column ) ) . to . throw (
38+ / ^ C a n n o t u s e b o t h a t e m p l a t e a n d a r e n d e r e r f o r < v a a d i n - g r i d - c o l u m n \/ > \. $ /
39+ ) ;
40+ } ) ;
41+ } ) ;
42+
943describe ( 'grid body template' , ( ) => {
1044 let host , grid ;
1145
@@ -26,63 +60,57 @@ describe('grid body template', () => {
2660 await nextRender ( grid ) ;
2761 } ) ;
2862
29- it ( 'should process the template' , ( ) => {
30- const template = grid . querySelector ( 'template.body' ) ;
31-
32- expect ( template . __templatizer ) . to . be . an . instanceof ( GridTemplatizer ) ;
33- } ) ;
34-
3563 it ( 'should render parentProperty' , ( ) => {
36- const parentProperty0 = queryCellContent ( { row : 0 , col : 2 } , 'div.parent-property' ) ;
37- const parentProperty1 = queryCellContent ( { row : 1 , col : 2 } , 'div.parent-property' ) ;
64+ const parentProperty0 = queryCellContent ( { row : 0 , col : 1 } , 'div.parent-property' ) ;
65+ const parentProperty1 = queryCellContent ( { row : 1 , col : 1 } , 'div.parent-property' ) ;
3866
3967 expect ( parentProperty0 . textContent ) . to . equal ( 'parentValue' ) ;
4068 expect ( parentProperty1 . textContent ) . to . equal ( 'parentValue' ) ;
4169 } ) ;
4270
4371 it ( 'should render model.index' , ( ) => {
44- const index0 = queryCellContent ( { row : 0 , col : 2 } , 'div.index' ) ;
45- const index1 = queryCellContent ( { row : 1 , col : 2 } , 'div.index' ) ;
72+ const index0 = queryCellContent ( { row : 0 , col : 1 } , 'div.index' ) ;
73+ const index1 = queryCellContent ( { row : 1 , col : 1 } , 'div.index' ) ;
4674
4775 expect ( index0 . textContent ) . to . equal ( '0' ) ;
4876 expect ( index1 . textContent ) . to . equal ( '1' ) ;
4977 } ) ;
5078
5179 it ( 'should render model.selected' , ( ) => {
52- const selected0 = queryCellContent ( { row : 0 , col : 2 } , 'div.selected' ) ;
53- const selected1 = queryCellContent ( { row : 1 , col : 2 } , 'div.selected' ) ;
80+ const selected0 = queryCellContent ( { row : 0 , col : 1 } , 'div.selected' ) ;
81+ const selected1 = queryCellContent ( { row : 1 , col : 1 } , 'div.selected' ) ;
5482
5583 expect ( selected0 . textContent ) . to . equal ( 'false' ) ;
5684 expect ( selected1 . textContent ) . to . equal ( 'false' ) ;
5785 } ) ;
5886
5987 it ( 'should render model.expanded' , ( ) => {
60- const expanded0 = queryCellContent ( { row : 0 , col : 2 } , 'div.expanded' ) ;
61- const expanded1 = queryCellContent ( { row : 1 , col : 2 } , 'div.expanded' ) ;
88+ const expanded0 = queryCellContent ( { row : 0 , col : 1 } , 'div.expanded' ) ;
89+ const expanded1 = queryCellContent ( { row : 1 , col : 1 } , 'div.expanded' ) ;
6290
6391 expect ( expanded0 . textContent ) . to . equal ( 'false' ) ;
6492 expect ( expanded1 . textContent ) . to . equal ( 'false' ) ;
6593 } ) ;
6694
6795 it ( 'should render model.detailsOpened' , ( ) => {
68- const detailsOpened0 = queryCellContent ( { row : 0 , col : 2 } , 'div.details-opened' ) ;
69- const detailsOpened1 = queryCellContent ( { row : 1 , col : 2 } , 'div.details-opened' ) ;
96+ const detailsOpened0 = queryCellContent ( { row : 0 , col : 1 } , 'div.details-opened' ) ;
97+ const detailsOpened1 = queryCellContent ( { row : 1 , col : 1 } , 'div.details-opened' ) ;
7098
7199 expect ( detailsOpened0 . textContent ) . to . equal ( 'false' ) ;
72100 expect ( detailsOpened1 . textContent ) . to . equal ( 'false' ) ;
73101 } ) ;
74102
75103 it ( 'should render model.item.title' , ( ) => {
76- const title0 = queryCellContent ( { row : 0 , col : 2 } , 'div.title' ) ;
77- const title1 = queryCellContent ( { row : 1 , col : 2 } , 'div.title' ) ;
104+ const title0 = queryCellContent ( { row : 0 , col : 1 } , 'div.title' ) ;
105+ const title1 = queryCellContent ( { row : 1 , col : 1 } , 'div.title' ) ;
78106
79107 expect ( title0 . textContent ) . to . equal ( 'item0' ) ;
80108 expect ( title1 . textContent ) . to . equal ( 'item1' ) ;
81109 } ) ;
82110
83111 describe ( 'changing parentProperty' , ( ) => {
84112 beforeEach ( ( ) => {
85- const input = queryCellContent ( { row : 0 , col : 1 } , 'input.parent-property' ) ;
113+ const input = queryCellContent ( { row : 0 , col : 0 } , 'input.parent-property' ) ;
86114
87115 input . value = 'new' ;
88116 fire ( input , 'input' ) ;
@@ -93,8 +121,8 @@ describe('grid body template', () => {
93121 } ) ;
94122
95123 it ( 'should re-render the property in other rows' , ( ) => {
96- const parentProperty0 = queryCellContent ( { row : 0 , col : 2 } , 'div.parent-property' ) ;
97- const parentProperty1 = queryCellContent ( { row : 1 , col : 2 } , 'div.parent-property' ) ;
124+ const parentProperty0 = queryCellContent ( { row : 0 , col : 1 } , 'div.parent-property' ) ;
125+ const parentProperty1 = queryCellContent ( { row : 1 , col : 1 } , 'div.parent-property' ) ;
98126
99127 expect ( parentProperty0 . textContent ) . to . equal ( 'new' ) ;
100128 expect ( parentProperty1 . textContent ) . to . equal ( 'new' ) ;
@@ -103,7 +131,7 @@ describe('grid body template', () => {
103131
104132 describe ( 'changing model.item.title' , ( ) => {
105133 beforeEach ( ( ) => {
106- const input = queryCellContent ( { row : 0 , col : 1 } , 'input.title' ) ;
134+ const input = queryCellContent ( { row : 0 , col : 0 } , 'input.title' ) ;
107135
108136 input . value = 'new0' ;
109137 fire ( input , 'input' ) ;
@@ -115,8 +143,8 @@ describe('grid body template', () => {
115143 } ) ;
116144
117145 it ( 'should re-render the row' , ( ) => {
118- const title0 = queryCellContent ( { row : 0 , col : 2 } , 'div.title' ) ;
119- const title1 = queryCellContent ( { row : 1 , col : 2 } , 'div.title' ) ;
146+ const title0 = queryCellContent ( { row : 0 , col : 1 } , 'div.title' ) ;
147+ const title1 = queryCellContent ( { row : 1 , col : 1 } , 'div.title' ) ;
120148
121149 expect ( title0 . textContent ) . to . equal ( 'new0' ) ;
122150 expect ( title1 . textContent ) . to . equal ( 'item1' ) ;
@@ -137,9 +165,9 @@ describe('grid body template', () => {
137165 cb ( items , 1 ) ;
138166 } ;
139167
140- checkbox = getCell ( { row : 0 , col : 1 } ) . _content . querySelector ( 'vaadin-checkbox.expanded' ) ;
141- expanded0 = getCell ( { row : 0 , col : 2 } ) . _content . querySelector ( 'div.expanded' ) ;
142- expanded1 = getCell ( { row : 1 , col : 2 } ) . _content . querySelector ( 'div.expanded' ) ;
168+ checkbox = getCell ( { row : 0 , col : 0 } ) . _content . querySelector ( 'vaadin-checkbox.expanded' ) ;
169+ expanded0 = getCell ( { row : 0 , col : 1 } ) . _content . querySelector ( 'div.expanded' ) ;
170+ expanded1 = getCell ( { row : 1 , col : 1 } ) . _content . querySelector ( 'div.expanded' ) ;
143171 } ) ;
144172
145173 beforeEach ( ( ) => {
@@ -175,9 +203,9 @@ describe('grid body template', () => {
175203 let checkbox , selected0 , selected1 ;
176204
177205 beforeEach ( ( ) => {
178- checkbox = queryCellContent ( { row : 0 , col : 1 } , 'vaadin-checkbox.selected' ) ;
179- selected0 = queryCellContent ( { row : 0 , col : 2 } , 'div.selected' ) ;
180- selected1 = queryCellContent ( { row : 1 , col : 2 } , 'div.selected' ) ;
206+ checkbox = queryCellContent ( { row : 0 , col : 0 } , 'vaadin-checkbox.selected' ) ;
207+ selected0 = queryCellContent ( { row : 0 , col : 1 } , 'div.selected' ) ;
208+ selected1 = queryCellContent ( { row : 1 , col : 1 } , 'div.selected' ) ;
181209 } ) ;
182210
183211 beforeEach ( ( ) => {
@@ -213,9 +241,9 @@ describe('grid body template', () => {
213241 let checkbox , detailsOpened0 , detailsOpened1 ;
214242
215243 beforeEach ( ( ) => {
216- checkbox = queryCellContent ( { row : 0 , col : 1 } , 'vaadin-checkbox.details-opened' ) ;
217- detailsOpened0 = queryCellContent ( { row : 0 , col : 2 } , 'div.details-opened' ) ;
218- detailsOpened1 = queryCellContent ( { row : 1 , col : 2 } , 'div.details-opened' ) ;
244+ checkbox = queryCellContent ( { row : 0 , col : 0 } , 'vaadin-checkbox.details-opened' ) ;
245+ detailsOpened0 = queryCellContent ( { row : 0 , col : 1 } , 'div.details-opened' ) ;
246+ detailsOpened1 = queryCellContent ( { row : 1 , col : 1 } , 'div.details-opened' ) ;
219247 } ) ;
220248
221249 beforeEach ( ( ) => {
0 commit comments