Files
privacy.sexy/tests/unit/presentation/electron/shared/IpcChannelDefinitions.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

70 lines
2.8 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import type { IpcChannel } from '@/presentation/electron/shared/IpcBridging/IpcChannel';
import { type ChannelDefinitionKey, IpcChannelDefinitions } from '@/presentation/electron/shared/IpcBridging/IpcChannelDefinitions';
describe('IpcChannelDefinitions', () => {
it('defines IPC channels correctly', () => {
const testScenarios: Record<ChannelDefinitionKey, {
readonly expectedNamespace: string;
readonly expectedAccessibleMembers: readonly string[];
}> = {
CodeRunner: {
expectedNamespace: 'code-run',
expectedAccessibleMembers: ['runCode'],
},
Dialog: {
expectedNamespace: 'dialogs',
expectedAccessibleMembers: ['saveFile'],
},
ScriptDiagnosticsCollector: {
expectedNamespace: 'script-diagnostics-collector',
expectedAccessibleMembers: ['collectDiagnosticInformation'],
},
};
Object.entries(testScenarios).forEach((
[definitionKey, { expectedNamespace, expectedAccessibleMembers }],
) => {
describe(`channel: "${definitionKey}"`, () => {
const ipcChannelUnderTest = IpcChannelDefinitions[definitionKey] as IpcChannel<unknown>;
it('has expected namespace', () => {
// act
const actualNamespace = ipcChannelUnderTest.namespace;
// assert
expect(actualNamespace).to.equal(expectedNamespace);
});
it('has expected accessible members', () => {
// act
const actualAccessibleMembers = ipcChannelUnderTest.accessibleMembers;
// assert
expect(actualAccessibleMembers).to.have.lengthOf(expectedAccessibleMembers.length);
expect(actualAccessibleMembers).to.have.members(expectedAccessibleMembers);
});
});
});
});
describe('IPC channel uniqueness', () => {
it('has unique namespaces', () => {
// arrange
const extractedNamespacesFromDefinitions = Object
.values(IpcChannelDefinitions)
.map((channel) => channel.namespace);
// act
const duplicateNamespaceEntries = extractedNamespacesFromDefinitions
.filter((item, index) => extractedNamespacesFromDefinitions.indexOf(item) !== index);
// assert
expect(duplicateNamespaceEntries).to.have.lengthOf(0);
});
it('has unique accessible members within each channel', () => {
Object.values(IpcChannelDefinitions).forEach((channel) => {
// arrange
const accessibleMembersOfChannel = channel.accessibleMembers as string[];
// act
const repeatedAccessibleMembersInChannel = accessibleMembersOfChannel
.filter((item, index) => accessibleMembersOfChannel.indexOf(item) !== index);
// assert
expect(repeatedAccessibleMembersInChannel).to.have.lengthOf(0);
});
});
});
});