@linxin666/dsh-pet 0.4.10 → 0.4.12
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.i18n.yaml +2 -2
- package/README.md +1 -1
- package/README.zh.md +4 -4
- package/lib/client.js +1137 -352
- package/lib/client.js.map +1 -1
- package/lib/index.js +32 -0
- package/lib/types/client/PetPreview.d.ts +12 -0
- package/lib/types/client/PetPreview.d.ts.map +1 -0
- package/lib/types/client/PetPreview.js +32 -0
- package/lib/types/client/PetSettingsCard.d.ts +46 -3
- package/lib/types/client/PetSettingsCard.d.ts.map +1 -1
- package/lib/types/client/PetSettingsCard.js +96 -11
- package/lib/types/client/PluginSettingsCard.d.ts +131 -17
- package/lib/types/client/PluginSettingsCard.d.ts.map +1 -1
- package/lib/types/client/PluginSettingsCard.js +158 -37
- package/lib/types/client/RangeBubble.d.ts +47 -0
- package/lib/types/client/RangeBubble.d.ts.map +1 -0
- package/lib/types/client/RangeBubble.js +107 -0
- package/lib/types/client/SegmentGroup.d.ts +29 -0
- package/lib/types/client/SegmentGroup.d.ts.map +1 -0
- package/lib/types/client/SegmentGroup.js +81 -0
- package/lib/types/client/index.d.ts.map +1 -1
- package/lib/types/client/index.js +9 -28
- package/lib/types/client/locales.d.ts +36 -44
- package/lib/types/client/locales.d.ts.map +1 -1
- package/lib/types/client/locales.js +36 -44
- package/lib/types/client/settings-form.d.ts +79 -41
- package/lib/types/client/settings-form.d.ts.map +1 -1
- package/lib/types/client/settings-form.js +96 -36
- package/lib/types/client/settings-registration.d.ts +15 -0
- package/lib/types/client/settings-registration.d.ts.map +1 -0
- package/lib/types/client/settings-registration.js +24 -0
- package/lib/types/client/web-extension-contract.d.ts +32 -0
- package/lib/types/client/web-extension-contract.d.ts.map +1 -0
- package/lib/types/client/web-extension-contract.js +6 -0
- package/lib/types/client/web-extension-page.d.ts +51 -0
- package/lib/types/client/web-extension-page.d.ts.map +1 -0
- package/lib/types/client/web-extension-page.js +122 -0
- package/lib/types/registry.d.ts.map +1 -1
- package/lib/types/registry.js +35 -0
- package/package.json +1 -1
- package/src/client/PetPreview.tsx +51 -0
- package/src/client/PetSettingsCard.test.tsx +78 -22
- package/src/client/PetSettingsCard.tsx +252 -115
- package/src/client/PluginSettingsCard.tsx +369 -108
- package/src/client/RangeBubble.tsx +163 -0
- package/src/client/SegmentGroup.tsx +92 -0
- package/src/client/index.ts +9 -27
- package/src/client/locales.ts +36 -44
- package/src/client/settings-card.module.css +493 -91
- package/src/client/settings-form.ts +116 -49
- package/src/client/settings-registration.test.ts +79 -0
- package/src/client/settings-registration.ts +34 -0
- package/src/client/settings-section.module.css +182 -0
- package/src/client/web-extension-contract.ts +35 -0
- package/src/client/web-extension-page.ts +150 -0
- package/src/registry.test.ts +121 -1
- package/src/registry.ts +37 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One settings page's seat in either the Web Extensions parent or the legacy
|
|
3
|
+
* first-level settings navigation.
|
|
4
|
+
*
|
|
5
|
+
* The parent supplies the page contract; a child does not know which slot the
|
|
6
|
+
* parent uses internally. While `webUiExtensions` is live the page is handed
|
|
7
|
+
* to its service, which owns keyed mounting and disposal. Without the parent,
|
|
8
|
+
* the same component registers as its original first-level settings section,
|
|
9
|
+
* so a standalone install keeps a working entry.
|
|
10
|
+
*/
|
|
11
|
+
const SETTINGS_SECTION = 'settings.section';
|
|
12
|
+
const WEB_EXTENSION_SLOT = 'web-ui.extension';
|
|
13
|
+
function serviceOf(ctx) {
|
|
14
|
+
if (typeof ctx.get !== 'function')
|
|
15
|
+
return undefined;
|
|
16
|
+
try {
|
|
17
|
+
const candidate = ctx.get('webUiExtensions');
|
|
18
|
+
return candidate !== null
|
|
19
|
+
&& typeof candidate === 'object'
|
|
20
|
+
&& typeof candidate.sectionId === 'string'
|
|
21
|
+
&& typeof candidate.registerPage === 'function'
|
|
22
|
+
? candidate
|
|
23
|
+
: undefined;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function warn(seat, error) {
|
|
30
|
+
try {
|
|
31
|
+
console.warn(`[dsh-web-settings] page "${seat}" could not be mounted`, error);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
// A restricted console must not drop the remaining entry.
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Keep exactly one reachable page contribution while the parent loads or
|
|
39
|
+
* unloads. The parent service owns integrated mounting; only the fallback uses
|
|
40
|
+
* this plugin's own slot registry. Slot disposal is synchronous, so the latch
|
|
41
|
+
* prevents a move from recursively registering a duplicate.
|
|
42
|
+
*/
|
|
43
|
+
export function installWebExtensionPage(ctx, page) {
|
|
44
|
+
let dispose;
|
|
45
|
+
let current;
|
|
46
|
+
let reconciling = false;
|
|
47
|
+
let disposed = false;
|
|
48
|
+
const present = (seat) => {
|
|
49
|
+
if (typeof ctx.slots.entries !== 'function')
|
|
50
|
+
return current === seat;
|
|
51
|
+
const slot = seat === 'integrated' ? WEB_EXTENSION_SLOT : SETTINGS_SECTION;
|
|
52
|
+
return ctx.slots.entries(slot).some(entry => entry.component === page.component
|
|
53
|
+
&& (seat === 'integrated' ? entry.options.key : entry.options.id) === page.key);
|
|
54
|
+
};
|
|
55
|
+
const registerSeat = (seat) => {
|
|
56
|
+
if (seat === 'integrated') {
|
|
57
|
+
const service = serviceOf(ctx);
|
|
58
|
+
if (service === undefined)
|
|
59
|
+
throw new Error('webUiExtensions service is unavailable');
|
|
60
|
+
return service.registerPage(page);
|
|
61
|
+
}
|
|
62
|
+
return ctx.slots.register({
|
|
63
|
+
name: SETTINGS_SECTION,
|
|
64
|
+
id: page.key,
|
|
65
|
+
order: page.order,
|
|
66
|
+
label: page.label,
|
|
67
|
+
locale: page.locale,
|
|
68
|
+
inject: page.inject,
|
|
69
|
+
...(page.children === undefined ? {} : { children: page.children }),
|
|
70
|
+
}, page.component);
|
|
71
|
+
};
|
|
72
|
+
const reconcile = () => {
|
|
73
|
+
if (disposed || reconciling)
|
|
74
|
+
return;
|
|
75
|
+
const target = serviceOf(ctx) === undefined ? 'legacy' : 'integrated';
|
|
76
|
+
if (current === target && present(target))
|
|
77
|
+
return;
|
|
78
|
+
const slot = target === 'integrated' ? WEB_EXTENSION_SLOT : SETTINGS_SECTION;
|
|
79
|
+
if (typeof ctx.slots.spec === 'function' && ctx.slots.spec(slot) === undefined)
|
|
80
|
+
return;
|
|
81
|
+
reconciling = true;
|
|
82
|
+
const previous = current;
|
|
83
|
+
const disposePrevious = dispose;
|
|
84
|
+
current = undefined;
|
|
85
|
+
dispose = undefined;
|
|
86
|
+
disposePrevious?.();
|
|
87
|
+
try {
|
|
88
|
+
dispose = registerSeat(target);
|
|
89
|
+
current = target;
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
warn(target, error);
|
|
93
|
+
if (previous !== undefined && previous !== target) {
|
|
94
|
+
try {
|
|
95
|
+
dispose = registerSeat(previous);
|
|
96
|
+
current = previous;
|
|
97
|
+
}
|
|
98
|
+
catch (restoreError) {
|
|
99
|
+
warn(previous, restoreError);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
reconciling = false;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
if (typeof ctx.on === 'function') {
|
|
108
|
+
try {
|
|
109
|
+
ctx.on('slots/changed', reconcile);
|
|
110
|
+
}
|
|
111
|
+
catch { /* the initial entry remains usable */ }
|
|
112
|
+
}
|
|
113
|
+
reconcile();
|
|
114
|
+
return () => {
|
|
115
|
+
if (disposed)
|
|
116
|
+
return;
|
|
117
|
+
disposed = true;
|
|
118
|
+
dispose?.();
|
|
119
|
+
dispose = undefined;
|
|
120
|
+
current = undefined;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources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M,uBAAuB,wBAAwB,CAAA;AAuG5D;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,kBAAkB,GAAG,WAAW,CAmFxE;AAED,6EAA6E;AAC7E,eAAO,MAAM,qBAAqB,UAAU,CAAA;AAE5C,2EAA2E;AAC3E,wBAAgB,cAAc,CAAC,KAAK,EAAE,eAAe,GAAG,cAAc,CAYrE;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,QAAQ,EAAE,WAAW,CAAC,EAAE,SAAS,GAAG,aAAa,CAsBpF;AAED,sEAAsE;AACtE,wBAAgB,YAAY,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,CAEpD"}
|
package/lib/types/registry.js
CHANGED
|
@@ -575,6 +575,27 @@ function resolveFrames2dEntry(manifest, dir, options) {
|
|
|
575
575
|
...(remarks === undefined ? {} : { remarks }),
|
|
576
576
|
};
|
|
577
577
|
}
|
|
578
|
+
/**
|
|
579
|
+
* Directory-name suffix the market installer carries while it downloads:
|
|
580
|
+
* '<id>.install-<base36 ms>-<base36 suffix>'
|
|
581
|
+
* (`installAsset` in dsh-web `packages/dsh-market/src/core/installer.ts` builds
|
|
582
|
+
* it as `dest + '.install-' + Date.now().toString(36) + '-' +
|
|
583
|
+
* Math.random().toString(36).slice(2, 8)`). Success renames the staging
|
|
584
|
+
* directory onto its id, and the failure path removes it, so such a directory
|
|
585
|
+
* surviving on disk means an install was interrupted and what it holds is a
|
|
586
|
+
* partial pet.
|
|
587
|
+
*
|
|
588
|
+
* The bounds are the producer's real range rather than a guess: base36 of
|
|
589
|
+
* `Date.now()` is 8 digits today and stays under 11 for several millennia,
|
|
590
|
+
* and `.slice(2, 8)` always yields exactly 6 base36 characters. A directory
|
|
591
|
+
* whose name merely mentions '.install-' outside that shape stays an ordinary
|
|
592
|
+
* pet directory.
|
|
593
|
+
*/
|
|
594
|
+
const PET_INSTALL_STAGING_NAME = /\.install-[0-9a-z]{1,11}-[0-9a-z]{1,11}$/;
|
|
595
|
+
/** True when a pet directory name is an interrupted-install staging leftover. */
|
|
596
|
+
function isPetInstallStagingName(name) {
|
|
597
|
+
return PET_INSTALL_STAGING_NAME.test(name);
|
|
598
|
+
}
|
|
578
599
|
/** Scan one directory of pet folders; entries come back in name order. */
|
|
579
600
|
function scanPetDir(dir, options) {
|
|
580
601
|
if (!existsSync(dir))
|
|
@@ -589,6 +610,20 @@ function scanPetDir(dir, options) {
|
|
|
589
610
|
names.sort();
|
|
590
611
|
const entries = [];
|
|
591
612
|
for (const name of names) {
|
|
613
|
+
// An interrupted market install leaves '<id>.install-<base36>-<base36>'
|
|
614
|
+
// behind holding a partial pet.json. Because a directory sorts just before
|
|
615
|
+
// its own staging suffixes and later entries win the id collision below,
|
|
616
|
+
// the leftover would override the finished pet with the same id. Drop it
|
|
617
|
+
// before the manifest is read, and only report it: cleanup belongs to the
|
|
618
|
+
// installer, and a scan must stay read-only.
|
|
619
|
+
if (isPetInstallStagingName(name)) {
|
|
620
|
+
const leftover = join(dir, name);
|
|
621
|
+
const message = 'skipping install staging leftover ' + name + ' (' + leftover
|
|
622
|
+
+ '): an interrupted install left it behind, and it is ignored so it cannot override the finished pet with the same id';
|
|
623
|
+
options.warnings?.push(message);
|
|
624
|
+
options.diagnostics?.push({ level: 'warning', source: leftover, message });
|
|
625
|
+
continue;
|
|
626
|
+
}
|
|
592
627
|
const manifestFile = join(dir, name, 'pet.json');
|
|
593
628
|
if (!existsSync(manifestFile))
|
|
594
629
|
continue;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@linxin666/dsh-pet",
|
|
3
3
|
"description": "Multi-pet companion plugin for the dsh web GUI: a registry-driven floating pet that reacts to model activity, with per-pet naming, petting/feeding interactions and an affinity score",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.12",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** Lightweight, static pet thumbnails built from the registry's existing assets. */
|
|
2
|
+
|
|
3
|
+
import type { PetDefinition } from '../registry.ts'
|
|
4
|
+
import sectionCss from './settings-section.module.css'
|
|
5
|
+
|
|
6
|
+
/** Registry data needed by a thumbnail; older hosts may serve only id/name. */
|
|
7
|
+
export type PetPreviewDefinition = Pick<PetDefinition, 'id' | 'displayName'>
|
|
8
|
+
& Partial<Pick<PetDefinition, 'renderer' | 'cell' | 'columns' | 'atlasRows' | 'atlasUrl' | 'frames2d'>>
|
|
9
|
+
|
|
10
|
+
const PREVIEW_LIMIT = 72
|
|
11
|
+
const DEFAULT_CELL = { width: 192, height: 208 }
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Render the atlas's first sprite cell or a frames2d idle frame. Live2d and
|
|
15
|
+
* incomplete legacy responses degrade to a text mark instead of a broken image.
|
|
16
|
+
*/
|
|
17
|
+
export function PetPreview(props: { pet: PetPreviewDefinition }) {
|
|
18
|
+
const { pet } = props
|
|
19
|
+
const renderer = pet.renderer ?? 'sprite2d'
|
|
20
|
+
if (renderer === 'sprite2d' && pet.atlasUrl !== undefined) {
|
|
21
|
+
const cell = pet.cell ?? DEFAULT_CELL
|
|
22
|
+
const scale = Math.min(PREVIEW_LIMIT / cell.width, PREVIEW_LIMIT / cell.height)
|
|
23
|
+
const width = Math.max(1, Math.round(cell.width * scale))
|
|
24
|
+
const height = Math.max(1, Math.round(cell.height * scale))
|
|
25
|
+
const columns = pet.columns ?? 8
|
|
26
|
+
const rows = pet.atlasRows ?? 9
|
|
27
|
+
return (
|
|
28
|
+
<span className={sectionCss.previewFrame} aria-hidden="true">
|
|
29
|
+
<span
|
|
30
|
+
className={sectionCss.previewAtlas}
|
|
31
|
+
style={{
|
|
32
|
+
width,
|
|
33
|
+
height,
|
|
34
|
+
backgroundImage: `url("${pet.atlasUrl}")`,
|
|
35
|
+
backgroundSize: `${columns * width}px ${rows * height}px`,
|
|
36
|
+
}}
|
|
37
|
+
/>
|
|
38
|
+
</span>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
const frame = renderer === 'frames2d'
|
|
42
|
+
? pet.frames2d?.tracks.idle?.frames[0] ?? pet.atlasUrl
|
|
43
|
+
: undefined
|
|
44
|
+
return (
|
|
45
|
+
<span className={sectionCss.previewFrame} aria-hidden="true">
|
|
46
|
+
{frame === undefined
|
|
47
|
+
? <span className={sectionCss.previewFallback}>{pet.displayName.slice(0, 1)}</span>
|
|
48
|
+
: <img className={sectionCss.previewImage} src={frame} alt="" draggable={false} />}
|
|
49
|
+
</span>
|
|
50
|
+
)
|
|
51
|
+
}
|
|
@@ -9,7 +9,8 @@ import { afterEach, beforeAll, describe, expect, it, vi } from 'vitest'
|
|
|
9
9
|
import { cleanup, render, screen } from '@testing-library/react'
|
|
10
10
|
import { useSyncExternalStore } from 'react'
|
|
11
11
|
import type { ConfigForm } from '@deepseek-ai/dsh-client-ui-settings/client'
|
|
12
|
-
import { PetSettingsCard, PetSettingsCardController, type PetSettings } from './PetSettingsCard.tsx'
|
|
12
|
+
import { BUBBLE_SCALE_RANGE, INSET_RANGE, PetSettingsCard, PetSettingsCardController, SIZE_RANGE, type PetSettings } from './PetSettingsCard.tsx'
|
|
13
|
+
import { BUBBLE_SCALE_MAX, BUBBLE_SCALE_MIN, DISPLAY_INSET_MAX, DISPLAY_SIZE_MAX, DISPLAY_SIZE_MIN } from '../persist.ts'
|
|
13
14
|
import { t } from './locales.ts'
|
|
14
15
|
|
|
15
16
|
vi.mock('@deepseek-ai/dsh-client-store', () => ({ // test-standards-allow: the SDK client bundle is a browser module factory and cannot be imported by Vitest
|
|
@@ -103,13 +104,12 @@ describe('pet selection without a Host settings form', () => {
|
|
|
103
104
|
const face = controller.inject()
|
|
104
105
|
const state = () => face.hooks.petSettingsCard.getSnapshot()
|
|
105
106
|
|
|
106
|
-
// When the user chooses the maid whale
|
|
107
|
+
// When the user chooses the maid whale
|
|
107
108
|
expect(state()).toMatchObject({ petSelectionFallback: true, petId: { text: 'whale-girl' }, dirty: false })
|
|
108
109
|
face.edit('petId', '')
|
|
109
110
|
expect(state()).toMatchObject({ dirty: false, petId: { text: 'whale-girl' } })
|
|
110
111
|
face.edit('petId', 'jyn')
|
|
111
|
-
expect(state()).toMatchObject({
|
|
112
|
-
face.save()
|
|
112
|
+
expect(state()).toMatchObject({ petId: { text: 'jyn' } })
|
|
113
113
|
await vi.waitFor(() => { expect(state().saving).toBe(false) })
|
|
114
114
|
|
|
115
115
|
// Then the pet service holds it, the draft clears, and the absent Host form is untouched
|
|
@@ -120,7 +120,7 @@ describe('pet selection without a Host settings form', () => {
|
|
|
120
120
|
controller.dispose()
|
|
121
121
|
})
|
|
122
122
|
|
|
123
|
-
it('user
|
|
123
|
+
it('user sees the selection go back when the pet API refuses it', async () => {
|
|
124
124
|
// Given the Host has no pet form and the pet API still serves its selection
|
|
125
125
|
vi.useFakeTimers()
|
|
126
126
|
const { scope } = unavailableForm()
|
|
@@ -134,12 +134,11 @@ describe('pet selection without a Host settings form', () => {
|
|
|
134
134
|
const controller = new PetSettingsCardController(scope)
|
|
135
135
|
await vi.advanceTimersByTimeAsync(0)
|
|
136
136
|
const face = controller.inject()
|
|
137
|
-
// When the user
|
|
137
|
+
// When the user picks a pet the pet API refuses
|
|
138
138
|
face.edit('petId', 'jyn')
|
|
139
|
-
face.save()
|
|
140
139
|
await vi.waitFor(() => { expect(face.hooks.petSettingsCard.getSnapshot().saving).toBe(false) })
|
|
141
|
-
// Then the choice
|
|
142
|
-
expect(face.hooks.petSettingsCard.getSnapshot()).toMatchObject({ dirty:
|
|
140
|
+
// Then the choice is back on the persisted pet and the failure is visible
|
|
141
|
+
expect(face.hooks.petSettingsCard.getSnapshot()).toMatchObject({ dirty: false, failed: true, petId: { text: 'whale-girl' } })
|
|
143
142
|
controller.dispose()
|
|
144
143
|
})
|
|
145
144
|
})
|
|
@@ -166,11 +165,10 @@ describe('pet visibility without a Host settings form', () => {
|
|
|
166
165
|
const face = controller.inject()
|
|
167
166
|
const state = () => face.hooks.petSettingsCard.getSnapshot()
|
|
168
167
|
|
|
169
|
-
// When the user switches the pet off
|
|
168
|
+
// When the user switches the pet off
|
|
170
169
|
expect(state()).toMatchObject({ petSelectionFallback: true, visible: { text: 'true' }, dirty: false })
|
|
171
170
|
face.edit('visible', 'false')
|
|
172
|
-
expect(state()).toMatchObject({
|
|
173
|
-
face.save()
|
|
171
|
+
expect(state()).toMatchObject({ visible: { text: 'false' } })
|
|
174
172
|
await vi.waitFor(() => { expect(state().saving).toBe(false) })
|
|
175
173
|
|
|
176
174
|
// Then the pet service holds it, the draft clears, and the absent Host form is untouched
|
|
@@ -181,7 +179,7 @@ describe('pet visibility without a Host settings form', () => {
|
|
|
181
179
|
controller.dispose()
|
|
182
180
|
})
|
|
183
181
|
|
|
184
|
-
it('user
|
|
182
|
+
it('user sees the switch go back when the pet API refuses the visibility write', async () => {
|
|
185
183
|
// Given the Host has no pet form and the pet API refuses visibility writes
|
|
186
184
|
vi.useFakeTimers()
|
|
187
185
|
const { scope } = unavailableForm()
|
|
@@ -195,12 +193,11 @@ describe('pet visibility without a Host settings form', () => {
|
|
|
195
193
|
const controller = new PetSettingsCardController(scope)
|
|
196
194
|
await vi.advanceTimersByTimeAsync(0)
|
|
197
195
|
const face = controller.inject()
|
|
198
|
-
// When the user
|
|
196
|
+
// When the user flips a visibility the pet API refuses
|
|
199
197
|
face.edit('visible', 'false')
|
|
200
|
-
face.save()
|
|
201
198
|
await vi.waitFor(() => { expect(face.hooks.petSettingsCard.getSnapshot().saving).toBe(false) })
|
|
202
|
-
// Then the switch
|
|
203
|
-
expect(face.hooks.petSettingsCard.getSnapshot()).toMatchObject({ dirty:
|
|
199
|
+
// Then the switch is back on the persisted visibility and the failure is visible
|
|
200
|
+
expect(face.hooks.petSettingsCard.getSnapshot()).toMatchObject({ dirty: false, failed: true, visible: { text: 'true' } })
|
|
204
201
|
controller.dispose()
|
|
205
202
|
})
|
|
206
203
|
})
|
|
@@ -230,6 +227,7 @@ describe('pet settings card rendered without a Host settings form', () => {
|
|
|
230
227
|
discard={face.discard}
|
|
231
228
|
edit={face.edit}
|
|
232
229
|
resetField={face.resetField}
|
|
230
|
+
refreshPets={face.refreshPets}
|
|
233
231
|
/>,
|
|
234
232
|
)
|
|
235
233
|
|
|
@@ -237,7 +235,7 @@ describe('pet settings card rendered without a Host settings form', () => {
|
|
|
237
235
|
expect(screen.getByLabelText(t('settings.pet'))).toBeTruthy()
|
|
238
236
|
expect(screen.getByLabelText(t('settings.visible'))).toBeTruthy()
|
|
239
237
|
// ...while the fields only the absent Host form owns stay hidden
|
|
240
|
-
expect(screen.
|
|
238
|
+
expect(screen.queryByRole('switch')).toBeNull()
|
|
241
239
|
expect(screen.queryByLabelText(t('settings.size'))).toBeNull()
|
|
242
240
|
controller.dispose()
|
|
243
241
|
})
|
|
@@ -268,18 +266,18 @@ describe('the status bubble switch on the Host settings form', () => {
|
|
|
268
266
|
discard={face.discard}
|
|
269
267
|
edit={face.edit}
|
|
270
268
|
resetField={face.resetField}
|
|
269
|
+
refreshPets={face.refreshPets}
|
|
271
270
|
/>,
|
|
272
271
|
)
|
|
273
272
|
expect(screen.getByLabelText(t('settings.statusBubbles'))).toBeTruthy()
|
|
274
273
|
expect(state()).toMatchObject({ statusBubbles: { text: 'auto', invalid: false } })
|
|
275
274
|
|
|
276
|
-
// When the user picks Off
|
|
275
|
+
// When the user picks Off
|
|
277
276
|
face.edit('statusBubbles', 'off')
|
|
278
|
-
expect(state()).toMatchObject({
|
|
279
|
-
face.save()
|
|
277
|
+
expect(state()).toMatchObject({ statusBubbles: { text: 'off' } })
|
|
280
278
|
await vi.waitFor(() => { expect(state().saving).toBe(false) })
|
|
281
279
|
|
|
282
|
-
// Then the settings document holds the mode, and the draft clears
|
|
280
|
+
// Then the settings document holds the mode with no further step, and the draft clears
|
|
283
281
|
expect(mutate).toHaveBeenCalledWith([{ op: 'set', path: ['statusBubbles'], value: 'off' }])
|
|
284
282
|
expect(value().user?.statusBubbles).toBe('off')
|
|
285
283
|
expect(state()).toMatchObject({ dirty: false, failed: false, statusBubbles: { text: 'off' } })
|
|
@@ -300,3 +298,61 @@ describe('the status bubble switch on the Host settings form', () => {
|
|
|
300
298
|
})
|
|
301
299
|
})
|
|
302
300
|
})
|
|
301
|
+
|
|
302
|
+
describe('the coarse sliders on the display fields', () => {
|
|
303
|
+
it('cover the bounds the host schema accepts for size and bubble scale', () => {
|
|
304
|
+
// The card spells the spans as literals because the browser half never
|
|
305
|
+
// imports the host module; this keeps the two from drifting apart.
|
|
306
|
+
expect(SIZE_RANGE).toMatchObject({ min: DISPLAY_SIZE_MIN, max: DISPLAY_SIZE_MAX })
|
|
307
|
+
expect(BUBBLE_SCALE_RANGE).toMatchObject({ min: BUBBLE_SCALE_MIN, max: BUBBLE_SCALE_MAX })
|
|
308
|
+
expect(INSET_RANGE.max).toBeLessThanOrEqual(DISPLAY_INSET_MAX)
|
|
309
|
+
})
|
|
310
|
+
})
|
|
311
|
+
|
|
312
|
+
describe('the pet registry while the plugin is off', () => {
|
|
313
|
+
it('re-reads the list when the master switch is turned on, without a page reload', async () => {
|
|
314
|
+
// Given the plugin is off, so the pet API never served the registry
|
|
315
|
+
vi.useFakeTimers()
|
|
316
|
+
const { scope } = readyForm({ enabled: false })
|
|
317
|
+
let apiServing = false
|
|
318
|
+
const fetch = vi.fn(async (input: RequestInfo | URL) => {
|
|
319
|
+
const path = String(input)
|
|
320
|
+
if (path === '/api/pet/pets') {
|
|
321
|
+
// The host registers '/api/pet/*' only while the plugin is enabled.
|
|
322
|
+
if (!apiServing) return response({ error: 'not registered' }, false)
|
|
323
|
+
return response([{ id: 'whale-girl', displayName: '鲸鱼娘' }])
|
|
324
|
+
}
|
|
325
|
+
if (path === '/api/pet/state') return response({ pet: { id: 'whale-girl' }, display: { visible: false } })
|
|
326
|
+
throw new Error('unexpected request: ' + path)
|
|
327
|
+
})
|
|
328
|
+
vi.stubGlobal('fetch', fetch)
|
|
329
|
+
const controller = new PetSettingsCardController(scope)
|
|
330
|
+
await vi.advanceTimersByTimeAsync(0)
|
|
331
|
+
const face = controller.inject()
|
|
332
|
+
const state = () => face.hooks.petSettingsCard.getSnapshot()
|
|
333
|
+
|
|
334
|
+
// When the card renders with the plugin off, there is nothing to pick
|
|
335
|
+
render(
|
|
336
|
+
<PetSettingsCard
|
|
337
|
+
t={t}
|
|
338
|
+
usePetSettingsCard={select => useSyncExternalStore(face.hooks.petSettingsCard.subscribe, () => select(face.hooks.petSettingsCard.getSnapshot()))}
|
|
339
|
+
save={face.save}
|
|
340
|
+
discard={face.discard}
|
|
341
|
+
edit={face.edit}
|
|
342
|
+
resetField={face.resetField}
|
|
343
|
+
refreshPets={face.refreshPets}
|
|
344
|
+
/>,
|
|
345
|
+
)
|
|
346
|
+
await vi.advanceTimersByTimeAsync(10_000)
|
|
347
|
+
expect(state().petPreviews).toHaveLength(0)
|
|
348
|
+
|
|
349
|
+
// When the plugin is turned on, the API exists and the card asks it again
|
|
350
|
+
apiServing = true
|
|
351
|
+
face.edit('enabled', 'true')
|
|
352
|
+
|
|
353
|
+
// Then the picker fills without the reader touching the page
|
|
354
|
+
await vi.waitFor(() => { expect(state().petPreviews).toHaveLength(1) })
|
|
355
|
+
expect(state().petId.text).toBe('whale-girl')
|
|
356
|
+
controller.dispose()
|
|
357
|
+
})
|
|
358
|
+
})
|