@flighthq/host-capacitor 0.5.1-next.920.da8f530 → 0.6.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/README.md +3 -3
- package/dist/capacitorApp.d.ts +11 -7
- package/dist/capacitorApp.d.ts.map +1 -1
- package/dist/capacitorApp.js +35 -25
- package/dist/capacitorApp.js.map +1 -1
- package/dist/capacitorClipboard.d.ts +5 -5
- package/dist/capacitorClipboard.d.ts.map +1 -1
- package/dist/capacitorClipboard.js +15 -6
- package/dist/capacitorClipboard.js.map +1 -1
- package/dist/capacitorConnectivity.d.ts +6 -5
- package/dist/capacitorConnectivity.d.ts.map +1 -1
- package/dist/capacitorConnectivity.js +15 -6
- package/dist/capacitorConnectivity.js.map +1 -1
- package/dist/capacitorDefaultHostGroups.d.ts +66 -0
- package/dist/capacitorDefaultHostGroups.d.ts.map +1 -0
- package/dist/capacitorDefaultHostGroups.js +119 -0
- package/dist/capacitorDefaultHostGroups.js.map +1 -0
- package/dist/capacitorDevice.d.ts +3 -3
- package/dist/capacitorDevice.d.ts.map +1 -1
- package/dist/capacitorDevice.js +8 -9
- package/dist/capacitorDevice.js.map +1 -1
- package/dist/capacitorDialog.d.ts +6 -5
- package/dist/capacitorDialog.d.ts.map +1 -1
- package/dist/capacitorDialog.js +16 -11
- package/dist/capacitorDialog.js.map +1 -1
- package/dist/capacitorFileSystem.d.ts +3 -3
- package/dist/capacitorFileSystem.d.ts.map +1 -1
- package/dist/capacitorFileSystem.js +6 -7
- package/dist/capacitorFileSystem.js.map +1 -1
- package/dist/capacitorGeolocation.d.ts +3 -3
- package/dist/capacitorGeolocation.d.ts.map +1 -1
- package/dist/capacitorGeolocation.js +13 -13
- package/dist/capacitorGeolocation.js.map +1 -1
- package/dist/capacitorHaptics.d.ts +3 -3
- package/dist/capacitorHaptics.d.ts.map +1 -1
- package/dist/capacitorHaptics.js +7 -8
- package/dist/capacitorHaptics.js.map +1 -1
- package/dist/capacitorHost.d.ts +4 -0
- package/dist/capacitorHost.d.ts.map +1 -0
- package/dist/capacitorHost.js +71 -0
- package/dist/capacitorHost.js.map +1 -0
- package/dist/capacitorInputHost.d.ts +6 -0
- package/dist/capacitorInputHost.d.ts.map +1 -0
- package/dist/capacitorInputHost.js +20 -0
- package/dist/capacitorInputHost.js.map +1 -0
- package/dist/capacitorKeyboard.d.ts +9 -15
- package/dist/capacitorKeyboard.d.ts.map +1 -1
- package/dist/capacitorKeyboard.js +36 -37
- package/dist/capacitorKeyboard.js.map +1 -1
- package/dist/capacitorNotification.d.ts +9 -3
- package/dist/capacitorNotification.d.ts.map +1 -1
- package/dist/capacitorNotification.js +171 -154
- package/dist/capacitorNotification.js.map +1 -1
- package/dist/capacitorProtocol.d.ts +4 -3
- package/dist/capacitorProtocol.d.ts.map +1 -1
- package/dist/capacitorProtocol.js +6 -9
- package/dist/capacitorProtocol.js.map +1 -1
- package/dist/capacitorShare.d.ts +7 -3
- package/dist/capacitorShare.d.ts.map +1 -1
- package/dist/capacitorShare.js +8 -6
- package/dist/capacitorShare.js.map +1 -1
- package/dist/capacitorStatusBar.d.ts +8 -5
- package/dist/capacitorStatusBar.d.ts.map +1 -1
- package/dist/capacitorStatusBar.js +51 -38
- package/dist/capacitorStatusBar.js.map +1 -1
- package/dist/capacitorStorageHost.d.ts +4 -0
- package/dist/capacitorStorageHost.d.ts.map +1 -0
- package/dist/capacitorStorageHost.js +5 -0
- package/dist/capacitorStorageHost.js.map +1 -0
- package/dist/capacitorSystemHost.d.ts +6 -0
- package/dist/capacitorSystemHost.d.ts.map +1 -0
- package/dist/capacitorSystemHost.js +9 -0
- package/dist/capacitorSystemHost.js.map +1 -0
- package/dist/contract.d.ts +19 -23
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +18 -23
- package/dist/contract.js.map +1 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -1
- package/dist/index.js.map +1 -1
- package/dist/types/CapacitorApi.d.ts +308 -0
- package/dist/types/CapacitorApi.d.ts.map +1 -0
- package/dist/types/CapacitorApi.js +35 -0
- package/dist/types/CapacitorApi.js.map +1 -0
- package/dist/types/CapacitorAppCapabilitiesFor.d.ts +6 -0
- package/dist/types/CapacitorAppCapabilitiesFor.d.ts.map +1 -0
- package/dist/types/CapacitorAppCapabilitiesFor.js +2 -0
- package/dist/types/CapacitorAppCapabilitiesFor.js.map +1 -0
- package/dist/types/CapacitorHost.d.ts +94 -0
- package/dist/types/CapacitorHost.d.ts.map +1 -0
- package/dist/types/CapacitorHost.js +2 -0
- package/dist/types/CapacitorHost.js.map +1 -0
- package/dist/types/CapacitorProtocolCapabilities.d.ts +3 -0
- package/dist/types/CapacitorProtocolCapabilities.d.ts.map +1 -0
- package/dist/types/CapacitorProtocolCapabilities.js +2 -0
- package/dist/types/CapacitorProtocolCapabilities.js.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +5 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +46 -15
- package/src/capacitorApp.test.ts +38 -19
- package/src/capacitorClipboard.test.ts +30 -28
- package/src/capacitorConnectivity.test.ts +34 -23
- package/src/capacitorDefaultHostGroups.test.ts +214 -0
- package/src/capacitorDevice.test.ts +18 -30
- package/src/capacitorDialog.test.ts +13 -33
- package/src/capacitorFileSystem.test.ts +30 -37
- package/src/capacitorGeolocation.test.ts +8 -17
- package/src/capacitorHaptics.test.ts +9 -13
- package/src/{capacitorRegister.test.ts → capacitorHost.test.ts} +91 -48
- package/src/capacitorInputHost.test.ts +33 -0
- package/src/capacitorKeyboard.test.ts +38 -89
- package/src/capacitorNotification.test.ts +54 -18
- package/src/capacitorProtocol.test.ts +10 -11
- package/src/capacitorShare.test.ts +15 -17
- package/src/capacitorStatusBar.test.ts +53 -16
- package/src/capacitorStorageHost.test.ts +10 -0
- package/src/capacitorSystemHost.test.ts +28 -0
- package/dist/capacitorRegister.d.ts +0 -5
- package/dist/capacitorRegister.d.ts.map +0 -1
- package/dist/capacitorRegister.js +0 -81
- package/dist/capacitorRegister.js.map +0 -1
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { readClipboardText } from '@flighthq/clipboard/contract';
|
|
2
|
-
import { EntityRuntimeKey } from '@flighthq/
|
|
3
|
-
import type { CapacitorApi } from '@flighthq/types/contract';
|
|
2
|
+
import { EntityRuntimeKey } from '@flighthq/entity/contract';
|
|
4
3
|
|
|
5
|
-
import { capacitorHost
|
|
4
|
+
import { capacitorHost } from './capacitorHost.ts';
|
|
5
|
+
import type { CapacitorApi } from './types/index.ts';
|
|
6
6
|
|
|
7
|
-
// A fake Capacitor API broad enough that every
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
// routes the seams to the Capacitor backends.
|
|
7
|
+
// A fake Capacitor API broad enough that every provider constructs without touching missing members.
|
|
8
|
+
// Providers close over `capacitor` and only call in when their methods run (plus the app, device,
|
|
9
|
+
// status-bar, and connectivity prefetches), so a thin fake proves composition routes the seams.
|
|
11
10
|
function fakeCapacitor(): CapacitorApi {
|
|
12
11
|
const asyncNoop = async () => {};
|
|
13
12
|
const asyncListener = async () => ({ async remove() {} });
|
|
@@ -62,17 +61,21 @@ describe('capacitor power slot coverage', () => {
|
|
|
62
61
|
// honest and forward-compatible; the named gap lives in agents/upstream-host-requirements.md so an
|
|
63
62
|
// examined absence stays distinguishable from an unexamined one.
|
|
64
63
|
it('claims no power capability at all', () => {
|
|
65
|
-
const host =
|
|
64
|
+
const host = capacitorHost(fakeCapacitor(), 'ios');
|
|
66
65
|
expect(host.power).toEqual({});
|
|
67
66
|
});
|
|
68
67
|
});
|
|
69
68
|
|
|
70
69
|
describe('capacitorHost', () => {
|
|
70
|
+
it('publishes every Host group and no parallel top-level surface', () => {
|
|
71
|
+
expect(Object.keys(capacitorHost(fakeCapacitor(), 'ios')).sort()).toEqual([...HOST_GROUP_NAMES]);
|
|
72
|
+
});
|
|
73
|
+
|
|
71
74
|
it('exposes the real Capacitor haptics provider', () => {
|
|
72
75
|
const host = capacitorHost(fakeCapacitor(), 'ios');
|
|
73
76
|
expect(EntityRuntimeKey in host).toBe(true);
|
|
74
|
-
expect(host.
|
|
75
|
-
expect(typeof host.
|
|
77
|
+
expect(host.haptics.engine).toBeDefined();
|
|
78
|
+
expect(typeof host.haptics.engine?.vibrate).toBe('function');
|
|
76
79
|
});
|
|
77
80
|
|
|
78
81
|
// An empty group means "not yet migrated off its package-local seam", NEVER "Capacitor cannot do
|
|
@@ -89,39 +92,32 @@ describe('capacitorHost', () => {
|
|
|
89
92
|
expect('directoryOpen' in host.dialog).toBe(false);
|
|
90
93
|
expect('fileOpen' in host.dialog).toBe(false);
|
|
91
94
|
expect('fileSave' in host.dialog).toBe(false);
|
|
92
|
-
expect(host.
|
|
95
|
+
expect(host.haptics.engine).toBeDefined();
|
|
93
96
|
expect(host.notification.delivery).toBeDefined();
|
|
94
97
|
expect(host.share.content).toBeDefined();
|
|
95
|
-
expect(host.
|
|
96
|
-
expect(host.
|
|
97
|
-
expect(host.
|
|
98
|
-
expect(host.
|
|
99
|
-
expect(host.
|
|
98
|
+
expect(host.fileSystem.access).toBeDefined();
|
|
99
|
+
expect(host.statusBar.color).toBeDefined();
|
|
100
|
+
expect(host.statusBar.info).toBeDefined();
|
|
101
|
+
expect(host.device.info).toBeDefined();
|
|
102
|
+
expect(host.audio).toEqual({});
|
|
103
|
+
expect(host.video).toEqual({});
|
|
100
104
|
expect(host.shortcut).toEqual({});
|
|
101
105
|
expect(host.updater).toEqual({});
|
|
102
106
|
});
|
|
103
107
|
|
|
104
|
-
//
|
|
105
|
-
//
|
|
106
|
-
// to {}, because the backend is an Entity and carries a runtime slot that is not an operation.
|
|
108
|
+
// A webview app has no native window operations of its own, so the whole window group is absent —
|
|
109
|
+
// an empty struct of capability slots rather than a live capability with inert methods.
|
|
107
110
|
it('claims no native window operations', () => {
|
|
108
|
-
expect(
|
|
111
|
+
expect(capacitorHost(fakeCapacitor(), 'ios').window).toEqual({});
|
|
109
112
|
});
|
|
110
113
|
|
|
111
114
|
it('names Shell as an exact empty capability group', () => {
|
|
112
115
|
const host = capacitorHost(fakeCapacitor(), 'ios');
|
|
113
116
|
expect(host.shell).toEqual({});
|
|
114
117
|
});
|
|
115
|
-
});
|
|
116
118
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
expect(typeof initializeCapacitorHost).toBe('function');
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
describe('registerCapacitorBackends', () => {
|
|
123
|
-
it('installs a backend for each covered capability', () => {
|
|
124
|
-
const host = registerCapacitorBackends(fakeCapacitor(), 'ios');
|
|
119
|
+
it('installs a provider for each covered capability', () => {
|
|
120
|
+
const host = capacitorHost(fakeCapacitor(), 'ios');
|
|
125
121
|
expect(EntityRuntimeKey in host).toBe(true);
|
|
126
122
|
expect(host.dialog.message.confirm).toBeTypeOf('function');
|
|
127
123
|
expect(host.dialog.prompt.prompt).toBeTypeOf('function');
|
|
@@ -131,29 +127,76 @@ describe('registerCapacitorBackends', () => {
|
|
|
131
127
|
expect(host.protocol.open.subscribe).toBeTypeOf('function');
|
|
132
128
|
expect(host.connectivity.status.getStatus).toBeTypeOf('function');
|
|
133
129
|
expect(host.connectivity.change.subscribe).toBeTypeOf('function');
|
|
134
|
-
expect(host.
|
|
135
|
-
expect(host.
|
|
136
|
-
expect(host.
|
|
130
|
+
expect(host.device.info).toBeDefined();
|
|
131
|
+
expect(host.fileSystem.access.readTextFile).toBeTypeOf('function');
|
|
132
|
+
expect(host.geolocation.position).toBeDefined();
|
|
137
133
|
expect(host.notification.delivery.notify).toBeTypeOf('function');
|
|
138
134
|
expect(host.notification.scheduling.scheduleNotification).toBeTypeOf('function');
|
|
139
135
|
expect(host.share.content.canShareContent({ text: 'ready' })).toBe(true);
|
|
140
|
-
expect(host.
|
|
141
|
-
expect(host.
|
|
142
|
-
expect(host.
|
|
143
|
-
expect(host.
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
// Haptics has migrated off the ambient seam: registerCapacitorBackends now RETURNS a Host carrying the
|
|
147
|
-
// real Capacitor provider, so the capability is proven by what the host exposes rather than by what a
|
|
148
|
-
// module-scoped variable happens to hold.
|
|
149
|
-
it('returns a host exposing the real Capacitor haptics capability', () => {
|
|
150
|
-
const host = registerCapacitorBackends(fakeCapacitor(), 'ios');
|
|
151
|
-
expect(host.input.haptics).toBeDefined();
|
|
152
|
-
expect(typeof host.input.haptics?.vibrate).toBe('function');
|
|
136
|
+
expect(host.softKeyboard.info).toBeDefined();
|
|
137
|
+
expect(host.softKeyboard.visibility).toBeDefined();
|
|
138
|
+
expect(host.statusBar.color.setBackgroundColor).toBeTypeOf('function');
|
|
139
|
+
expect(host.statusBar.info.getInfo).toBeTypeOf('function');
|
|
153
140
|
});
|
|
154
141
|
|
|
155
|
-
it('routes a capability call through to the Capacitor
|
|
156
|
-
const host =
|
|
157
|
-
expect(await readClipboardText(host)).toBe('CAP-TEXT');
|
|
142
|
+
it('routes a capability call through to the Capacitor provider', async () => {
|
|
143
|
+
const host = capacitorHost(fakeCapacitor(), 'ios');
|
|
144
|
+
expect(await readClipboardText(host.clipboard.text)).toBe('CAP-TEXT');
|
|
158
145
|
});
|
|
159
146
|
});
|
|
147
|
+
|
|
148
|
+
// The capability groups every provider host carries (D26: each provider declares its own; there is no
|
|
149
|
+
// aggregate Host to read them from).
|
|
150
|
+
const HOST_GROUP_NAMES = [
|
|
151
|
+
'accessibility',
|
|
152
|
+
'app',
|
|
153
|
+
'audio',
|
|
154
|
+
'audioDecode',
|
|
155
|
+
'bitmap',
|
|
156
|
+
'canvas',
|
|
157
|
+
'clipboard',
|
|
158
|
+
'compress',
|
|
159
|
+
'connectivity',
|
|
160
|
+
'decompress',
|
|
161
|
+
'device',
|
|
162
|
+
'dialog',
|
|
163
|
+
'fileSystem',
|
|
164
|
+
'font',
|
|
165
|
+
'fullscreen',
|
|
166
|
+
'geolocation',
|
|
167
|
+
'gl',
|
|
168
|
+
'glyph',
|
|
169
|
+
'haptics',
|
|
170
|
+
'image',
|
|
171
|
+
'imageDecode',
|
|
172
|
+
'imageEncode',
|
|
173
|
+
'input',
|
|
174
|
+
'ipc',
|
|
175
|
+
'lifecycle',
|
|
176
|
+
'mediaSession',
|
|
177
|
+
'menu',
|
|
178
|
+
'midi',
|
|
179
|
+
'net',
|
|
180
|
+
'notification',
|
|
181
|
+
'permissions',
|
|
182
|
+
'platform',
|
|
183
|
+
'power',
|
|
184
|
+
'preferences',
|
|
185
|
+
'protocol',
|
|
186
|
+
'screen',
|
|
187
|
+
'sensors',
|
|
188
|
+
'share',
|
|
189
|
+
'shell',
|
|
190
|
+
'shortcut',
|
|
191
|
+
'socket',
|
|
192
|
+
'softKeyboard',
|
|
193
|
+
'statusBar',
|
|
194
|
+
'surface',
|
|
195
|
+
'textSegment',
|
|
196
|
+
'textShaper',
|
|
197
|
+
'tray',
|
|
198
|
+
'updater',
|
|
199
|
+
'video',
|
|
200
|
+
'wgpu',
|
|
201
|
+
'window',
|
|
202
|
+
];
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { capacitorHostHapticsGroup, capacitorHostSoftKeyboardGroup } from './capacitorInputHost.ts';
|
|
2
|
+
import type { CapacitorApi } from './types/index.ts';
|
|
3
|
+
|
|
4
|
+
function fakeCapacitor(): CapacitorApi {
|
|
5
|
+
return {
|
|
6
|
+
haptics: {},
|
|
7
|
+
keyboard: {
|
|
8
|
+
addListener: async () => ({ async remove() {} }),
|
|
9
|
+
},
|
|
10
|
+
} as unknown as CapacitorApi;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
describe('capacitorHostHapticsGroup', () => {
|
|
14
|
+
it('publishes the Entity-backed haptics engine slot', () => {
|
|
15
|
+
const haptics = capacitorHostHapticsGroup(fakeCapacitor());
|
|
16
|
+
expect(Object.keys(haptics)).toEqual(['engine']);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('capacitorHostSoftKeyboardGroup', () => {
|
|
21
|
+
it('publishes the exact mobile soft-keyboard profile as Entity-backed providers', () => {
|
|
22
|
+
const softKeyboard = capacitorHostSoftKeyboardGroup(fakeCapacitor());
|
|
23
|
+
expect(Object.keys(softKeyboard).sort()).toEqual([
|
|
24
|
+
'accessoryBar',
|
|
25
|
+
'change',
|
|
26
|
+
'info',
|
|
27
|
+
'resizeModeWrite',
|
|
28
|
+
'scrollAssist',
|
|
29
|
+
'style',
|
|
30
|
+
'visibility',
|
|
31
|
+
]);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { EntityRuntimeKey } from '@flighthq/entity/contract';
|
|
2
|
+
import { SoftKeyboardResizeBodyKind } from '@flighthq/keyboard/contract';
|
|
3
|
+
import type { SoftKeyboardInfo } from '@flighthq/keyboard/contract';
|
|
3
4
|
|
|
4
5
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
initializeCapacitorSoftKeyboardInfoBackend,
|
|
15
|
-
initializeCapacitorSoftKeyboardResizeModeWriteBackend,
|
|
16
|
-
initializeCapacitorSoftKeyboardScrollAssistBackend,
|
|
17
|
-
initializeCapacitorSoftKeyboardStyleBackend,
|
|
18
|
-
initializeCapacitorSoftKeyboardVisibilityBackend,
|
|
19
|
-
} from './capacitorKeyboard';
|
|
6
|
+
capacitorHostSoftKeyboardAccessoryBar,
|
|
7
|
+
capacitorHostSoftKeyboardChange,
|
|
8
|
+
capacitorHostSoftKeyboardInfo,
|
|
9
|
+
capacitorHostSoftKeyboardResizeModeWrite,
|
|
10
|
+
capacitorHostSoftKeyboardScrollAssist,
|
|
11
|
+
capacitorHostSoftKeyboardStyle,
|
|
12
|
+
capacitorHostSoftKeyboardVisibility,
|
|
13
|
+
} from './capacitorKeyboard.ts';
|
|
14
|
+
import type { CapacitorApi } from './types/index.ts';
|
|
20
15
|
|
|
21
16
|
function fakeCapacitor() {
|
|
22
17
|
const calls: Array<{ method: string; arg?: unknown }> = [];
|
|
@@ -57,14 +52,10 @@ function blankInfo(): SoftKeyboardInfo {
|
|
|
57
52
|
return { visible: false, height: 0, x: 0, y: 0, width: 0 };
|
|
58
53
|
}
|
|
59
54
|
|
|
60
|
-
describe('
|
|
61
|
-
it('returns an Entity', () => {
|
|
62
|
-
expect(EntityRuntimeKey in createCapacitorSoftKeyboardAccessoryBarBackend(fakeCapacitor().capacitor)).toBe(true);
|
|
63
|
-
});
|
|
64
|
-
|
|
55
|
+
describe('capacitorHostSoftKeyboardAccessoryBar', () => {
|
|
65
56
|
it('returns ok on success', async () => {
|
|
66
57
|
const { capacitor, calls } = fakeCapacitor();
|
|
67
|
-
const backend =
|
|
58
|
+
const backend = capacitorHostSoftKeyboardAccessoryBar(capacitor);
|
|
68
59
|
expect(await backend.setAccessoryBarVisible(true)).toBe('ok');
|
|
69
60
|
expect(calls[0].arg).toEqual({ isVisible: true });
|
|
70
61
|
});
|
|
@@ -80,16 +71,16 @@ describe('createCapacitorSoftKeyboardAccessoryBarBackend', () => {
|
|
|
80
71
|
},
|
|
81
72
|
},
|
|
82
73
|
} as unknown as CapacitorApi;
|
|
83
|
-
expect(await
|
|
74
|
+
expect(await capacitorHostSoftKeyboardAccessoryBar(failCapacitor).setAccessoryBarVisible(true)).toBe(
|
|
84
75
|
'operation-failed',
|
|
85
76
|
);
|
|
86
77
|
});
|
|
87
78
|
});
|
|
88
79
|
|
|
89
|
-
describe('
|
|
80
|
+
describe('capacitorHostSoftKeyboardChange', () => {
|
|
90
81
|
it('subscribe returns ok with unsubscribe and fires on will events', async () => {
|
|
91
82
|
const { capacitor, fire } = fakeCapacitor();
|
|
92
|
-
const backend =
|
|
83
|
+
const backend = capacitorHostSoftKeyboardChange(capacitor);
|
|
93
84
|
let fires = 0;
|
|
94
85
|
const subscription = await backend.subscribe(() => fires++);
|
|
95
86
|
expect(subscription.result).toBe('ok');
|
|
@@ -108,34 +99,33 @@ describe('createCapacitorSoftKeyboardChangeBackend', () => {
|
|
|
108
99
|
},
|
|
109
100
|
},
|
|
110
101
|
} as unknown as CapacitorApi;
|
|
111
|
-
const subscription = await
|
|
102
|
+
const subscription = await capacitorHostSoftKeyboardChange(failCapacitor).subscribe(() => {});
|
|
112
103
|
expect(subscription.result).toBe('acquisition-failed');
|
|
113
104
|
expect(subscription.unsubscribe).toBeNull();
|
|
114
105
|
});
|
|
115
106
|
});
|
|
116
107
|
|
|
117
|
-
describe('
|
|
118
|
-
it('returns an Entity', () => {
|
|
119
|
-
expect(EntityRuntimeKey in createCapacitorSoftKeyboardInfoBackend(fakeCapacitor().capacitor)).toBe(true);
|
|
120
|
-
});
|
|
121
|
-
|
|
108
|
+
describe('capacitorHostSoftKeyboardInfo', () => {
|
|
122
109
|
it('tracks the keyboard mirror from will-show/will-hide events', async () => {
|
|
123
110
|
const { capacitor, fire } = fakeCapacitor();
|
|
124
|
-
const backend =
|
|
111
|
+
const backend = capacitorHostSoftKeyboardInfo(capacitor);
|
|
125
112
|
await Promise.resolve();
|
|
126
113
|
fire('keyboardWillShow', { keyboardHeight: 320 });
|
|
127
|
-
const shown =
|
|
114
|
+
const shown = blankInfo();
|
|
115
|
+
backend.getInfo(shown);
|
|
128
116
|
expect(shown.visible).toBe(true);
|
|
129
117
|
expect(shown.height).toBe(320);
|
|
130
118
|
fire('keyboardWillHide');
|
|
131
|
-
|
|
119
|
+
const hidden = blankInfo();
|
|
120
|
+
backend.getInfo(hidden);
|
|
121
|
+
expect(hidden.visible).toBe(false);
|
|
132
122
|
});
|
|
133
123
|
});
|
|
134
124
|
|
|
135
|
-
describe('
|
|
125
|
+
describe('capacitorHostSoftKeyboardResizeModeWrite', () => {
|
|
136
126
|
it('returns ok on success and maps the mode', async () => {
|
|
137
127
|
const { capacitor, calls } = fakeCapacitor();
|
|
138
|
-
const backend =
|
|
128
|
+
const backend = capacitorHostSoftKeyboardResizeModeWrite(capacitor);
|
|
139
129
|
expect(await backend.setResizeMode(SoftKeyboardResizeBodyKind)).toBe('ok');
|
|
140
130
|
expect(calls[0].arg).toEqual({ mode: 'body' });
|
|
141
131
|
});
|
|
@@ -151,16 +141,16 @@ describe('createCapacitorSoftKeyboardResizeModeWriteBackend', () => {
|
|
|
151
141
|
},
|
|
152
142
|
},
|
|
153
143
|
} as unknown as CapacitorApi;
|
|
154
|
-
expect(await
|
|
144
|
+
expect(await capacitorHostSoftKeyboardResizeModeWrite(failCapacitor).setResizeMode('None')).toBe(
|
|
155
145
|
'operation-failed',
|
|
156
146
|
);
|
|
157
147
|
});
|
|
158
148
|
});
|
|
159
149
|
|
|
160
|
-
describe('
|
|
150
|
+
describe('capacitorHostSoftKeyboardScrollAssist', () => {
|
|
161
151
|
it('returns ok on success', async () => {
|
|
162
152
|
const { capacitor, calls } = fakeCapacitor();
|
|
163
|
-
const backend =
|
|
153
|
+
const backend = capacitorHostSoftKeyboardScrollAssist(capacitor);
|
|
164
154
|
expect(await backend.setScrollAssistEnabled(false)).toBe('ok');
|
|
165
155
|
expect(calls[0].arg).toEqual({ isDisabled: true });
|
|
166
156
|
});
|
|
@@ -176,16 +166,16 @@ describe('createCapacitorSoftKeyboardScrollAssistBackend', () => {
|
|
|
176
166
|
},
|
|
177
167
|
},
|
|
178
168
|
} as unknown as CapacitorApi;
|
|
179
|
-
expect(await
|
|
169
|
+
expect(await capacitorHostSoftKeyboardScrollAssist(failCapacitor).setScrollAssistEnabled(true)).toBe(
|
|
180
170
|
'operation-failed',
|
|
181
171
|
);
|
|
182
172
|
});
|
|
183
173
|
});
|
|
184
174
|
|
|
185
|
-
describe('
|
|
175
|
+
describe('capacitorHostSoftKeyboardStyle', () => {
|
|
186
176
|
it('returns ok on success', async () => {
|
|
187
177
|
const { capacitor, calls } = fakeCapacitor();
|
|
188
|
-
const backend =
|
|
178
|
+
const backend = capacitorHostSoftKeyboardStyle(capacitor);
|
|
189
179
|
expect(await backend.setStyle('Dark')).toBe('ok');
|
|
190
180
|
expect(calls[0].arg).toEqual({ style: 'DARK' });
|
|
191
181
|
});
|
|
@@ -201,14 +191,14 @@ describe('createCapacitorSoftKeyboardStyleBackend', () => {
|
|
|
201
191
|
},
|
|
202
192
|
},
|
|
203
193
|
} as unknown as CapacitorApi;
|
|
204
|
-
expect(await
|
|
194
|
+
expect(await capacitorHostSoftKeyboardStyle(failCapacitor).setStyle('Dark')).toBe('operation-failed');
|
|
205
195
|
});
|
|
206
196
|
});
|
|
207
197
|
|
|
208
|
-
describe('
|
|
198
|
+
describe('capacitorHostSoftKeyboardVisibility', () => {
|
|
209
199
|
it('returns ok when show/hide succeed', async () => {
|
|
210
200
|
const { capacitor, calls } = fakeCapacitor();
|
|
211
|
-
const backend =
|
|
201
|
+
const backend = capacitorHostSoftKeyboardVisibility(capacitor);
|
|
212
202
|
expect(await backend.show()).toBe('ok');
|
|
213
203
|
expect(await backend.hide()).toBe('ok');
|
|
214
204
|
expect(calls.map((c) => c.method)).toEqual(['show', 'hide']);
|
|
@@ -226,7 +216,7 @@ describe('createCapacitorSoftKeyboardVisibilityBackend', () => {
|
|
|
226
216
|
},
|
|
227
217
|
},
|
|
228
218
|
} as unknown as CapacitorApi;
|
|
229
|
-
expect(await
|
|
219
|
+
expect(await capacitorHostSoftKeyboardVisibility(failCapacitor).show()).toBe('operation-failed');
|
|
230
220
|
});
|
|
231
221
|
|
|
232
222
|
it('returns operation-failed when hide rejects', async () => {
|
|
@@ -241,47 +231,6 @@ describe('createCapacitorSoftKeyboardVisibilityBackend', () => {
|
|
|
241
231
|
},
|
|
242
232
|
},
|
|
243
233
|
} as unknown as CapacitorApi;
|
|
244
|
-
expect(await
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
describe('initializeCapacitorSoftKeyboardAccessoryBarBackend', () => {
|
|
248
|
-
it('is the construction initializer of createCapacitorSoftKeyboardAccessoryBarBackend', () => {
|
|
249
|
-
expect(typeof initializeCapacitorSoftKeyboardAccessoryBarBackend).toBe('function');
|
|
250
|
-
});
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
describe('initializeCapacitorSoftKeyboardChangeBackend', () => {
|
|
254
|
-
it('is the construction initializer of createCapacitorSoftKeyboardChangeBackend', () => {
|
|
255
|
-
expect(typeof initializeCapacitorSoftKeyboardChangeBackend).toBe('function');
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
describe('initializeCapacitorSoftKeyboardInfoBackend', () => {
|
|
260
|
-
it('is the construction initializer of createCapacitorSoftKeyboardInfoBackend', () => {
|
|
261
|
-
expect(typeof initializeCapacitorSoftKeyboardInfoBackend).toBe('function');
|
|
262
|
-
});
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
describe('initializeCapacitorSoftKeyboardResizeModeWriteBackend', () => {
|
|
266
|
-
it('is the construction initializer of createCapacitorSoftKeyboardResizeModeWriteBackend', () => {
|
|
267
|
-
expect(typeof initializeCapacitorSoftKeyboardResizeModeWriteBackend).toBe('function');
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
describe('initializeCapacitorSoftKeyboardScrollAssistBackend', () => {
|
|
272
|
-
it('is the construction initializer of createCapacitorSoftKeyboardScrollAssistBackend', () => {
|
|
273
|
-
expect(typeof initializeCapacitorSoftKeyboardScrollAssistBackend).toBe('function');
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
describe('initializeCapacitorSoftKeyboardStyleBackend', () => {
|
|
278
|
-
it('is the construction initializer of createCapacitorSoftKeyboardStyleBackend', () => {
|
|
279
|
-
expect(typeof initializeCapacitorSoftKeyboardStyleBackend).toBe('function');
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
describe('initializeCapacitorSoftKeyboardVisibilityBackend', () => {
|
|
284
|
-
it('is the construction initializer of createCapacitorSoftKeyboardVisibilityBackend', () => {
|
|
285
|
-
expect(typeof initializeCapacitorSoftKeyboardVisibilityBackend).toBe('function');
|
|
234
|
+
expect(await capacitorHostSoftKeyboardVisibility(failCapacitor).hide()).toBe('operation-failed');
|
|
286
235
|
});
|
|
287
236
|
});
|
|
@@ -1,15 +1,20 @@
|
|
|
1
|
+
import { EntityRuntimeKey } from '@flighthq/entity/contract';
|
|
1
2
|
import { cancelScheduledNotification } from '@flighthq/notification/contract';
|
|
2
|
-
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
capacitorHostNotification,
|
|
6
|
+
capacitorHostNotificationAction,
|
|
7
|
+
capacitorHostNotificationClick,
|
|
8
|
+
capacitorHostNotificationDelivery,
|
|
9
|
+
capacitorHostNotificationLifecycle,
|
|
10
|
+
capacitorHostNotificationPermission,
|
|
11
|
+
capacitorHostNotificationScheduling,
|
|
12
|
+
} from './capacitorNotification.ts';
|
|
3
13
|
import type {
|
|
4
14
|
CapacitorApi,
|
|
5
15
|
CapacitorLocalNotificationAction,
|
|
6
16
|
CapacitorLocalNotificationSchema,
|
|
7
|
-
} from '
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
createCapacitorNotificationCapabilities,
|
|
11
|
-
initializeCapacitorNotificationCapabilities,
|
|
12
|
-
} from './capacitorNotification';
|
|
17
|
+
} from './types/index.ts';
|
|
13
18
|
|
|
14
19
|
function fakeCapacitor(display = 'granted') {
|
|
15
20
|
const scheduled: CapacitorLocalNotificationSchema[] = [];
|
|
@@ -60,10 +65,10 @@ function fakeCapacitor(display = 'granted') {
|
|
|
60
65
|
};
|
|
61
66
|
}
|
|
62
67
|
|
|
63
|
-
describe('
|
|
68
|
+
describe('capacitorHostNotification', () => {
|
|
64
69
|
it('constructs the exact Android/iOS common profile', () => {
|
|
65
|
-
const capabilities =
|
|
66
|
-
expect(EntityRuntimeKey in capabilities).toBe(
|
|
70
|
+
const capabilities = capacitorHostNotification(fakeCapacitor().capacitor);
|
|
71
|
+
expect(EntityRuntimeKey in capabilities).toBe(false);
|
|
67
72
|
expect(Object.keys(capabilities).sort()).toEqual([
|
|
68
73
|
'action',
|
|
69
74
|
'click',
|
|
@@ -76,7 +81,7 @@ describe('createCapacitorNotificationCapabilities', () => {
|
|
|
76
81
|
|
|
77
82
|
it('validates profile fields and native acquisition ids before publishing', async () => {
|
|
78
83
|
const fixture = fakeCapacitor();
|
|
79
|
-
const capabilities =
|
|
84
|
+
const capabilities = capacitorHostNotification(fixture.capacitor);
|
|
80
85
|
await expect(capabilities.delivery.notify({ icon: 'icon.png', title: 'No' })).resolves.toEqual({
|
|
81
86
|
fields: ['icon'],
|
|
82
87
|
reason: 'invalid-request',
|
|
@@ -89,7 +94,7 @@ describe('createCapacitorNotificationCapabilities', () => {
|
|
|
89
94
|
|
|
90
95
|
it('keeps duplicate public ids as distinct private native resources', async () => {
|
|
91
96
|
const fixture = fakeCapacitor();
|
|
92
|
-
const capabilities =
|
|
97
|
+
const capabilities = capacitorHostNotification(fixture.capacitor);
|
|
93
98
|
const first = await capabilities.scheduling.scheduleNotification({ id: 'same', title: 'First' }, { at: 1 });
|
|
94
99
|
const second = await capabilities.scheduling.scheduleNotification({ id: 'same', title: 'Second' }, { at: 2 });
|
|
95
100
|
if (first.reason !== 'scheduled' || second.reason !== 'scheduled') throw new Error('fixture schedule failed');
|
|
@@ -100,7 +105,7 @@ describe('createCapacitorNotificationCapabilities', () => {
|
|
|
100
105
|
|
|
101
106
|
it('reconciles repeated pending enumeration to stable Entity identity', async () => {
|
|
102
107
|
const fixture = fakeCapacitor();
|
|
103
|
-
const capabilities =
|
|
108
|
+
const capabilities = capacitorHostNotification(fixture.capacitor);
|
|
104
109
|
const scheduled = await capabilities.scheduling.scheduleNotification({ id: 'later', title: 'Later' }, { at: 1 });
|
|
105
110
|
if (scheduled.reason !== 'scheduled') throw new Error('fixture schedule failed');
|
|
106
111
|
const first = await capabilities.scheduling.getPendingNotifications();
|
|
@@ -118,7 +123,7 @@ describe('createCapacitorNotificationCapabilities', () => {
|
|
|
118
123
|
fixture.localNotifications.getPending = async () => {
|
|
119
124
|
throw new Error('failed');
|
|
120
125
|
};
|
|
121
|
-
const capabilities =
|
|
126
|
+
const capabilities = capacitorHostNotification(fixture.capacitor);
|
|
122
127
|
await expect(capabilities.permission.getPermission()).resolves.toEqual({
|
|
123
128
|
reason: 'operation-failed',
|
|
124
129
|
});
|
|
@@ -127,7 +132,7 @@ describe('createCapacitorNotificationCapabilities', () => {
|
|
|
127
132
|
|
|
128
133
|
it('acquires independent click/action resources and releases their native handles', async () => {
|
|
129
134
|
const fixture = fakeCapacitor();
|
|
130
|
-
const capabilities =
|
|
135
|
+
const capabilities = capacitorHostNotification(fixture.capacitor);
|
|
131
136
|
const seen: string[] = [];
|
|
132
137
|
const click = await capabilities.click.attach((notification) => seen.push(`click:${notification.id}`));
|
|
133
138
|
const action = await capabilities.action.attach((notification, actionId) =>
|
|
@@ -141,8 +146,39 @@ describe('createCapacitorNotificationCapabilities', () => {
|
|
|
141
146
|
expect(seen).toHaveLength(2);
|
|
142
147
|
});
|
|
143
148
|
});
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
149
|
+
|
|
150
|
+
describe('capacitorHostNotificationAction', () => {
|
|
151
|
+
it('constructs the action provider', () => {
|
|
152
|
+
expect(capacitorHostNotificationAction(fakeCapacitor().capacitor).attach).toBeTypeOf('function');
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
describe('capacitorHostNotificationClick', () => {
|
|
157
|
+
it('constructs the click provider', () => {
|
|
158
|
+
expect(capacitorHostNotificationClick(fakeCapacitor().capacitor).attach).toBeTypeOf('function');
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
describe('capacitorHostNotificationDelivery', () => {
|
|
163
|
+
it('constructs the delivery provider', () => {
|
|
164
|
+
expect(capacitorHostNotificationDelivery(fakeCapacitor().capacitor).notify).toBeTypeOf('function');
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
describe('capacitorHostNotificationLifecycle', () => {
|
|
169
|
+
it('constructs the lifecycle provider', () => {
|
|
170
|
+
expect(capacitorHostNotificationLifecycle(fakeCapacitor().capacitor).destroy).toBeTypeOf('function');
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
describe('capacitorHostNotificationPermission', () => {
|
|
175
|
+
it('constructs the permission provider', () => {
|
|
176
|
+
expect(capacitorHostNotificationPermission(fakeCapacitor().capacitor).getPermission).toBeTypeOf('function');
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
describe('capacitorHostNotificationScheduling', () => {
|
|
181
|
+
it('constructs the scheduling provider', () => {
|
|
182
|
+
expect(capacitorHostNotificationScheduling(fakeCapacitor().capacitor).scheduleNotification).toBeTypeOf('function');
|
|
147
183
|
});
|
|
148
184
|
});
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import type { CapacitorApi } from '@flighthq/types/contract';
|
|
2
|
-
import { EntityRuntimeKey } from '@flighthq/types/contract';
|
|
3
1
|
import { describe, expect, it } from 'vitest';
|
|
4
2
|
|
|
5
|
-
import {
|
|
3
|
+
import { capacitorHostProtocol, capacitorHostProtocolOpen } from './capacitorProtocol.ts';
|
|
4
|
+
import type { CapacitorApi } from './types/index.ts';
|
|
6
5
|
|
|
7
6
|
const flush = async () => {
|
|
8
7
|
await Promise.resolve();
|
|
9
8
|
await Promise.resolve();
|
|
10
9
|
};
|
|
11
10
|
|
|
12
|
-
describe('
|
|
13
|
-
it('publishes only a live-open
|
|
11
|
+
describe('capacitorHostProtocol', () => {
|
|
12
|
+
it('publishes only a live-open slot and adapts appUrlOpen', async () => {
|
|
14
13
|
let listener: ((event: { url: string }) => void) | undefined;
|
|
15
14
|
let removed = 0;
|
|
16
15
|
const capacitor = {
|
|
@@ -25,10 +24,8 @@ describe('createCapacitorProtocolCapabilities', () => {
|
|
|
25
24
|
},
|
|
26
25
|
},
|
|
27
26
|
} as unknown as CapacitorApi;
|
|
28
|
-
const protocol =
|
|
29
|
-
expect(EntityRuntimeKey in protocol).toBe(true);
|
|
27
|
+
const protocol = capacitorHostProtocol(capacitor);
|
|
30
28
|
expect(Object.keys(protocol)).toEqual(['open']);
|
|
31
|
-
expect(EntityRuntimeKey in protocol.open).toBe(true);
|
|
32
29
|
let url = '';
|
|
33
30
|
const off = protocol.open.subscribe((next) => (url = next));
|
|
34
31
|
await flush();
|
|
@@ -39,8 +36,10 @@ describe('createCapacitorProtocolCapabilities', () => {
|
|
|
39
36
|
expect(removed).toBe(1);
|
|
40
37
|
});
|
|
41
38
|
});
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
|
|
40
|
+
describe('capacitorHostProtocolOpen', () => {
|
|
41
|
+
it('constructs the open provider', () => {
|
|
42
|
+
const capacitor = { app: { addListener: async () => ({ async remove() {} }) } } as unknown as CapacitorApi;
|
|
43
|
+
expect(capacitorHostProtocolOpen(capacitor)).toBeDefined();
|
|
45
44
|
});
|
|
46
45
|
});
|