1
1
import { expect } from '@vaadin/chai-plugins' ;
2
2
import { defineCE , fixtureSync , nextFrame } from '@vaadin/testing-helpers' ;
3
3
import sinon from 'sinon' ;
4
- import { html , LitElement } from 'lit' ;
4
+ import { LitElement } from 'lit' ;
5
+ import { html , unsafeStatic } from 'lit/static-html.js' ;
5
6
import { PolylitMixin } from '../src/polylit-mixin.js' ;
6
7
7
8
describe ( 'PolylitMixin' , ( ) => {
@@ -37,7 +38,7 @@ describe('PolylitMixin', () => {
37
38
const tag = defineCE (
38
39
class extends PolylitMixin ( LitElement ) {
39
40
render ( ) {
40
- return html `< div id =" foo " > Component</ div > ` ;
41
+ return html `< div > Component</ div > ` ;
41
42
}
42
43
43
44
get ( path , object ) {
@@ -55,10 +56,6 @@ describe('PolylitMixin', () => {
55
56
await element . updateComplete ;
56
57
} ) ;
57
58
58
- it ( 'should reference elements with id' , ( ) => {
59
- expect ( element . $ . foo ) . to . be . instanceOf ( HTMLDivElement ) ;
60
- } ) ;
61
-
62
59
it ( 'should get the nested value' , ( ) => {
63
60
expect ( element . get ( 'foo.bar' , { foo : { bar : 'baz' } } ) ) . to . equal ( 'baz' ) ;
64
61
} ) ;
@@ -74,31 +71,6 @@ describe('PolylitMixin', () => {
74
71
} ) ;
75
72
} ) ;
76
73
77
- describe ( 'createRenderRoot' , ( ) => {
78
- let element ;
79
-
80
- const tag = defineCE (
81
- class extends PolylitMixin ( LitElement ) {
82
- render ( ) {
83
- return html `< div id ="foo "> Component</ div > ` ;
84
- }
85
-
86
- createRenderRoot ( ) {
87
- return this ;
88
- }
89
- } ,
90
- ) ;
91
-
92
- beforeEach ( async ( ) => {
93
- element = fixtureSync ( `<${ tag } ></${ tag } >` ) ;
94
- await element . updateComplete ;
95
- } ) ;
96
-
97
- it ( 'should reference elements with id when rendering to light DOM' , ( ) => {
98
- expect ( element . $ . foo ) . to . be . instanceOf ( HTMLDivElement ) ;
99
- } ) ;
100
- } ) ;
101
-
102
74
describe ( 'reflectToAttribute' , ( ) => {
103
75
let element ;
104
76
@@ -1208,4 +1180,79 @@ describe('PolylitMixin', () => {
1208
1180
} ) . to . not . throw ( Error ) ;
1209
1181
} ) ;
1210
1182
} ) ;
1183
+
1184
+ describe ( 'element id map' , ( ) => {
1185
+ let element ;
1186
+
1187
+ describe ( 'basic' , ( ) => {
1188
+ const teleportedTag = defineCE (
1189
+ class extends PolylitMixin ( LitElement ) {
1190
+ connectedCallback ( ) {
1191
+ super . connectedCallback ( ) ;
1192
+
1193
+ if ( this . parentNode !== document . body ) {
1194
+ document . body . appendChild ( this ) ;
1195
+ }
1196
+ }
1197
+
1198
+ render ( ) {
1199
+ return html `Teleported` ;
1200
+ }
1201
+ } ,
1202
+ ) ;
1203
+
1204
+ const tag = defineCE (
1205
+ class extends PolylitMixin ( LitElement ) {
1206
+ render ( ) {
1207
+ return html `
1208
+ < div id ="title "> Title</ div >
1209
+ < ${ unsafeStatic ( teleportedTag ) } id ="teleported" />
1210
+ ` ;
1211
+ }
1212
+ } ,
1213
+ ) ;
1214
+
1215
+ beforeEach ( async ( ) => {
1216
+ element = fixtureSync ( `<${ tag } ></${ tag } >` ) ;
1217
+ await element . updateComplete ;
1218
+ } ) ;
1219
+
1220
+ afterEach ( ( ) => {
1221
+ document . querySelector ( '#teleported' ) . remove ( ) ;
1222
+ } ) ;
1223
+
1224
+ it ( 'should register elements with id' , ( ) => {
1225
+ expect ( element . $ . title ) . to . be . instanceOf ( HTMLDivElement ) ;
1226
+ expect ( element . $ . title . id ) . to . equal ( 'title' ) ;
1227
+ } ) ;
1228
+
1229
+ it ( 'should register teleported elements with id' , ( ) => {
1230
+ expect ( element . $ . teleported ) . to . be . instanceOf ( HTMLElement ) ;
1231
+ expect ( element . $ . teleported . id ) . to . equal ( 'teleported' ) ;
1232
+ } ) ;
1233
+ } ) ;
1234
+
1235
+ describe ( 'createRenderRoot' , ( ) => {
1236
+ const tag = defineCE (
1237
+ class extends PolylitMixin ( LitElement ) {
1238
+ render ( ) {
1239
+ return html `< div id ="foo "> Component</ div > ` ;
1240
+ }
1241
+
1242
+ createRenderRoot ( ) {
1243
+ return this ;
1244
+ }
1245
+ } ,
1246
+ ) ;
1247
+
1248
+ beforeEach ( async ( ) => {
1249
+ element = fixtureSync ( `<${ tag } ></${ tag } >` ) ;
1250
+ await element . updateComplete ;
1251
+ } ) ;
1252
+
1253
+ it ( 'should register elements with id when rendering to light DOM' , ( ) => {
1254
+ expect ( element . $ . foo ) . to . be . instanceOf ( HTMLDivElement ) ;
1255
+ } ) ;
1256
+ } ) ;
1257
+ } ) ;
1211
1258
} ) ;
0 commit comments