@@ -5,7 +5,7 @@ describe('UUICopyElement', () => {
55 let element : UUICopyElement ;
66
77 beforeEach ( async ( ) => {
8- element = await fixture ( html ` < uui-copy > </ uui-copy > ` ) ;
8+ element = await fixture ( html `< uui-copy value =" Oh hi there " > </ uui-copy > ` ) ;
99 } ) ;
1010
1111 it ( 'is defined with its own instance' , ( ) => {
@@ -15,4 +15,53 @@ describe('UUICopyElement', () => {
1515 it ( 'passes the a11y audit' , async ( ) => {
1616 await expect ( element ) . shadowDom . to . be . accessible ( ) ;
1717 } ) ;
18+
19+ it ( 'renders correctly' , async ( ) => {
20+ expect ( element ) . shadowDom . to . equal ( `
21+ <uui-button>
22+ <slot>
23+ <uui-icon name="copy"></uui-icon> Copy
24+ </slot>
25+ </uui-button>
26+ ` ) ;
27+ } ) ;
28+
29+ it ( 'copies the value property to clipboard when button is clicked' , async ( ) => {
30+ const button = element . shadowRoot ?. querySelector ( 'uui-button' ) ;
31+ // // Mock the clipboard API
32+ // navigator.clipboard = {
33+ // writeText: async text => {
34+ // expect(text).to.equal('Test Text');
35+ // return Promise.resolve();
36+ // },
37+ // };
38+
39+ button ?. click ( ) ;
40+ } ) ;
41+
42+ it ( 'fires copying and copied events' , async ( ) => {
43+ const button = element . shadowRoot ?. querySelector ( 'uui-button' ) ;
44+ // // Mock the clipboard API
45+ // navigator.clipboard = {
46+ // writeText: async text => {
47+ // return Promise.resolve();
48+ // },
49+ // };
50+
51+ let copyingEventFired = false ;
52+ let copiedEventFired = false ;
53+
54+ element . addEventListener ( 'copying' , ( ) => {
55+ copyingEventFired = true ;
56+ } ) ;
57+
58+ element . addEventListener ( 'copied' , ( ) => {
59+ copiedEventFired = true ;
60+ } ) ;
61+
62+ button ?. click ( ) ;
63+
64+ expect ( copyingEventFired ) . to . be . true ;
65+ expect ( copiedEventFired ) . to . be . true ;
66+ } ) ;
1867} ) ;
0 commit comments