mirror of
https://github.com/appwrite/console.git
synced 2026-04-07 19:17:46 +00:00
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import { expect, test, vi } from 'vitest';
|
|
import { render, fireEvent } from '@testing-library/svelte';
|
|
import Copy from '../../../src/lib/mock/copy.test.svelte';
|
|
|
|
const value = 'This is a test';
|
|
|
|
test('copy to clipboard function called on click', async () => {
|
|
const { getByTestId } = render(Copy, {
|
|
value
|
|
});
|
|
|
|
Object.assign(window.navigator, {
|
|
clipboard: {
|
|
writeText: vi.fn().mockImplementation(() => Promise.resolve())
|
|
}
|
|
});
|
|
|
|
const button = getByTestId('copy-content');
|
|
await fireEvent.click(button);
|
|
|
|
expect(window.navigator.clipboard.writeText).toHaveBeenCalledWith('This is a test');
|
|
});
|
|
|
|
test('copy to clipboard function called on enter', async () => {
|
|
const { getByTestId } = render(Copy, {
|
|
value
|
|
});
|
|
Object.assign(window.navigator, {
|
|
clipboard: {
|
|
writeText: vi.fn().mockImplementation(() => Promise.resolve())
|
|
}
|
|
});
|
|
|
|
const button = getByTestId('copy-content');
|
|
await fireEvent.keyUp(button, {
|
|
key: 'Enter'
|
|
});
|
|
|
|
expect(window.navigator.clipboard.writeText).toHaveBeenCalledWith('This is a test');
|
|
});
|