Skip to content

Commit

Permalink
WIP: To add useful tests
Browse files Browse the repository at this point in the history
  • Loading branch information
warrenbuckley committed Jan 2, 2025
1 parent 8bffab2 commit 0901ebe
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion packages/uui-copy/lib/uui-copy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('UUICopyElement', () => {
let element: UUICopyElement;

beforeEach(async () => {
element = await fixture(html` <uui-copy></uui-copy> `);
element = await fixture(html`<uui-copy value="Oh hi there"></uui-copy>`);
});

it('is defined with its own instance', () => {
Expand All @@ -15,4 +15,53 @@ describe('UUICopyElement', () => {
it('passes the a11y audit', async () => {
await expect(element).shadowDom.to.be.accessible();
});

it('renders correctly', async () => {
expect(element).shadowDom.to.equal(`
<uui-button>
<slot>
<uui-icon name="copy"></uui-icon> Copy
</slot>
</uui-button>
`);
});

it('copies the value property to clipboard when button is clicked', async () => {
const button = element.shadowRoot?.querySelector('uui-button');
// // Mock the clipboard API
// navigator.clipboard = {
// writeText: async text => {
// expect(text).to.equal('Test Text');
// return Promise.resolve();
// },
// };

button?.click();
});

it('fires copying and copied events', async () => {
const button = element.shadowRoot?.querySelector('uui-button');
// // Mock the clipboard API
// navigator.clipboard = {
// writeText: async text => {
// return Promise.resolve();
// },
// };

let copyingEventFired = false;
let copiedEventFired = false;

element.addEventListener('copying', () => {
copyingEventFired = true;
});

element.addEventListener('copied', () => {
copiedEventFired = true;
});

button?.click();

expect(copyingEventFired).to.be.true;
expect(copiedEventFired).to.be.true;
});
});

0 comments on commit 0901ebe

Please sign in to comment.