@@ -24,6 +24,16 @@ describe('CopyToClipboard', () => {
24
24
expect ( new CopyToClipboard ( ) ) . to . be . instanceOf ( LitElement ) ;
25
25
} ) ;
26
26
27
+ it ( 'has a reactive property/attribite named "layout" (String)' , ( ) => {
28
+ expect ( CopyToClipboard ) . to . have . deep . nested . property ( 'properties.layout' , { } ) ;
29
+ expect ( new CopyToClipboard ( ) ) . to . have . property ( 'layout' , null ) ;
30
+ } ) ;
31
+
32
+ it ( 'has a reactive property/attribite named "theme" (String)' , ( ) => {
33
+ expect ( CopyToClipboard ) . to . have . deep . nested . property ( 'properties.theme' , { } ) ;
34
+ expect ( new CopyToClipboard ( ) ) . to . have . property ( 'theme' , null ) ;
35
+ } ) ;
36
+
27
37
it ( 'has a reactive property/attribite named "text" (String)' , ( ) => {
28
38
expect ( CopyToClipboard ) . to . have . nested . property ( 'properties.text.type' , String ) ;
29
39
} ) ;
@@ -37,7 +47,7 @@ describe('CopyToClipboard', () => {
37
47
expect ( new CopyToClipboard ( ) ) . to . have . property ( 'ns' , 'copy-to-clipboard' ) ;
38
48
} ) ;
39
49
40
- it ( 'renders in the idle state by default' , async ( ) => {
50
+ it ( 'renders in the idle state by default (icon layout) ' , async ( ) => {
41
51
const layout = html `< foxy-copy-to-clipboard > </ foxy-copy-to-clipboard > ` ;
42
52
const element = await fixture < CopyToClipboard > ( layout ) ;
43
53
const tooltip = element . renderRoot . querySelector ( 'vcf-tooltip foxy-i18n' ) as HTMLElement ;
@@ -46,23 +56,32 @@ describe('CopyToClipboard', () => {
46
56
expect ( tooltip ) . to . have . property ( 'key' , 'click_to_copy' ) ;
47
57
} ) ;
48
58
49
- it ( 'renders default icon when icon attribute is not set' , async ( ) => {
59
+ it ( 'renders in the idle state by default (text layout)' , async ( ) => {
60
+ const layout = html `< foxy-copy-to-clipboard layout ="text "> </ foxy-copy-to-clipboard > ` ;
61
+ const element = await fixture < CopyToClipboard > ( layout ) ;
62
+ const tooltip = element . renderRoot . querySelector ( 'vaadin-button foxy-i18n' ) as HTMLElement ;
63
+
64
+ expect ( tooltip ) . to . have . property ( 'infer' , '' ) ;
65
+ expect ( tooltip ) . to . have . property ( 'key' , 'click_to_copy' ) ;
66
+ } ) ;
67
+
68
+ it ( 'renders default icon in icon layout when icon attribute is not set' , async ( ) => {
50
69
const layout = html `< foxy-copy-to-clipboard > </ foxy-copy-to-clipboard > ` ;
51
70
const element = await fixture < CopyToClipboard > ( layout ) ;
52
71
const icon = element . renderRoot . querySelector ( 'iron-icon' ) as HTMLElement ;
53
72
54
73
expect ( icon ) . to . have . property ( 'icon' , 'icons:content-copy' ) ;
55
74
} ) ;
56
75
57
- it ( 'renders custom icon when icon attribute is set' , async ( ) => {
76
+ it ( 'renders custom icon in icon layout when icon attribute is set' , async ( ) => {
58
77
const layout = html `< foxy-copy-to-clipboard icon ="icons:foo "> </ foxy-copy-to-clipboard > ` ;
59
78
const element = await fixture < CopyToClipboard > ( layout ) ;
60
79
const icon = element . renderRoot . querySelector ( 'iron-icon' ) as HTMLElement ;
61
80
62
81
expect ( icon ) . to . have . property ( 'icon' , 'icons:foo' ) ;
63
82
} ) ;
64
83
65
- it ( 'copies text on click' , async ( ) => {
84
+ it ( 'copies text on click in icon layout ' , async ( ) => {
66
85
const writeTextMethod = stub ( navigator . clipboard , 'writeText' ) . resolves ( ) ;
67
86
const layout = html `< foxy-copy-to-clipboard text ="Foo "> </ foxy-copy-to-clipboard > ` ;
68
87
const element = await fixture < CopyToClipboard > ( layout ) ;
@@ -86,7 +105,31 @@ describe('CopyToClipboard', () => {
86
105
writeTextMethod . restore ( ) ;
87
106
} ) ;
88
107
89
- it ( 'switches to the busy state when copying text' , async ( ) => {
108
+ it ( 'copies text on click in text layout' , async ( ) => {
109
+ const writeTextMethod = stub ( navigator . clipboard , 'writeText' ) . resolves ( ) ;
110
+ const layout = html `< foxy-copy-to-clipboard layout ="text " text ="Foo "> </ foxy-copy-to-clipboard > ` ;
111
+ const element = await fixture < CopyToClipboard > ( layout ) ;
112
+ const button = element . renderRoot . querySelector ( 'vaadin-button' ) ;
113
+
114
+ button ?. click ( ) ;
115
+ await waitUntil (
116
+ ( ) => {
117
+ try {
118
+ expect ( writeTextMethod ) . to . have . been . calledOnceWith ( 'Foo' ) ;
119
+ return true ;
120
+ } catch {
121
+ return false ;
122
+ }
123
+ } ,
124
+ undefined ,
125
+ { timeout : 5000 }
126
+ ) ;
127
+
128
+ expect ( writeTextMethod ) . to . have . been . calledOnceWith ( 'Foo' ) ;
129
+ writeTextMethod . restore ( ) ;
130
+ } ) ;
131
+
132
+ it ( 'switches to the busy state when copying text in icon layout' , async ( ) => {
90
133
const writeTextMethod = stub ( navigator . clipboard , 'writeText' ) . returns (
91
134
new Promise ( ( ) => void 0 )
92
135
) ;
@@ -104,7 +147,25 @@ describe('CopyToClipboard', () => {
104
147
writeTextMethod . restore ( ) ;
105
148
} ) ;
106
149
107
- it ( 'switches to the idle state ~2s after copying text successfully' , async ( ) => {
150
+ it ( 'switches to the busy state when copying text in text layout' , async ( ) => {
151
+ const writeTextMethod = stub ( navigator . clipboard , 'writeText' ) . returns (
152
+ new Promise ( ( ) => void 0 )
153
+ ) ;
154
+
155
+ const layout = html `< foxy-copy-to-clipboard layout ="text " text ="Foo "> </ foxy-copy-to-clipboard > ` ;
156
+ const element = await fixture < CopyToClipboard > ( layout ) ;
157
+ const button = element . renderRoot . querySelector ( 'vaadin-button' ) ;
158
+ const tooltip = button ?. querySelector ( 'foxy-i18n' ) ;
159
+
160
+ button ?. click ( ) ;
161
+ await element . requestUpdate ( ) ;
162
+
163
+ expect ( tooltip ) . to . have . property ( 'infer' , '' ) ;
164
+ expect ( tooltip ) . to . have . property ( 'key' , 'copying' ) ;
165
+ writeTextMethod . restore ( ) ;
166
+ } ) ;
167
+
168
+ it ( 'switches to the idle state ~2s after copying text successfully in icon layout' , async ( ) => {
108
169
const writeTextMethod = stub ( navigator . clipboard , 'writeText' ) . resolves ( ) ;
109
170
const layout = html `< foxy-copy-to-clipboard > </ foxy-copy-to-clipboard > ` ;
110
171
const element = await fixture < CopyToClipboard > ( layout ) ;
@@ -127,7 +188,30 @@ describe('CopyToClipboard', () => {
127
188
writeTextMethod . restore ( ) ;
128
189
} ) ;
129
190
130
- it ( 'switches to the error state when copying text fails' , async ( ) => {
191
+ it ( 'switches to the idle state ~2s after copying text successfully in text layout' , async ( ) => {
192
+ const writeTextMethod = stub ( navigator . clipboard , 'writeText' ) . resolves ( ) ;
193
+ const layout = html `< foxy-copy-to-clipboard layout ="text "> </ foxy-copy-to-clipboard > ` ;
194
+ const element = await fixture < CopyToClipboard > ( layout ) ;
195
+ const button = element . renderRoot . querySelector ( 'vaadin-button' ) ;
196
+ const tooltip = button ?. querySelector ( 'foxy-i18n' ) ;
197
+
198
+ button ?. click ( ) ;
199
+
200
+ await waitUntil (
201
+ async ( ) => {
202
+ await element . requestUpdate ( ) ;
203
+ return tooltip ?. getAttribute ( 'key' ) === 'click_to_copy' ;
204
+ } ,
205
+ undefined ,
206
+ { timeout : 5000 }
207
+ ) ;
208
+
209
+ expect ( tooltip ) . to . have . property ( 'infer' , '' ) ;
210
+ expect ( tooltip ) . to . have . property ( 'key' , 'click_to_copy' ) ;
211
+ writeTextMethod . restore ( ) ;
212
+ } ) ;
213
+
214
+ it ( 'switches to the error state when copying text fails in icon layout' , async ( ) => {
131
215
const writeTextMethod = stub ( navigator . clipboard , 'writeText' ) . rejects ( ) ;
132
216
const layout = html `< foxy-copy-to-clipboard text ="Foo "> </ foxy-copy-to-clipboard > ` ;
133
217
const element = await fixture < CopyToClipboard > ( layout ) ;
@@ -150,7 +234,30 @@ describe('CopyToClipboard', () => {
150
234
writeTextMethod . restore ( ) ;
151
235
} ) ;
152
236
153
- it ( 'switches to the idle state ~2s after copying text fails' , async ( ) => {
237
+ it ( 'switches to the error state when copying text fails in text layout' , async ( ) => {
238
+ const writeTextMethod = stub ( navigator . clipboard , 'writeText' ) . rejects ( ) ;
239
+ const layout = html `< foxy-copy-to-clipboard layout ="text " text ="Foo "> </ foxy-copy-to-clipboard > ` ;
240
+ const element = await fixture < CopyToClipboard > ( layout ) ;
241
+ const button = element . renderRoot . querySelector ( 'vaadin-button' ) ;
242
+ const tooltip = button ?. querySelector ( 'foxy-i18n' ) ;
243
+
244
+ button ?. click ( ) ;
245
+
246
+ await waitUntil (
247
+ async ( ) => {
248
+ await element . requestUpdate ( ) ;
249
+ return tooltip ?. getAttribute ( 'key' ) === 'failed_to_copy' ;
250
+ } ,
251
+ undefined ,
252
+ { timeout : 5000 }
253
+ ) ;
254
+
255
+ expect ( tooltip ) . to . have . property ( 'infer' , '' ) ;
256
+ expect ( tooltip ) . to . have . property ( 'key' , 'failed_to_copy' ) ;
257
+ writeTextMethod . restore ( ) ;
258
+ } ) ;
259
+
260
+ it ( 'switches to the idle state ~2s after copying text fails in icon layout' , async ( ) => {
154
261
const writeTextMethod = stub ( navigator . clipboard , 'writeText' ) . rejects ( ) ;
155
262
const layout = html `< foxy-copy-to-clipboard > </ foxy-copy-to-clipboard > ` ;
156
263
const element = await fixture < CopyToClipboard > ( layout ) ;
@@ -172,4 +279,36 @@ describe('CopyToClipboard', () => {
172
279
expect ( tooltip ) . to . have . property ( 'key' , 'click_to_copy' ) ;
173
280
writeTextMethod . restore ( ) ;
174
281
} ) ;
282
+
283
+ it ( 'switches to the idle state ~2s after copying text fails in text layout' , async ( ) => {
284
+ const writeTextMethod = stub ( navigator . clipboard , 'writeText' ) . rejects ( ) ;
285
+ const layout = html `< foxy-copy-to-clipboard layout ="text "> </ foxy-copy-to-clipboard > ` ;
286
+ const element = await fixture < CopyToClipboard > ( layout ) ;
287
+ const button = element . renderRoot . querySelector ( 'vaadin-button' ) ;
288
+ const tooltip = button ?. querySelector ( 'foxy-i18n' ) ;
289
+
290
+ button ?. click ( ) ;
291
+
292
+ await waitUntil (
293
+ async ( ) => {
294
+ await element . requestUpdate ( ) ;
295
+ return tooltip ?. getAttribute ( 'key' ) === 'click_to_copy' ;
296
+ } ,
297
+ undefined ,
298
+ { timeout : 5000 }
299
+ ) ;
300
+
301
+ expect ( tooltip ) . to . have . property ( 'infer' , '' ) ;
302
+ expect ( tooltip ) . to . have . property ( 'key' , 'click_to_copy' ) ;
303
+ writeTextMethod . restore ( ) ;
304
+ } ) ;
305
+
306
+ it ( 'propagates theme attribute to vaadin-button in text layout' , async ( ) => {
307
+ const element = await fixture < CopyToClipboard > ( html `
308
+ < foxy-copy-to-clipboard layout ="text " theme ="foo "> </ foxy-copy-to-clipboard >
309
+ ` ) ;
310
+
311
+ const button = element . renderRoot . querySelector ( 'vaadin-button' ) ;
312
+ expect ( button ) . to . have . attribute ( 'theme' , 'foo' ) ;
313
+ } ) ;
175
314
} ) ;
0 commit comments