mirror of
https://github.com/appwrite/console.git
synced 2026-04-07 19:17:46 +00:00
33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
import { vi } from 'vitest';
|
|
import { expect, test } from 'vitest';
|
|
import { render, fireEvent } from '@testing-library/svelte';
|
|
import { CopyInput } from '../../../src/lib/components';
|
|
|
|
const value = 'This is a test';
|
|
|
|
test('shows CopyInput component', () => {
|
|
const { getByRole } = render(CopyInput, { value });
|
|
const input = document.querySelector('input');
|
|
const button = getByRole('button');
|
|
|
|
expect(input).toBeInTheDocument();
|
|
expect(button).toBeInTheDocument();
|
|
expect(input).toHaveAttribute('type', 'text');
|
|
expect(input).toHaveAttribute('readonly');
|
|
});
|
|
|
|
test('copy to clipboard function called on click', async () => {
|
|
const { getByRole } = render(CopyInput, { value });
|
|
|
|
Object.assign(window.navigator, {
|
|
clipboard: {
|
|
writeText: vi.fn().mockImplementation(() => Promise.resolve())
|
|
}
|
|
});
|
|
|
|
const button = getByRole('button');
|
|
await fireEvent.click(button);
|
|
|
|
expect(window.navigator.clipboard.writeText).toHaveBeenCalledWith('This is a test');
|
|
});
|