This commit introduces native operating system file dialogs in the desktop application replacing the existing web-based dialogs. It lays the foundation for future enhancements such as: - Providing error messages when saving or executing files, addressing #264. - Creating system restore points, addressing #50. Documentation updates: - Update `desktop-vs-web-features.md` with added functionality. - Update `README.md` with security feature highlights. - Update home page documentation to emphasize security features. Other supporting changes include: - Integrate IPC communication channels for secure Electron dialog API interactions. - Refactor `IpcRegistration` for more type-safety and simplicity. - Introduce a Vue hook to encapsulate dialog functionality. - Improve errors during IPC registration for easier troubleshooting. - Move `ClientLoggerFactory` for consistency in hooks organization and remove `LoggerFactory` interface for simplicity. - Add tests for the save file dialog in the browser context. - Add `Blob` polyfill in tests to compensate for the missing `blob.text()` function in `jsdom` (see jsdom/jsdom#2555). Improve environment detection logic: - Treat test environment as browser environments to correctly activate features based on the environment. This resolves issues where the environment is misidentified as desktop, but Electron preloader APIs are missing. - Rename `isDesktop` environment identification variable to `isRunningAsDesktopApplication` for better clarity and to avoid confusion with desktop environments in web/browser/test environments. - Simplify `BrowserRuntimeEnvironment` to consistently detect non-desktop application environments. - Improve environment detection for Electron main process (electron/electron#2288).
67 lines
2.9 KiB
TypeScript
67 lines
2.9 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/Browser/TouchSupportDetection';
|
|
import { BrowserRuntimeEnvironment } from '@/infrastructure/RuntimeEnvironment/Browser/BrowserRuntimeEnvironment';
|
|
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 TouchSupportControlledBrowserEnvironment(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.isRunningAsDesktopApplication ? '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 TouchSupportControlledBrowserEnvironment extends BrowserRuntimeEnvironment {
|
|
public constructor(isTouchEnabled: boolean) {
|
|
super(window, undefined, undefined, getTouchDetectorMock(isTouchEnabled));
|
|
}
|
|
}
|