This commit improves the handling of paths with spaces or special characters during script execution in the desktop application. Key improvements: - Paths are now quoted for macOS/Linux, addressing issues with whitespace or single quotes. - Windows paths are enclosed in double quotes to handle special characters. Other supporting changes: - Add more documentation for terminal execution commands. - Refactor terminal script file execution into a dedicated file for improved separation of concerns. - Refactor naming of `RuntimeEnvironment` to align with naming conventions (no interface with I prefix) and for clarity. - Refactor `TemporaryFileCodeRunner` to simplify it by removing the `os` parameter and handling OS-specific logic within the filename generator instead. - Refactor `fileName` to `filename` for consistency.
67 lines
2.8 KiB
TypeScript
67 lines
2.8 KiB
TypeScript
import { describe, it, afterEach } from 'vitest';
|
|
import { OperatingSystem } from '@/domain/OperatingSystem';
|
|
import { MobileSafariActivePseudoClassEnabler } from '@/presentation/bootstrapping/Modules/MobileSafariActivePseudoClassEnabler';
|
|
import { EventName, createWindowEventSpies } from '@tests/shared/Spies/WindowEventSpies';
|
|
import { formatAssertionMessage } from '@tests/shared/FormatAssertionMessage';
|
|
import { isTouchEnabledDevice } from '@/infrastructure/RuntimeEnvironment/TouchSupportDetection';
|
|
import { HostRuntimeEnvironment } from '@/infrastructure/RuntimeEnvironment/HostRuntimeEnvironment';
|
|
import { MobileSafariDetectionTestCases } from './MobileSafariDetectionTestCases';
|
|
|
|
describe('MobileSafariActivePseudoClassEnabler', () => {
|
|
describe('bootstrap', () => {
|
|
MobileSafariDetectionTestCases.forEach(({
|
|
description, userAgent, supportsTouch, expectedResult,
|
|
}) => {
|
|
it(description, () => {
|
|
// arrange
|
|
const expectedEvent: EventName = 'touchstart';
|
|
patchUserAgent(userAgent, afterEach);
|
|
const { isAddEventCalled, currentListeners } = createWindowEventSpies(afterEach);
|
|
const patchedEnvironment = new ConstructibleRuntimeEnvironment(supportsTouch);
|
|
const sut = new MobileSafariActivePseudoClassEnabler(patchedEnvironment);
|
|
// act
|
|
sut.bootstrap();
|
|
// assert
|
|
const isSet = isAddEventCalled(expectedEvent);
|
|
expect(isSet).to.equal(expectedResult, formatAssertionMessage([
|
|
`Expected result\t\t: ${expectedResult ? 'true (mobile Safari)' : 'false (not mobile Safari)'}`,
|
|
`Actual result\t\t: ${isSet ? 'true (mobile Safari)' : 'false (not mobile Safari)'}`,
|
|
`User agent\t\t: ${navigator.userAgent}`,
|
|
`Touch supported\t\t: ${supportsTouch}`,
|
|
`Current OS\t\t: ${patchedEnvironment.os === undefined ? 'unknown' : OperatingSystem[patchedEnvironment.os]}`,
|
|
`Is desktop?\t\t: ${patchedEnvironment.isDesktop ? 'Yes (Desktop app)' : 'No (Browser)'}`,
|
|
`Listeners (${currentListeners.length})\t\t: ${JSON.stringify(currentListeners)}`,
|
|
]));
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
function patchUserAgent(
|
|
userAgent: string,
|
|
restoreCallback: (restoreFunc: () => void) => void,
|
|
) {
|
|
const originalNavigator = window.navigator;
|
|
const userAgentGetter = { get: () => userAgent };
|
|
window.navigator = Object.create(navigator, {
|
|
userAgent: userAgentGetter,
|
|
});
|
|
restoreCallback(() => {
|
|
Object.assign(window, {
|
|
navigator: originalNavigator,
|
|
});
|
|
});
|
|
}
|
|
|
|
function getTouchDetectorMock(
|
|
isTouchEnabled: boolean,
|
|
): typeof isTouchEnabledDevice {
|
|
return () => isTouchEnabled;
|
|
}
|
|
|
|
class ConstructibleRuntimeEnvironment extends HostRuntimeEnvironment {
|
|
public constructor(isTouchEnabled: boolean) {
|
|
super(window, undefined, undefined, getTouchDetectorMock(isTouchEnabled));
|
|
}
|
|
}
|