mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-10-16 14:32:03 +00:00
WIP
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C) 2026 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* tsconfig.spec.json maps every `@capacitor/*` import to this folder, so this
|
||||
* file replaces `@capacitor/core` in all tests – including the imports made by
|
||||
* real Capacitor plugins (registerPlugin, WebPlugin, CapacitorHttp, …).
|
||||
*
|
||||
* Therefore everything is re-exported from the real package (imported via a
|
||||
* relative path, which bypasses the path mapping) and only `Capacitor` is
|
||||
* replaced by a controllable mock. The local export shadows the one from
|
||||
* `export *`.
|
||||
*/
|
||||
export * from '../../node_modules/@capacitor/core';
|
||||
|
||||
type Platform = 'web' | 'ios' | 'android';
|
||||
|
||||
export class CapacitorMock {
|
||||
private platform: Platform = 'web';
|
||||
|
||||
getPlatform(): Platform {
|
||||
return this.platform;
|
||||
}
|
||||
|
||||
isNativePlatform(): boolean {
|
||||
return this.platform !== 'web';
|
||||
}
|
||||
|
||||
isPluginAvailable(_name: string): boolean {
|
||||
return this.isNativePlatform();
|
||||
}
|
||||
|
||||
convertFileSrc(filePath: string): string {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test helper: simulate running on the given platform.
|
||||
*/
|
||||
setPlatform(platform: Platform): void {
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test helper: back to the default (web), call this in afterEach.
|
||||
*/
|
||||
reset(): void {
|
||||
this.platform = 'web';
|
||||
}
|
||||
}
|
||||
|
||||
export const Capacitor = new CapacitorMock();
|
||||
Reference in New Issue
Block a user