1
1
import { expect } from '@vaadin/chai-plugins' ;
2
- import { fixtureSync , focusin , focusout , nextFrame } from '@vaadin/testing-helpers' ;
2
+ import { defineLit , definePolymer , fixtureSync , focusin , focusout , nextFrame } from '@vaadin/testing-helpers' ;
3
3
import sinon from 'sinon' ;
4
- import { html , PolymerElement } from '@polymer/polymer/polymer-element.js' ;
4
+ import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js' ;
5
+ import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js' ;
5
6
import { DelegateFocusMixin } from '../src/delegate-focus-mixin.js' ;
6
7
7
- describe ( 'delegate-focus-mixin' , ( ) => {
8
- let element , input , setFocusedSpy ;
9
-
10
- customElements . define (
11
- 'delegate-focus-mixin-element' ,
12
- class extends DelegateFocusMixin ( PolymerElement ) {
13
- static get template ( ) {
14
- return html `
15
- < slot name ="input "> </ slot >
16
- < slot name ="suffix "> </ slot >
17
- ` ;
18
- }
19
-
20
- /** @protected */
21
- ready ( ) {
22
- super . ready ( ) ;
23
-
24
- const input = this . querySelector ( 'input' ) ;
25
- this . _setFocusElement ( input ) ;
26
- }
27
-
28
- _setFocused ( focused ) {
29
- super . _setFocused ( focused ) ;
30
- setFocusedSpy ?. ( focused ) ;
31
- }
32
- } ,
8
+ const runTests = ( defineHelper , baseMixin ) => {
9
+ let setFocusedSpy ;
10
+
11
+ const tag = defineHelper (
12
+ 'delegate-focus-mixin' ,
13
+ `
14
+ <slot name="input"></slot>
15
+ <slot name="suffix"></slot>
16
+ ` ,
17
+ ( Base ) =>
18
+ class extends DelegateFocusMixin ( baseMixin ( Base ) ) {
19
+ ready ( ) {
20
+ super . ready ( ) ;
21
+ const input = this . querySelector ( 'input' ) ;
22
+ this . _setFocusElement ( input ) ;
23
+ }
24
+
25
+ _setFocused ( focused ) {
26
+ super . _setFocused ( focused ) ;
27
+ setFocusedSpy ?. ( focused ) ;
28
+ }
29
+ } ,
33
30
) ;
34
31
32
+ let element , input ;
33
+
35
34
describe ( 'default' , ( ) => {
36
35
let button ;
37
36
38
37
beforeEach ( ( ) => {
39
38
setFocusedSpy = sinon . spy ( ) ;
40
39
element = fixtureSync ( `
41
- <delegate-focus-mixin-element >
40
+ <${ tag } >
42
41
<input slot="input" />
43
42
<button slot="suffix"></button>
44
- </delegate-focus-mixin-element >
43
+ </${ tag } >
45
44
` ) ;
46
45
input = element . querySelector ( 'input' ) ;
47
46
button = element . querySelector ( 'button' ) ;
@@ -143,9 +142,9 @@ describe('delegate-focus-mixin', () => {
143
142
144
143
beforeEach ( ( ) => {
145
144
element = fixtureSync ( `
146
- <delegate-focus-mixin-element >
145
+ <${ tag } >
147
146
<input slot="input" />
148
- </delegate-focus-mixin-element >
147
+ </${ tag } >
149
148
` ) ;
150
149
input = element . querySelector ( 'input' ) ;
151
150
spy = sinon . spy ( ) ;
@@ -188,7 +187,7 @@ describe('delegate-focus-mixin', () => {
188
187
189
188
describe ( 'autofocus' , ( ) => {
190
189
beforeEach ( ( ) => {
191
- element = document . createElement ( 'delegate-focus-mixin-element' ) ;
190
+ element = document . createElement ( tag ) ;
192
191
element . autofocus = true ;
193
192
194
193
const input = document . createElement ( 'input' ) ;
@@ -246,9 +245,9 @@ describe('delegate-focus-mixin', () => {
246
245
describe ( 'default' , ( ) => {
247
246
beforeEach ( ( ) => {
248
247
element = fixtureSync ( `
249
- <delegate-focus-mixin-element >
248
+ <${ tag } >
250
249
<input slot="input" />
251
- </delegate-focus-mixin-element >
250
+ </${ tag } >
252
251
` ) ;
253
252
input = element . querySelector ( 'input' ) ;
254
253
} ) ;
@@ -285,9 +284,9 @@ describe('delegate-focus-mixin', () => {
285
284
describe ( 'attribute' , ( ) => {
286
285
beforeEach ( ( ) => {
287
286
element = fixtureSync ( `
288
- <delegate-focus-mixin-element tabindex="-1">
287
+ <${ tag } tabindex="-1">
289
288
<input slot="input" />
290
- </delegate-focus-mixin-element >
289
+ </${ tag } >
291
290
` ) ;
292
291
input = element . querySelector ( 'input' ) ;
293
292
} ) ;
@@ -307,4 +306,12 @@ describe('delegate-focus-mixin', () => {
307
306
} ) ;
308
307
} ) ;
309
308
} ) ;
309
+ } ;
310
+
311
+ describe ( 'DelegateFocusMixin + Polymer' , ( ) => {
312
+ runTests ( definePolymer , ControllerMixin ) ;
313
+ } ) ;
314
+
315
+ describe ( 'DelegateFocusMixin + Lit' , ( ) => {
316
+ runTests ( defineLit , PolylitMixin ) ;
310
317
} ) ;
0 commit comments