Files
privacy.sexy/tests/unit/infrastructure/RuntimeEnvironment/Browser/TouchSupportDetection.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

60 lines
2.0 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { type BrowserTouchSupportAccessor, isTouchEnabledDevice } from '@/infrastructure/RuntimeEnvironment/Browser/TouchSupportDetection';
describe('TouchSupportDetection', () => {
describe('isTouchEnabledDevice', () => {
const testScenarios: ReadonlyArray<{
readonly description: string;
readonly accessor: BrowserTouchSupportAccessor;
readonly expectedTouch: boolean;
}> = [
{
description: 'detects no touch capabilities',
accessor: createMockAccessor(),
expectedTouch: false,
},
{
description: 'detects touch capability with defined document.ontouchend',
accessor: createMockAccessor({ documentOntouchend: () => 'not-undefined' }),
expectedTouch: true,
},
{
description: 'detects touch capability with navigator.maxTouchPoints > 0',
accessor: createMockAccessor({ navigatorMaxTouchPoints: () => 1 }),
expectedTouch: true,
},
{
description: 'detects touch capability when matchMedia for pointer coarse is true',
accessor: createMockAccessor({
windowMatchMediaMatches: (query: string) => {
return query === '(any-pointer: coarse)';
},
}),
expectedTouch: true,
},
];
testScenarios.forEach(({ description, accessor, expectedTouch }) => {
it(`${description} - returns ${expectedTouch}`, () => {
// act
const isTouchDetected = isTouchEnabledDevice(accessor);
// assert
expect(isTouchDetected).to.equal(expectedTouch);
});
});
});
});
function createMockAccessor(
touchSupportFeatures: Partial<BrowserTouchSupportAccessor> = {},
): BrowserTouchSupportAccessor {
const defaultTouchSupport: BrowserTouchSupportAccessor = {
navigatorMaxTouchPoints: () => undefined,
windowMatchMediaMatches: () => false,
documentOntouchend: () => undefined,
};
return {
...defaultTouchSupport,
...touchSupportFeatures,
};
}