Files
privacy.sexy/tests/unit/infrastructure/Dialog/Electron/ElectronDialog.spec.ts
undergroundwires a721e82a4f Bump TypeScript to 5.3 with verbatimModuleSyntax
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.
2024-02-27 04:20:22 +01:00

105 lines
3.2 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { FileType, type SaveFileOutcome } from '@/presentation/common/Dialog';
import type { ElectronSaveFileDialog } from '@/infrastructure/Dialog/Electron/ElectronSaveFileDialog';
import { ElectronDialog, type ElectronDialogAccessor } from '@/infrastructure/Dialog/Electron/ElectronDialog';
describe('ElectronDialog', () => {
describe('saveFile', () => {
it('forwards arguments', async () => {
// arrange
const expectedSaveFileArgs = createTestSaveFileArguments();
let actualSaveFileArgs: Parameters<ElectronSaveFileDialog['saveFile']> | undefined;
const fileSaverDialogSpy: ElectronSaveFileDialog = {
saveFile: (...args) => {
actualSaveFileArgs = args;
return Promise.resolve({
success: true,
});
},
};
const electronDialog = new ElectronDialogBuilder()
.withSaveFileDialog(fileSaverDialogSpy)
.build();
// act
await electronDialog.saveFile(...expectedSaveFileArgs);
// assert
expect(actualSaveFileArgs).to.deep.equal(expectedSaveFileArgs);
});
it('forwards outcome', async () => {
// arrange
const expectedResult: SaveFileOutcome = {
success: true,
};
const fileSaverDialogMock: ElectronSaveFileDialog = {
saveFile: () => Promise.resolve(expectedResult),
};
const browserDialog = new ElectronDialogBuilder()
.withSaveFileDialog(fileSaverDialogMock)
.build();
// act
const actualResult = await browserDialog.saveFile(...createTestSaveFileArguments());
// assert
expect(actualResult).to.equal(expectedResult);
});
});
describe('showError', () => {
it('forwards arguments', () => {
// arrange
const expectedShowErrorArguments: Parameters<ElectronDialog['showError']> = [
'test title', 'test message',
];
let actualShowErrorArgs: Parameters<ElectronDialogAccessor['showErrorBox']> | undefined;
const electronDialogAccessorSpy: ElectronDialogAccessor = {
showErrorBox: (...args) => {
actualShowErrorArgs = args;
},
};
const electronDialog = new ElectronDialogBuilder()
.withElectron(electronDialogAccessorSpy)
.build();
// act
electronDialog.showError(...expectedShowErrorArguments);
// assert
expect(actualShowErrorArgs).to.deep.equal(expectedShowErrorArguments);
});
});
});
function createTestSaveFileArguments(): Parameters<ElectronSaveFileDialog['saveFile']> {
return [
'test file content',
'test filename',
FileType.ShellScript,
];
}
class ElectronDialogBuilder {
private electron: ElectronDialogAccessor = {
showErrorBox: () => {},
};
private saveFileDialog: ElectronSaveFileDialog = {
saveFile: () => Promise.resolve({ success: true }),
};
public withElectron(electron: ElectronDialogAccessor): this {
this.electron = electron;
return this;
}
public withSaveFileDialog(saveFileDialog: ElectronSaveFileDialog): this {
this.saveFileDialog = saveFileDialog;
return this;
}
public build() {
return new ElectronDialog(this.saveFileDialog, this.electron);
}
}