This commit upgrades TypeScript to the latest version 5.3 and introduces `verbatimModuleSyntax` in line with the official Vue guide recommendatinos (vuejs/docs#2592). By enforcing `import type` for type-only imports, this commit improves code clarity and supports tooling optimization, ensuring imports are only bundled when necessary for runtime. Changes: - Bump TypeScript to 5.3.3 across the project. - Adjust import statements to utilize `import type` where applicable, promoting cleaner and more efficient code.
75 lines
2.4 KiB
TypeScript
75 lines
2.4 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { BrowserClipboard, type NavigatorClipboard } from '@/presentation/components/Shared/Hooks/Clipboard/BrowserClipboard';
|
|
import { StubWithObservableMethodCalls } from '@tests/unit/shared/Stubs/StubWithObservableMethodCalls';
|
|
import { expectThrowsAsync } from '@tests/shared/Assertions/ExpectThrowsAsync';
|
|
import { expectExists } from '@tests/shared/Assertions/ExpectExists';
|
|
|
|
describe('BrowserClipboard', () => {
|
|
describe('writeText', () => {
|
|
it('calls navigator clipboard with the correct text', async () => {
|
|
// arrange
|
|
const expectedText = 'test text';
|
|
const navigatorClipboard = new NavigatorClipboardStub();
|
|
const clipboard = new BrowserClipboard(navigatorClipboard);
|
|
// act
|
|
await clipboard.copyText(expectedText);
|
|
// assert
|
|
const calls = navigatorClipboard.callHistory;
|
|
expect(calls).to.have.lengthOf(1);
|
|
const call = calls.find((c) => c.methodName === 'writeText');
|
|
expectExists(call);
|
|
const [actualText] = call.args;
|
|
expect(actualText).to.equal(expectedText);
|
|
});
|
|
it('throws when navigator clipboard fails', async () => {
|
|
// arrange
|
|
const expectedError = 'internalError';
|
|
const navigatorClipboard = new NavigatorClipboardStub();
|
|
navigatorClipboard.writeText = () => {
|
|
throw new Error(expectedError);
|
|
};
|
|
const clipboard = new BrowserClipboard(navigatorClipboard);
|
|
// act
|
|
const act = () => clipboard.copyText('unimportant-text');
|
|
// assert
|
|
await expectThrowsAsync(act, expectedError);
|
|
});
|
|
});
|
|
});
|
|
|
|
class NavigatorClipboardStub
|
|
extends StubWithObservableMethodCalls<NavigatorClipboard>
|
|
implements NavigatorClipboard {
|
|
writeText(data: string): Promise<void> {
|
|
this.registerMethodCall({
|
|
methodName: 'writeText',
|
|
args: [data],
|
|
});
|
|
return Promise.resolve();
|
|
}
|
|
|
|
read(): Promise<ClipboardItems> {
|
|
throw new Error('Method not implemented.');
|
|
}
|
|
|
|
readText(): Promise<string> {
|
|
throw new Error('Method not implemented.');
|
|
}
|
|
|
|
write(): Promise<void> {
|
|
throw new Error('Method not implemented.');
|
|
}
|
|
|
|
addEventListener(): void {
|
|
throw new Error('Method not implemented.');
|
|
}
|
|
|
|
dispatchEvent(): boolean {
|
|
throw new Error('Method not implemented.');
|
|
}
|
|
|
|
removeEventListener(): void {
|
|
throw new Error('Method not implemented.');
|
|
}
|
|
}
|