@vnejs/plugins.platform.android 0.1.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.platform.android",
3
- "version": "0.1.5",
3
+ "version": "0.2.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,7 +18,7 @@
18
18
  "tsconfig.json"
19
19
  ],
20
20
  "scripts": {
21
- "test": "echo \"Error: no test specified\" && exit 1",
21
+ "test": "npx @vnejs/monorepo test",
22
22
  "build": "npx @vnejs/monorepo package",
23
23
  "publish:major:plugin": "npm run publish:major",
24
24
  "publish:minor:plugin": "npm run publish:minor",
@@ -30,15 +30,18 @@
30
30
  "author": "",
31
31
  "license": "ISC",
32
32
  "dependencies": {
33
- "@vnejs/contracts.platform.android": "~0.1.0"
33
+ "@vnejs/contracts.platform.android": "~0.2.0"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "@capacitor/app": "~8.0.0",
37
37
  "@capacitor/splash-screen": "~8.0.0",
38
- "@vnejs/module.core": "~0.1.0",
39
- "@vnejs/shared": "~0.1.0"
38
+ "@vnejs/module.core": "~0.2.0",
39
+ "@vnejs/shared": "~0.2.0"
40
40
  },
41
41
  "devDependencies": {
42
- "@vnejs/configs.ts-common": "~0.1.0"
42
+ "@vnejs/configs.ts-common": "~0.2.0",
43
+ "@vnejs/configs.vitest": "~0.2.0",
44
+ "@vnejs/contracts.core.platforms": "~0.2.0",
45
+ "@vnejs/test-utils": "~0.2.0"
43
46
  }
44
47
  }
@@ -0,0 +1,55 @@
1
+ import { App } from "@capacitor/app";
2
+ import { SplashScreen } from "@capacitor/splash-screen";
3
+ import { beforeEach, describe, expect, it, vi } from "vitest";
4
+
5
+ import { SUBSCRIBE_EVENTS as SYSTEM_EVENTS } from "@vnejs/contracts.core.system";
6
+
7
+ import { Android } from "../modules/android.js";
8
+ import { createAndroidTestModule, PLATFORMS_CONST, registerAndroidPluginVne } from "./setup.js";
9
+
10
+ vi.mock("@capacitor/app", () => ({
11
+ App: { exitApp: vi.fn() },
12
+ }));
13
+
14
+ vi.mock("@capacitor/splash-screen", () => ({
15
+ SplashScreen: { hide: vi.fn() },
16
+ }));
17
+
18
+ describe("Android", () => {
19
+ beforeEach(() => {
20
+ vi.clearAllMocks();
21
+ registerAndroidPluginVne();
22
+ });
23
+
24
+ it("SYSTEM.STARTED hides splash screen on mobile platform", async () => {
25
+ const { module, observer } = createAndroidTestModule(Android);
26
+
27
+ vi.spyOn(module as Android, "waitRender").mockResolvedValue(0);
28
+
29
+ await observer.emit(SYSTEM_EVENTS.STARTED);
30
+
31
+ expect(SplashScreen.hide).toHaveBeenCalledExactlyOnceWith({ fadeOutDuration: 1000 });
32
+ });
33
+
34
+ it("SYSTEM.CLOSE exits the app on mobile platform", async () => {
35
+ const { observer } = createAndroidTestModule(Android);
36
+
37
+ await observer.emit(SYSTEM_EVENTS.CLOSE);
38
+
39
+ expect(App.exitApp).toHaveBeenCalledOnce();
40
+ });
41
+
42
+ it("does not subscribe handlers on non-mobile platform", async () => {
43
+ registerAndroidPluginVne(PLATFORMS_CONST.WEB);
44
+
45
+ const { module, observer } = createAndroidTestModule(Android);
46
+
47
+ vi.spyOn(module as Android, "waitRender").mockResolvedValue(0);
48
+
49
+ await observer.emit(SYSTEM_EVENTS.STARTED);
50
+ await observer.emit(SYSTEM_EVENTS.CLOSE);
51
+
52
+ expect(SplashScreen.hide).not.toHaveBeenCalled();
53
+ expect(App.exitApp).not.toHaveBeenCalled();
54
+ });
55
+ });
@@ -0,0 +1,13 @@
1
+ import { vi } from "vitest";
2
+
3
+ import { CONSTANTS as PLATFORMS_CONST, PARAMS as PLATFORMS_PARAMS, PLUGIN_NAME as PLATFORMS } from "@vnejs/contracts.core.platforms";
4
+ import { PLUGIN_NAME } from "@vnejs/contracts.platform.android";
5
+ import { createTestModule, registerCoreVne, registerVnePlugin } from "@vnejs/test-utils";
6
+
7
+ export const registerAndroidPluginVne = (platform = PLATFORMS_CONST.MOBILE) => {
8
+ registerCoreVne();
9
+ registerVnePlugin(PLATFORMS, { constants: PLATFORMS_CONST, params: { ...PLATFORMS_PARAMS, CURRENT_PLATFORM: platform } });
10
+ registerVnePlugin(PLUGIN_NAME, {});
11
+ };
12
+
13
+ export { createTestModule as createAndroidTestModule, PLUGIN_NAME, PLATFORMS_CONST };
package/tsconfig.json CHANGED
@@ -5,5 +5,5 @@
5
5
  "outDir": "dist"
6
6
  },
7
7
  "include": ["src/**/*.ts"],
8
- "exclude": ["dist", "node_modules"]
8
+ "exclude": ["dist", "node_modules", "src/tests"]
9
9
  }