Skip to content

Commit 95534e9

Browse files
authored
Merge pull request #3487 from superdoc-dev/caio-pizzol/SD-typecheck-coverage-drain-3
test(typecheck): drain 18 UI/state obligations from public-method coverage (SD-673)
2 parents 8939a3f + e747c21 commit 95534e9

2 files changed

Lines changed: 161 additions & 18 deletions

File tree

β€Žtests/consumer-typecheck/public-method-coverage-debt-snapshot.jsonβ€Ž

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,23 @@
77
"canPerformPermission:returns",
88
"closeSurface:parameters",
99
"closeSurface:returns",
10-
"destroy:returns",
11-
"element:returns",
1210
"export:parameters",
1311
"export:returns",
1412
"exportEditorsToDOCX:parameters",
1513
"exportEditorsToDOCX:returns",
16-
"focus:returns",
1714
"getPresentationEditorForDocument:parameters",
1815
"getPresentationEditorForDocument:returns",
1916
"lockSuperdoc:parameters",
2017
"lockSuperdoc:returns",
2118
"openSurface:parameters",
2219
"openSurface:returns",
2320
"removeCommentsList:returns",
24-
"requiredNumberOfEditors:returns",
2521
"save:returns",
2622
"scrollToComment:parameters",
2723
"scrollToComment:returns",
28-
"setDisableContextMenu:parameters",
29-
"setDisableContextMenu:returns",
30-
"setHighContrastMode:parameters",
31-
"setHighContrastMode:returns",
3224
"setLocked:parameters",
3325
"setLocked:returns",
34-
"setShowBookmarks:parameters",
35-
"setShowBookmarks:returns",
36-
"setShowFormattingMarks:parameters",
37-
"setShowFormattingMarks:returns",
38-
"setTrackedChangesPreferences:parameters",
39-
"setTrackedChangesPreferences:returns",
40-
"setZoom:parameters",
41-
"setZoom:returns",
4226
"state:returns",
43-
"toggleFormattingMarks:returns",
44-
"toggleRuler:returns",
4527
"upgradeToCollaboration:parameters",
4628
"upgradeToCollaboration:returns"
4729
]
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
/**
2+
* Consumer typecheck: UI and state-control public APIs on `SuperDoc`.
3+
*
4+
* Drains the low-risk UI/state batch from the public-method coverage
5+
* gate. Each method's parameter or return shape is asserted against
6+
* the emitted `.d.ts` with strict identity equality, so a future
7+
* migration that narrows or widens any of these contracts will fail
8+
* CI on the obligation diff rather than slipping silently into a
9+
* release.
10+
*
11+
* Methods covered here, with returns verified against the emitted
12+
* `.d.ts` and not inferred from intent:
13+
*
14+
* - `setZoom(percent)` β†’ `void`
15+
* - `setHighContrastMode(isHighContrast)` β†’ `void`
16+
* - `setShowBookmarks(show?)` β†’ `void`
17+
* - `setShowFormattingMarks(show?)` β†’ `void`
18+
* - `setDisableContextMenu(disabled?)` β†’ `void`
19+
* - `setTrackedChangesPreferences(preferences?)` β†’ `void`
20+
* - `toggleFormattingMarks()` β†’ `void`
21+
* - `toggleRuler()` β†’ `void`
22+
* - `focus()` β†’ `void`
23+
* - `destroy()` β†’ `void`
24+
* - `element` (getter) β†’ `Element | null`
25+
* - `requiredNumberOfEditors` (getter) β†’ `number`
26+
*
27+
* Drained obligations (18): 6 method pairs (parameters + returns)
28+
* for the setters, plus 4 zero-param method returns and 2 getter
29+
* returns.
30+
*
31+
* Not covered here:
32+
*
33+
* - The `state` getter returns `{ documents: RuntimeDocument[]; users: User[] }`.
34+
* RuntimeDocument is an internal-only type (declared in
35+
* core/types/index.ts with an "Internal use only; not part of any
36+
* public typedef" header) and is not re-exported through the
37+
* public facade. Asserting the indexed return type against a
38+
* consumer-importable shape would require either widening the
39+
* source return to use the public Document (lossy for internal
40+
* callers) or promoting RuntimeDocument to a public supported-root
41+
* type (out of scope here). The corresponding obligation is left
42+
* on the debt snapshot until that surface decision is made.
43+
*/
44+
import type { SuperDoc } from 'superdoc';
45+
46+
type Equal<A, B> = (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? true : false;
47+
type AssertEqual<A, B> = Equal<A, B> extends true ? true : never;
48+
49+
declare const sd: SuperDoc;
50+
51+
// ─── setZoom ────────────────────────────────────────────────────────
52+
// Updates the active zoom in the Pinia store; the Vue layer's
53+
// activeZoom watcher propagates to each PresentationEditor.
54+
// Early-returns on non-positive / non-finite input.
55+
const _setZoomParamsOk: AssertEqual<Parameters<SuperDoc['setZoom']>, [percent: number]> = true;
56+
const _setZoomReturnOk: AssertEqual<ReturnType<SuperDoc['setZoom']>, void> = true;
57+
sd.setZoom(150);
58+
59+
// ─── setHighContrastMode ────────────────────────────────────────────
60+
// Forwards to `activeEditor.setHighContrastMode` and writes to the
61+
// highContrastModeStore. No-op until the active editor exists.
62+
const _setHighContrastParamsOk: AssertEqual<
63+
Parameters<SuperDoc['setHighContrastMode']>,
64+
[isHighContrast: boolean]
65+
> = true;
66+
const _setHighContrastReturnOk: AssertEqual<ReturnType<SuperDoc['setHighContrastMode']>, void> = true;
67+
sd.setHighContrastMode(true);
68+
69+
// ─── setShowBookmarks ───────────────────────────────────────────────
70+
// Writes `layoutEngineOptions.showBookmarks` and forwards to each
71+
// PresentationEditor. Parameter has a `= true` default in source, so
72+
// the emitted signature is `(show?: boolean)`.
73+
const _setShowBookmarksParamsOk: AssertEqual<Parameters<SuperDoc['setShowBookmarks']>, [show?: boolean]> = true;
74+
const _setShowBookmarksReturnOk: AssertEqual<ReturnType<SuperDoc['setShowBookmarks']>, void> = true;
75+
sd.setShowBookmarks(true);
76+
sd.setShowBookmarks();
77+
78+
// ─── setShowFormattingMarks ─────────────────────────────────────────
79+
// Same shape as setShowBookmarks. Writes the layout option, forwards
80+
// to PresentationEditor, and emits `formatting-marks-change`.
81+
const _setShowFormattingMarksParamsOk: AssertEqual<
82+
Parameters<SuperDoc['setShowFormattingMarks']>,
83+
[show?: boolean]
84+
> = true;
85+
const _setShowFormattingMarksReturnOk: AssertEqual<ReturnType<SuperDoc['setShowFormattingMarks']>, void> = true;
86+
sd.setShowFormattingMarks(true);
87+
88+
// ─── setDisableContextMenu ──────────────────────────────────────────
89+
// Writes `config.disableContextMenu` and forwards to each
90+
// PresentationEditor / Editor. Same `(disabled?: boolean)` default
91+
// shape as the other toggles.
92+
const _setDisableContextMenuParamsOk: AssertEqual<
93+
Parameters<SuperDoc['setDisableContextMenu']>,
94+
[disabled?: boolean]
95+
> = true;
96+
const _setDisableContextMenuReturnOk: AssertEqual<ReturnType<SuperDoc['setDisableContextMenu']>, void> = true;
97+
sd.setDisableContextMenu(true);
98+
99+
// ─── setTrackedChangesPreferences ───────────────────────────────────
100+
// Accepts an inline literal of mode + enabled. The source param is
101+
// optional; an empty object normalizes to `undefined`. Mode is the
102+
// closed union `'review' | 'original' | 'final' | 'off'`.
103+
const _setTrackedChangesParamsOk: AssertEqual<
104+
Parameters<SuperDoc['setTrackedChangesPreferences']>,
105+
[preferences?: { mode?: 'review' | 'original' | 'final' | 'off'; enabled?: boolean }]
106+
> = true;
107+
const _setTrackedChangesReturnOk: AssertEqual<ReturnType<SuperDoc['setTrackedChangesPreferences']>, void> = true;
108+
sd.setTrackedChangesPreferences({ mode: 'review', enabled: true });
109+
110+
// ─── toggleFormattingMarks ──────────────────────────────────────────
111+
// Reads current `layoutEngineOptions.showFormattingMarks` and flips
112+
// via `setShowFormattingMarks`. Zero-arg.
113+
const _toggleFormattingMarksReturnOk: AssertEqual<ReturnType<SuperDoc['toggleFormattingMarks']>, void> = true;
114+
115+
// ─── toggleRuler ────────────────────────────────────────────────────
116+
// Flips `config.rulers` and writes through to each RuntimeDocument's
117+
// `rulers` mirror in the Pinia store. Throws (via `#requireSuperdocStore`)
118+
// when called pre-ready.
119+
const _toggleRulerReturnOk: AssertEqual<ReturnType<SuperDoc['toggleRuler']>, void> = true;
120+
121+
// ─── focus ──────────────────────────────────────────────────────────
122+
// Focuses `activeEditor` if present; otherwise walks the document
123+
// list and focuses the first editor found.
124+
const _focusReturnOk: AssertEqual<ReturnType<SuperDoc['focus']>, void> = true;
125+
126+
// ─── destroy ────────────────────────────────────────────────────────
127+
// Tears down surfaces, toolbar, Vue app, collaboration, and the
128+
// internal mount wrapper. Idempotent: marks `#destroyed` early so
129+
// in-flight init bails out.
130+
const _destroyReturnOk: AssertEqual<ReturnType<SuperDoc['destroy']>, void> = true;
131+
132+
// ─── element (getter) ───────────────────────────────────────────────
133+
// Resolves `config.selector` to a DOM element. String selectors go
134+
// through `document.querySelector` (`Element | null`); element
135+
// references are returned as-is. Emitted return is `Element | null`.
136+
const _elementOk: AssertEqual<SuperDoc['element'], Element | null> = true;
137+
138+
// ─── requiredNumberOfEditors (getter) ───────────────────────────────
139+
// Count of DOCX documents in the Pinia store. Throws pre-ready.
140+
const _requiredNumberOfEditorsOk: AssertEqual<SuperDoc['requiredNumberOfEditors'], number> = true;
141+
142+
void [
143+
_setZoomParamsOk,
144+
_setZoomReturnOk,
145+
_setHighContrastParamsOk,
146+
_setHighContrastReturnOk,
147+
_setShowBookmarksParamsOk,
148+
_setShowBookmarksReturnOk,
149+
_setShowFormattingMarksParamsOk,
150+
_setShowFormattingMarksReturnOk,
151+
_setDisableContextMenuParamsOk,
152+
_setDisableContextMenuReturnOk,
153+
_setTrackedChangesParamsOk,
154+
_setTrackedChangesReturnOk,
155+
_toggleFormattingMarksReturnOk,
156+
_toggleRulerReturnOk,
157+
_focusReturnOk,
158+
_destroyReturnOk,
159+
_elementOk,
160+
_requiredNumberOfEditorsOk,
161+
];

0 commit comments

Comments
Β (0)