@dovetail-ts/test-support 0.0.0-stage → 1.0.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/dist/index.js ADDED
@@ -0,0 +1,814 @@
1
+ import { Harness, testId, ByTestId, ByRole, role, ComponentHarness } from '@harnessed-ts/core';
2
+ import { IDBFactory, IDBVersionChangeEvent, IDBTransaction, IDBRequest, IDBOpenDBRequest, IDBObjectStore, IDBKeyRange, IDBIndex, IDBDatabase, IDBCursorWithValue, IDBCursor } from 'fake-indexeddb';
3
+ import { encodeMessage, parseMessage } from '@dovetail-ts/protocol';
4
+
5
+ var __create = Object.create;
6
+ var __defProp = Object.defineProperty;
7
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
8
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name);
9
+ var __typeError = (msg) => {
10
+ throw TypeError(msg);
11
+ };
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
14
+ var __decoratorStart = (base) => [, , , __create(base?.[__knownSymbol("metadata")] ?? null)];
15
+ var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
16
+ var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
17
+ var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
18
+ var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
19
+ var __runInitializers = (array, flags, self, value) => {
20
+ for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
21
+ return value;
22
+ };
23
+ var __decorateElement = (array, flags, name, decorators, target, extra) => {
24
+ var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
25
+ var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
26
+ var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
27
+ var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
28
+ return __privateGet(this, extra);
29
+ }, set [name](x) {
30
+ return __privateSet(this, extra, x);
31
+ } }, name));
32
+ k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
33
+ for (var i = decorators.length - 1; i >= 0; i--) {
34
+ ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
35
+ if (k) {
36
+ ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
37
+ if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
38
+ if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
39
+ }
40
+ it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
41
+ if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
42
+ else if (typeof it !== "object" || it === null) __typeError("Object expected");
43
+ else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
44
+ }
45
+ return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
46
+ };
47
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
48
+ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
49
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
50
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
51
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
52
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
53
+ var _DovetailHarness_decorators, _init, _a;
54
+ _DovetailHarness_decorators = [Harness({ host: testId("dovetail") })];
55
+ var DovetailHarness = class extends (_a = ComponentHarness) {
56
+ /** A harness of this class on the element of `host`, in place of the host of the class. */
57
+ static at(env, host, parentScope = []) {
58
+ const harness = new this(env, parentScope);
59
+ harness._scope = [...parentScope, host];
60
+ return harness;
61
+ }
62
+ /** The `data-state` attribute of the host, or null. */
63
+ async state() {
64
+ return this.self.attribute("data-state");
65
+ }
66
+ /** The text of the host, without the white space at the ends. */
67
+ async text() {
68
+ return (await this.self.text()).trim();
69
+ }
70
+ };
71
+ _init = __decoratorStart(_a);
72
+ DovetailHarness = __decorateElement(_init, 0, "DovetailHarness", _DovetailHarness_decorators, DovetailHarness);
73
+ __runInitializers(_init, 1, DovetailHarness);
74
+
75
+ // src/fake-clock.ts
76
+ var RUN_ALL_LIMIT = 1e4;
77
+ var FakeClock = class {
78
+ #now;
79
+ #nextId = 1;
80
+ #timers = [];
81
+ constructor(start = 0) {
82
+ this.#now = start;
83
+ }
84
+ /** The time in milliseconds, as `Date.now()`. */
85
+ now() {
86
+ return this.#now;
87
+ }
88
+ /** The number of timers that have not run yet. */
89
+ get pending() {
90
+ return this.#timers.length;
91
+ }
92
+ setTimeout(run, delay = 0) {
93
+ return this.#add(run, delay, 0);
94
+ }
95
+ clearTimeout(id) {
96
+ this.#timers = this.#timers.filter((timer) => timer.id !== id);
97
+ }
98
+ setInterval(run, every) {
99
+ return this.#add(run, every, Math.max(1, every));
100
+ }
101
+ clearInterval(id) {
102
+ this.clearTimeout(id);
103
+ }
104
+ /** Moves the clock `ms` forward, and runs each timer that comes due, in time order. */
105
+ tick(ms) {
106
+ if (ms < 0) throw new Error("FakeClock.tick: the clock cannot move back");
107
+ const end = this.#now + ms;
108
+ for (let timer = this.#next(end); timer; timer = this.#next(end)) this.#fire(timer);
109
+ this.#now = end;
110
+ }
111
+ /** Runs each timer, also the timers that they set, and moves the clock to the last one. */
112
+ runAll() {
113
+ for (let count = 0; this.#timers.length > 0; count++) {
114
+ if (count >= RUN_ALL_LIMIT) {
115
+ throw new Error(
116
+ `FakeClock.runAll: more than ${RUN_ALL_LIMIT} timers; a timer sets itself again`
117
+ );
118
+ }
119
+ const timer = this.#next(Infinity);
120
+ if (timer) this.#fire(timer);
121
+ }
122
+ }
123
+ #add(run, delay, every) {
124
+ const id = this.#nextId++;
125
+ this.#timers.push({ id, at: this.#now + Math.max(0, delay), every, run });
126
+ return id;
127
+ }
128
+ /** The first timer due at or before `end`. Equal times run in the order that they were set. */
129
+ #next(end) {
130
+ let first;
131
+ for (const timer of this.#timers) {
132
+ if (timer.at <= end && (!first || timer.at < first.at)) first = timer;
133
+ }
134
+ return first;
135
+ }
136
+ #fire(timer) {
137
+ this.#now = timer.at;
138
+ if (timer.every > 0) timer.at += timer.every;
139
+ else this.#timers = this.#timers.filter((t) => t !== timer);
140
+ timer.run();
141
+ }
142
+ };
143
+ var GLOBALS = {
144
+ IDBCursor,
145
+ IDBCursorWithValue,
146
+ IDBDatabase,
147
+ IDBIndex,
148
+ IDBKeyRange,
149
+ IDBObjectStore,
150
+ IDBOpenDBRequest,
151
+ IDBRequest,
152
+ IDBTransaction,
153
+ IDBVersionChangeEvent
154
+ };
155
+ function installFakeIndexedDB(scope = globalThis) {
156
+ const target = scope;
157
+ const values = { indexedDB: new IDBFactory(), ...GLOBALS };
158
+ const before = Object.keys(values).map((key) => ({
159
+ key,
160
+ had: Object.prototype.hasOwnProperty.call(target, key),
161
+ value: target[key]
162
+ }));
163
+ for (const [key, value] of Object.entries(values)) {
164
+ Object.defineProperty(target, key, { value, configurable: true, writable: true });
165
+ }
166
+ return () => {
167
+ for (const { key, had, value } of before) {
168
+ if (had) Object.defineProperty(target, key, { value, configurable: true, writable: true });
169
+ else delete target[key];
170
+ }
171
+ };
172
+ }
173
+
174
+ // src/network-switch.ts
175
+ var NetworkSwitch = class {
176
+ #mode = "online";
177
+ #listeners = /* @__PURE__ */ new Set();
178
+ #latency;
179
+ #dropRate;
180
+ #seed;
181
+ #target;
182
+ constructor(options = {}) {
183
+ this.#latency = options.latency ?? 500;
184
+ this.#dropRate = options.dropRate ?? 0.2;
185
+ this.#seed = options.seed ?? 1;
186
+ this.#target = options.target;
187
+ }
188
+ get mode() {
189
+ return this.#mode;
190
+ }
191
+ get isOnline() {
192
+ return this.#mode !== "offline";
193
+ }
194
+ set(mode) {
195
+ if (mode === this.#mode) return;
196
+ const wasOnline = this.isOnline;
197
+ this.#mode = mode;
198
+ if (wasOnline !== this.isOnline)
199
+ this.#target?.dispatchEvent(new Event(this.isOnline ? "online" : "offline"));
200
+ for (const listener of [...this.#listeners]) listener(mode);
201
+ }
202
+ /** Calls `listener` on each change of the mode. Returns a function that stops it. */
203
+ subscribe(listener) {
204
+ this.#listeners.add(listener);
205
+ return () => this.#listeners.delete(listener);
206
+ }
207
+ /** The delay of the next message, in milliseconds. */
208
+ delay() {
209
+ return this.#mode === "slow" ? this.#latency : 0;
210
+ }
211
+ /** True when the next message drops its connection. Only the flaky mode drops. */
212
+ drops() {
213
+ return this.#mode === "flaky" && this.#random() < this.#dropRate;
214
+ }
215
+ /** mulberry32: a small seeded generator, so a flaky test runs the same way each time. */
216
+ #random() {
217
+ let t = this.#seed = this.#seed + 1831565813 | 0;
218
+ t = Math.imul(t ^ t >>> 15, t | 1);
219
+ t ^= t + Math.imul(t ^ t >>> 7, t | 61);
220
+ return ((t ^ t >>> 14) >>> 0) / 4294967296;
221
+ }
222
+ };
223
+
224
+ // src/fake-transport.ts
225
+ var DROPPED = { code: 1006, reason: "offline", wasClean: false };
226
+ var End = class {
227
+ constructor(link, from) {
228
+ this.link = link;
229
+ this.from = from;
230
+ }
231
+ link;
232
+ from;
233
+ peer;
234
+ #open = false;
235
+ #messages = /* @__PURE__ */ new Set();
236
+ #closes = /* @__PURE__ */ new Set();
237
+ get isOpen() {
238
+ return this.#open;
239
+ }
240
+ open() {
241
+ return this.link.open();
242
+ }
243
+ /** Sends a message. It goes on the wire as text, so the other end gets a copy. */
244
+ send(message) {
245
+ if (!this.#open) throw new Error("FakeHub: the transport is not open");
246
+ this.link.carry(this.peer, encodeMessage(message));
247
+ }
248
+ close(code = 1e3, reason = "") {
249
+ this.link.close({ code, reason, wasClean: true });
250
+ }
251
+ onMessage(listener) {
252
+ this.#messages.add(listener);
253
+ return () => this.#messages.delete(listener);
254
+ }
255
+ onClose(listener) {
256
+ this.#closes.add(listener);
257
+ return () => this.#closes.delete(listener);
258
+ }
259
+ markOpen() {
260
+ this.#open = true;
261
+ }
262
+ /** Gets a frame from the wire. A frame that is not a valid message closes the connection. */
263
+ receive(text) {
264
+ if (!this.#open) return;
265
+ const result = parseMessage(text, { from: this.from });
266
+ if (!result.ok) {
267
+ this.link.close({ code: 1007, reason: result.error.message, wasClean: false });
268
+ return;
269
+ }
270
+ for (const listener of [...this.#messages]) listener(result.message);
271
+ }
272
+ closed(info) {
273
+ if (!this.#open) return;
274
+ this.#open = false;
275
+ for (const listener of [...this.#closes]) listener(info);
276
+ }
277
+ };
278
+ var Link = class {
279
+ constructor(hub) {
280
+ this.hub = hub;
281
+ this.client = new End(this, "server");
282
+ this.server = new End(this, "client");
283
+ this.client.peer = this.server;
284
+ this.server.peer = this.client;
285
+ }
286
+ hub;
287
+ client;
288
+ server;
289
+ #state = "new";
290
+ async open() {
291
+ if (this.#state === "open") return;
292
+ if (this.#state === "closed") throw new Error("FakeHub: the transport is closed");
293
+ if (!this.hub.network.isOnline) throw new Error("FakeHub: the network is offline");
294
+ this.#state = "open";
295
+ this.client.markOpen();
296
+ this.server.markOpen();
297
+ this.hub.accept(this);
298
+ }
299
+ /** Delivers a frame to the end `to`, after the delay of the network. */
300
+ carry(to, text) {
301
+ const network = this.hub.network;
302
+ this.hub.timers.setTimeout(() => {
303
+ if (this.#state !== "open") return;
304
+ if (network.drops()) this.close(DROPPED);
305
+ else to?.receive(text);
306
+ }, network.delay());
307
+ }
308
+ close(info) {
309
+ if (this.#state !== "open") {
310
+ this.#state = "closed";
311
+ return;
312
+ }
313
+ this.#state = "closed";
314
+ this.hub.release(this);
315
+ this.client.closed(info);
316
+ this.server.closed(info);
317
+ }
318
+ };
319
+ var FakeHub = class {
320
+ network;
321
+ timers;
322
+ #links = /* @__PURE__ */ new Set();
323
+ #listeners = /* @__PURE__ */ new Set();
324
+ constructor(options = {}) {
325
+ this.network = options.network ?? new NetworkSwitch();
326
+ this.timers = options.clock ?? globalThis;
327
+ this.network.subscribe(() => {
328
+ if (this.network.isOnline) return;
329
+ for (const link of [...this.#links]) link.close(DROPPED);
330
+ });
331
+ }
332
+ /** The number of open connections. */
333
+ get connections() {
334
+ return this.#links.size;
335
+ }
336
+ /** A new client transport. It connects on `open()`. */
337
+ connect() {
338
+ return new Link(this).client;
339
+ }
340
+ /** Calls `listener` with the server end of each new connection. Returns a function that stops it. */
341
+ onConnection(listener) {
342
+ this.#listeners.add(listener);
343
+ return () => this.#listeners.delete(listener);
344
+ }
345
+ /** @internal */
346
+ accept(link) {
347
+ this.#links.add(link);
348
+ for (const listener of [...this.#listeners]) listener(link.server);
349
+ }
350
+ /** @internal */
351
+ release(link) {
352
+ this.#links.delete(link);
353
+ }
354
+ };
355
+ async function sizeOf(query) {
356
+ const box = await query.boundingBox();
357
+ return `${Math.round(box.width)}x${Math.round(box.height)}`;
358
+ }
359
+ var _AvatarStackHarness_decorators, _init2, _a2;
360
+ _AvatarStackHarness_decorators = [Harness({ host: testId("dovetail-avatar-stack") })];
361
+ var AvatarStackHarness = class extends (_a2 = DovetailHarness) {
362
+ /** The names of the visible avatars, in order. The local user has the name it has. */
363
+ async names() {
364
+ return this.#avatars().map((avatar) => avatar.attribute("data-name").then((name) => name ?? ""));
365
+ }
366
+ /** The status of each visible avatar: `online` or `away`. */
367
+ async statuses() {
368
+ return this.#avatars().map((avatar) => avatar.attribute("data-status").then((s) => s ?? ""));
369
+ }
370
+ /** The accessible label of each visible avatar, for example `Ben, away`. */
371
+ async labels() {
372
+ return this.elementBy(testId("dovetail-avatar-label")).texts();
373
+ }
374
+ /**
375
+ * The size of each accessible label on the screen, as `width x height` in whole pixels. A
376
+ * visually hidden label is `1x1` or smaller.
377
+ */
378
+ async labelSizes() {
379
+ return this.elementBy(testId("dovetail-avatar-label")).map((label) => sizeOf(label));
380
+ }
381
+ /**
382
+ * The image URL that each visible avatar gives to its image, in order. An empty string when the
383
+ * avatar has no image, for example when the URL policy refuses the URL of the peer.
384
+ */
385
+ async imageUrls() {
386
+ return this.#avatars().map((avatar) => avatar.attribute("data-avatar-url").then((url) => url ?? ""));
387
+ }
388
+ /** The number of people that the overflow count holds. 0 when it does not show. */
389
+ async overflow() {
390
+ return Number(await this.self.attribute("data-overflow"));
391
+ }
392
+ /** Puts the pointer on the avatar at `index`. Its tooltip opens. */
393
+ async hoverAvatar(index) {
394
+ await this.#avatars().nth(index).hover();
395
+ }
396
+ /** Moves the keyboard focus to the avatar at `index`. Its tooltip opens. */
397
+ async focusAvatar(index) {
398
+ await this.#avatars().nth(index).focus();
399
+ }
400
+ /** The text of the open tooltip. */
401
+ async tooltip() {
402
+ return this.elementBy(testId("dovetail-avatar-tooltip")).text();
403
+ }
404
+ #avatars() {
405
+ return this.elementBy(testId("dovetail-avatar"));
406
+ }
407
+ };
408
+ _init2 = __decoratorStart(_a2);
409
+ AvatarStackHarness = __decorateElement(_init2, 0, "AvatarStackHarness", _AvatarStackHarness_decorators, AvatarStackHarness);
410
+ __runInitializers(_init2, 1, AvatarStackHarness);
411
+ var _TypingHarness_decorators, _init3, _a3;
412
+ _TypingHarness_decorators = [Harness({ host: testId("dovetail-typing") })];
413
+ var TypingHarness = class extends (_a3 = DovetailHarness) {
414
+ };
415
+ _init3 = __decoratorStart(_a3);
416
+ TypingHarness = __decorateElement(_init3, 0, "TypingHarness", _TypingHarness_decorators, TypingHarness);
417
+ __runInitializers(_init3, 1, TypingHarness);
418
+ var _LiveCursorsHarness_decorators, _init4, _a4;
419
+ _LiveCursorsHarness_decorators = [Harness({ host: testId("dovetail-live-cursors") })];
420
+ var LiveCursorsHarness = class extends (_a4 = DovetailHarness) {
421
+ /** Puts the local pointer in the container. */
422
+ async pointIn() {
423
+ await this.self.hover();
424
+ }
425
+ /** The names on the remote pointers, in order. */
426
+ async cursorNames() {
427
+ return this.#cursors().texts();
428
+ }
429
+ /** The position of the pointer of `name`, as `x,y` fractions, or null with no such pointer. */
430
+ async position(name) {
431
+ const cursors = await this.#cursors().all();
432
+ for (const cursor of cursors) {
433
+ if (await cursor.text() !== name) continue;
434
+ return `${await cursor.attribute("data-x")},${await cursor.attribute("data-y")}`;
435
+ }
436
+ return null;
437
+ }
438
+ /** The color of each remote pointer (the `--dovetail-cursor` property), in order. */
439
+ async colors() {
440
+ return this.#cursors().map(async (cursor) => {
441
+ const style = await cursor.attribute("style") ?? "";
442
+ return /--dovetail-cursor:\s*([^;]*)/.exec(style)?.[1]?.trim() ?? "";
443
+ });
444
+ }
445
+ #cursors() {
446
+ return this.elementBy(testId("dovetail-cursor"));
447
+ }
448
+ };
449
+ _init4 = __decoratorStart(_a4);
450
+ LiveCursorsHarness = __decorateElement(_init4, 0, "LiveCursorsHarness", _LiveCursorsHarness_decorators, LiveCursorsHarness);
451
+ __runInitializers(_init4, 1, LiveCursorsHarness);
452
+ var _DeadLettersHarness_decorators, _init5, _a5;
453
+ _DeadLettersHarness_decorators = [Harness({ host: testId("dovetail-dead-letters") })];
454
+ var DeadLettersHarness = class extends (_a5 = DovetailHarness) {
455
+ /** The text of the hidden live region, for example `1 change failed`. Empty with no failures. */
456
+ async summary() {
457
+ return (await this.#summary().text()).trim();
458
+ }
459
+ /** The size of the hidden live region on the screen, as `width x height`. Hidden is `1x1`. */
460
+ async summarySize() {
461
+ return sizeOf(this.#summary());
462
+ }
463
+ #summary() {
464
+ return this.elementBy(testId("dovetail-dead-letters-summary"));
465
+ }
466
+ /** The name of each failed write, for example `Save note 1`. */
467
+ async titles() {
468
+ return this.elementBy(testId("dovetail-dead-letter-title")).texts();
469
+ }
470
+ /** Why the server refused each write. */
471
+ async reasons() {
472
+ return this.elementBy(testId("dovetail-dead-letter-reason")).texts();
473
+ }
474
+ /** Sends the write at `index` again. */
475
+ async retry(index) {
476
+ await this.elementBy(testId("dovetail-retry")).nth(index).click();
477
+ }
478
+ /** Removes the write at `index`. Its change rolls back. */
479
+ async discard(index) {
480
+ await this.elementBy(testId("dovetail-discard")).nth(index).click();
481
+ }
482
+ };
483
+ _init5 = __decoratorStart(_a5);
484
+ DeadLettersHarness = __decorateElement(_init5, 0, "DeadLettersHarness", _DeadLettersHarness_decorators, DeadLettersHarness);
485
+ __runInitializers(_init5, 1, DeadLettersHarness);
486
+ var _ConnectionBadgeHarness_decorators, _init6, _a6;
487
+ _ConnectionBadgeHarness_decorators = [Harness({ host: testId("dovetail-connection-badge") })];
488
+ var ConnectionBadgeHarness = class extends (_a6 = DovetailHarness) {
489
+ /** The number of queued writes that the badge shows. */
490
+ async queued() {
491
+ return Number(await this.self.attribute("data-queued"));
492
+ }
493
+ };
494
+ _init6 = __decoratorStart(_a6);
495
+ ConnectionBadgeHarness = __decorateElement(_init6, 0, "ConnectionBadgeHarness", _ConnectionBadgeHarness_decorators, ConnectionBadgeHarness);
496
+ __runInitializers(_init6, 1, ConnectionBadgeHarness);
497
+ var _SyncStatusHarness_decorators, _init7, _a7;
498
+ _SyncStatusHarness_decorators = [Harness({ host: testId("dovetail-sync-status") })];
499
+ var SyncStatusHarness = class extends (_a7 = DovetailHarness) {
500
+ };
501
+ _init7 = __decoratorStart(_a7);
502
+ SyncStatusHarness = __decorateElement(_init7, 0, "SyncStatusHarness", _SyncStatusHarness_decorators, SyncStatusHarness);
503
+ __runInitializers(_init7, 1, SyncStatusHarness);
504
+ var _EditorHarness_decorators, _init8, _a8;
505
+ _EditorHarness_decorators = [Harness({ host: testId("dovetail-editor") })];
506
+ var EditorHarness = class extends (_a8 = DovetailHarness) {
507
+ /** Replaces the content of the editor with `text`, as a user who types it. */
508
+ async type(text) {
509
+ await this.#content().fill(text);
510
+ }
511
+ /** The text of the editor. The name labels of the remote carets are in it too. */
512
+ async content() {
513
+ return (await this.#content().text()).trim();
514
+ }
515
+ /** The names of the peers whose caret the editor shows. */
516
+ async carets() {
517
+ const names = await this.self.attribute("data-carets") ?? "";
518
+ return names === "" ? [] : names.split(", ");
519
+ }
520
+ #content() {
521
+ return this.elementBy(testId("dovetail-editor-content"));
522
+ }
523
+ };
524
+ _init8 = __decoratorStart(_a8);
525
+ EditorHarness = __decorateElement(_init8, 0, "EditorHarness", _EditorHarness_decorators, EditorHarness);
526
+ __runInitializers(_init8, 1, EditorHarness);
527
+ var _DemoPaneHarness_decorators, _init9, _a9;
528
+ _DemoPaneHarness_decorators = [Harness({ host: testId("demo-pane") })];
529
+ var DemoPaneHarness = class extends (_a9 = DovetailHarness) {
530
+ /** True when the offline switch of the pane is on. */
531
+ async isOffline() {
532
+ return await this.#offline().attribute("aria-checked") === "true";
533
+ }
534
+ /** Turns on the offline switch. It does nothing when the pane is offline. */
535
+ async goOffline() {
536
+ if (!await this.isOffline()) await this.#offline().click();
537
+ }
538
+ /** Turns off the offline switch. It does nothing when the pane is online. */
539
+ async goOnline() {
540
+ if (await this.isOffline()) await this.#offline().click();
541
+ }
542
+ /** Types `text` in the comment field and sends the form. */
543
+ async comment(text) {
544
+ await this.elementBy(testId("demo-comment-input")).fill(text);
545
+ await this.elementBy(testId("demo-comment-submit")).click();
546
+ }
547
+ #offline() {
548
+ return this.elementBy(testId("demo-offline"));
549
+ }
550
+ };
551
+ _init9 = __decoratorStart(_a9);
552
+ DemoPaneHarness = __decorateElement(_init9, 0, "DemoPaneHarness", _DemoPaneHarness_decorators, DemoPaneHarness);
553
+ __runInitializers(_init9, 1, DemoPaneHarness);
554
+ var _loadOlderButton_dec, _texts_dec, _a10, _ActivityFeedHarness_decorators, _init10, _texts, _loadOlderButton;
555
+ _ActivityFeedHarness_decorators = [Harness({ host: testId("dovetail-activity-feed") })];
556
+ var ActivityFeedHarness = class extends (_a10 = DovetailHarness, _texts_dec = [ByTestId("dovetail-activity-text")], _loadOlderButton_dec = [ByTestId("dovetail-load-older")], _a10) {
557
+ constructor() {
558
+ super(...arguments);
559
+ __privateAdd(this, _texts, __runInitializers(_init10, 8, this)), __runInitializers(_init10, 11, this);
560
+ __privateAdd(this, _loadOlderButton, __runInitializers(_init10, 12, this)), __runInitializers(_init10, 15, this);
561
+ }
562
+ /** The texts of the groups, the newest first, as "ana edited 3 notes". */
563
+ async groups() {
564
+ return (await this.texts.texts()).map((text) => text.trim());
565
+ }
566
+ /** True when the "Load older" button is there. */
567
+ async hasMore() {
568
+ return !await this.loadOlderButton.isAbsent();
569
+ }
570
+ async loadOlder() {
571
+ await this.loadOlderButton.click();
572
+ }
573
+ };
574
+ _init10 = __decoratorStart(_a10);
575
+ _texts = new WeakMap();
576
+ _loadOlderButton = new WeakMap();
577
+ __decorateElement(_init10, 4, "texts", _texts_dec, ActivityFeedHarness, _texts);
578
+ __decorateElement(_init10, 4, "loadOlderButton", _loadOlderButton_dec, ActivityFeedHarness, _loadOlderButton);
579
+ ActivityFeedHarness = __decorateElement(_init10, 0, "ActivityFeedHarness", _ActivityFeedHarness_decorators, ActivityFeedHarness);
580
+ __runInitializers(_init10, 1, ActivityFeedHarness);
581
+ var _badge_dec, _a11, _InboxButtonHarness_decorators, _init11, _badge;
582
+ _InboxButtonHarness_decorators = [Harness({ host: testId("dovetail-inbox-button") })];
583
+ var InboxButtonHarness = class extends (_a11 = DovetailHarness, _badge_dec = [ByTestId("dovetail-unread-count")], _a11) {
584
+ constructor() {
585
+ super(...arguments);
586
+ __privateAdd(this, _badge, __runInitializers(_init11, 8, this)), __runInitializers(_init11, 11, this);
587
+ }
588
+ /** The unread count that the badge shows, as text. `0` when the badge is not there. */
589
+ async unread() {
590
+ return await this.badge.isAbsent() ? "0" : (await this.badge.text()).trim();
591
+ }
592
+ /** The accessible name of the button, as "Inbox, 3 unread". */
593
+ async label() {
594
+ return this.self.attribute("aria-label");
595
+ }
596
+ /** Presses the button. */
597
+ async click() {
598
+ await this.self.click();
599
+ }
600
+ };
601
+ _init11 = __decoratorStart(_a11);
602
+ _badge = new WeakMap();
603
+ __decorateElement(_init11, 4, "badge", _badge_dec, InboxButtonHarness, _badge);
604
+ InboxButtonHarness = __decorateElement(_init11, 0, "InboxButtonHarness", _InboxButtonHarness_decorators, InboxButtonHarness);
605
+ __runInitializers(_init11, 1, InboxButtonHarness);
606
+ var _archiveButton_dec, _markReadButton_dec, _body_dec, _a12, _NotificationRowHarness_decorators, _init12, _body, _markReadButton, _archiveButton;
607
+ _NotificationRowHarness_decorators = [Harness({ host: testId("dovetail-notification") })];
608
+ var NotificationRowHarness = class extends (_a12 = DovetailHarness, _body_dec = [ByTestId("dovetail-notification-text")], _markReadButton_dec = [ByTestId("dovetail-mark-read")], _archiveButton_dec = [ByTestId("dovetail-archive")], _a12) {
609
+ constructor() {
610
+ super(...arguments);
611
+ __privateAdd(this, _body, __runInitializers(_init12, 8, this)), __runInitializers(_init12, 11, this);
612
+ __privateAdd(this, _markReadButton, __runInitializers(_init12, 12, this)), __runInitializers(_init12, 15, this);
613
+ __privateAdd(this, _archiveButton, __runInitializers(_init12, 16, this)), __runInitializers(_init12, 19, this);
614
+ }
615
+ /** The text of the notification. */
616
+ async text() {
617
+ return (await this.body.text()).trim();
618
+ }
619
+ async markRead() {
620
+ await this.markReadButton.click();
621
+ }
622
+ async archive() {
623
+ await this.archiveButton.click();
624
+ }
625
+ /** True when the item has a "Mark as read" button. */
626
+ async canMarkRead() {
627
+ return !await this.markReadButton.isAbsent();
628
+ }
629
+ };
630
+ _init12 = __decoratorStart(_a12);
631
+ _body = new WeakMap();
632
+ _markReadButton = new WeakMap();
633
+ _archiveButton = new WeakMap();
634
+ __decorateElement(_init12, 4, "body", _body_dec, NotificationRowHarness, _body);
635
+ __decorateElement(_init12, 4, "markReadButton", _markReadButton_dec, NotificationRowHarness, _markReadButton);
636
+ __decorateElement(_init12, 4, "archiveButton", _archiveButton_dec, NotificationRowHarness, _archiveButton);
637
+ NotificationRowHarness = __decorateElement(_init12, 0, "NotificationRowHarness", _NotificationRowHarness_decorators, NotificationRowHarness);
638
+ __runInitializers(_init12, 1, NotificationRowHarness);
639
+ var _texts_dec2, _retryButton_dec, _errorState_dec, _emptyState_dec, _loadMoreButton_dec, _markAllButton_dec, _allTab_dec, _unreadTab_dec, _a13, _InboxHarness_decorators, _init13, _unreadTab, _allTab, _markAllButton, _loadMoreButton, _emptyState, _errorState, _retryButton, _texts2;
640
+ _InboxHarness_decorators = [Harness({ host: testId("dovetail-inbox") })];
641
+ var InboxHarness = class extends (_a13 = DovetailHarness, _unreadTab_dec = [ByRole("tab", { name: /^Unread/ })], _allTab_dec = [ByRole("tab", { name: /^All/ })], _markAllButton_dec = [ByTestId("dovetail-mark-all-read")], _loadMoreButton_dec = [ByTestId("dovetail-load-more")], _emptyState_dec = [ByTestId("dovetail-inbox-empty")], _errorState_dec = [ByTestId("dovetail-inbox-error")], _retryButton_dec = [ByTestId("dovetail-retry")], _texts_dec2 = [ByTestId("dovetail-notification-text")], _a13) {
642
+ constructor() {
643
+ super(...arguments);
644
+ __privateAdd(this, _unreadTab, __runInitializers(_init13, 8, this)), __runInitializers(_init13, 11, this);
645
+ __privateAdd(this, _allTab, __runInitializers(_init13, 12, this)), __runInitializers(_init13, 15, this);
646
+ __privateAdd(this, _markAllButton, __runInitializers(_init13, 16, this)), __runInitializers(_init13, 19, this);
647
+ __privateAdd(this, _loadMoreButton, __runInitializers(_init13, 20, this)), __runInitializers(_init13, 23, this);
648
+ __privateAdd(this, _emptyState, __runInitializers(_init13, 24, this)), __runInitializers(_init13, 27, this);
649
+ __privateAdd(this, _errorState, __runInitializers(_init13, 28, this)), __runInitializers(_init13, 31, this);
650
+ __privateAdd(this, _retryButton, __runInitializers(_init13, 32, this)), __runInitializers(_init13, 35, this);
651
+ __privateAdd(this, _texts2, __runInitializers(_init13, 36, this)), __runInitializers(_init13, 39, this);
652
+ }
653
+ /** The notification at `index` of the open tab. */
654
+ notification(index) {
655
+ return this.childHarness(NotificationRowHarness).nth(index);
656
+ }
657
+ /** The texts of the notifications of the open tab, top to bottom. */
658
+ async notifications() {
659
+ return (await this.texts.texts()).map((text) => text.trim());
660
+ }
661
+ /** The states (`unread` or `read`) of the notifications of the open tab. */
662
+ async states() {
663
+ return this.childHarness(NotificationRowHarness).map((row) => row.state());
664
+ }
665
+ /** The text of the selected tab, as "Unread 2" or "All". */
666
+ async selectedTab() {
667
+ const unread = await this.unreadTab.attribute("aria-selected") === "true";
668
+ return (await (unread ? this.unreadTab : this.allTab).text() ?? "").replace(/\s+/g, " ").trim();
669
+ }
670
+ /** Presses a key (as `ArrowRight`) on the selected tab. The arrow keys move between the tabs. */
671
+ async pressOnTab(key) {
672
+ const unread = await this.unreadTab.attribute("aria-selected") === "true";
673
+ const tab = unread ? this.unreadTab : this.allTab;
674
+ await tab.focus();
675
+ await tab.press(key);
676
+ }
677
+ /**
678
+ * The accessible name of the element with the keyboard focus (its `aria-label`, or else its
679
+ * text), or null when the focus is not in the inbox. Harnessed has no query for the focus, so
680
+ * this reads the document of the browser driver.
681
+ */
682
+ async focused() {
683
+ const active = globalThis.document?.activeElement;
684
+ if (!active?.closest("[data-test-dovetail-inbox]")) return null;
685
+ return (active.getAttribute("aria-label") ?? active.textContent ?? "").replace(/\s+/g, " ").trim();
686
+ }
687
+ async showUnread() {
688
+ await this.unreadTab.click();
689
+ }
690
+ async showAll() {
691
+ await this.allTab.click();
692
+ }
693
+ async markRead(index) {
694
+ await this.notification(index).markRead();
695
+ }
696
+ async archive(index) {
697
+ await this.notification(index).archive();
698
+ }
699
+ async markAllRead() {
700
+ await this.markAllButton.click();
701
+ }
702
+ /** True when "Mark all as read" can be pressed. */
703
+ async canMarkAllRead() {
704
+ return this.markAllButton.isEnabled();
705
+ }
706
+ /** True when the "Load more" button is there. */
707
+ async hasMore() {
708
+ return !await this.loadMoreButton.isAbsent();
709
+ }
710
+ async loadMore() {
711
+ await this.loadMoreButton.click();
712
+ }
713
+ /** The text of the empty state, or null when it is not there. */
714
+ async emptyText() {
715
+ return await this.emptyState.isAbsent() ? null : (await this.emptyState.text()).trim();
716
+ }
717
+ /** The text of the error state, or null when it is not there. */
718
+ async errorText() {
719
+ if (await this.errorState.isAbsent()) return null;
720
+ return (await this.errorState.text()).replace(/\s+/g, " ").trim();
721
+ }
722
+ async retry() {
723
+ await this.retryButton.click();
724
+ }
725
+ };
726
+ _init13 = __decoratorStart(_a13);
727
+ _unreadTab = new WeakMap();
728
+ _allTab = new WeakMap();
729
+ _markAllButton = new WeakMap();
730
+ _loadMoreButton = new WeakMap();
731
+ _emptyState = new WeakMap();
732
+ _errorState = new WeakMap();
733
+ _retryButton = new WeakMap();
734
+ _texts2 = new WeakMap();
735
+ __decorateElement(_init13, 4, "unreadTab", _unreadTab_dec, InboxHarness, _unreadTab);
736
+ __decorateElement(_init13, 4, "allTab", _allTab_dec, InboxHarness, _allTab);
737
+ __decorateElement(_init13, 4, "markAllButton", _markAllButton_dec, InboxHarness, _markAllButton);
738
+ __decorateElement(_init13, 4, "loadMoreButton", _loadMoreButton_dec, InboxHarness, _loadMoreButton);
739
+ __decorateElement(_init13, 4, "emptyState", _emptyState_dec, InboxHarness, _emptyState);
740
+ __decorateElement(_init13, 4, "errorState", _errorState_dec, InboxHarness, _errorState);
741
+ __decorateElement(_init13, 4, "retryButton", _retryButton_dec, InboxHarness, _retryButton);
742
+ __decorateElement(_init13, 4, "texts", _texts_dec2, InboxHarness, _texts2);
743
+ InboxHarness = __decorateElement(_init13, 0, "InboxHarness", _InboxHarness_decorators, InboxHarness);
744
+ __runInitializers(_init13, 1, InboxHarness);
745
+ var _items_dec, _a14, _ToastBridgeHarness_decorators, _init14, _items;
746
+ _ToastBridgeHarness_decorators = [Harness({ host: role("region", { name: /^Notifications/ }) })];
747
+ var ToastBridgeHarness = class extends (_a14 = DovetailHarness, _items_dec = [ByRole("listitem")], _a14) {
748
+ constructor() {
749
+ super(...arguments);
750
+ __privateAdd(this, _items, __runInitializers(_init14, 8, this)), __runInitializers(_init14, 11, this);
751
+ }
752
+ /** The text of each toast, the newest first. */
753
+ async toasts() {
754
+ if (await this.isAbsent()) return [];
755
+ return (await this.items.texts()).map((text) => text.replace(/\s+/g, " ").trim());
756
+ }
757
+ /** The type of each toast (`default`, `success`, `warning` or `error`), the newest first. */
758
+ async types() {
759
+ if (await this.isAbsent()) return [];
760
+ return this.items.map((item) => item.attribute("data-type"));
761
+ }
762
+ };
763
+ _init14 = __decoratorStart(_a14);
764
+ _items = new WeakMap();
765
+ __decorateElement(_init14, 4, "items", _items_dec, ToastBridgeHarness, _items);
766
+ ToastBridgeHarness = __decorateElement(_init14, 0, "ToastBridgeHarness", _ToastBridgeHarness_decorators, ToastBridgeHarness);
767
+ __runInitializers(_init14, 1, ToastBridgeHarness);
768
+ var _InspectorHarness_decorators, _init15, _a15;
769
+ _InspectorHarness_decorators = [Harness({ host: testId("dovetail-inspector") })];
770
+ var InspectorHarness = class extends (_a15 = DovetailHarness) {
771
+ /** Each transition of the connection, oldest first: `connect: idle → connecting`. */
772
+ async history() {
773
+ return this.elementBy(testId("dovetail-inspector-transition")).texts();
774
+ }
775
+ /**
776
+ * Each room of the connection, with its feed cursor and its holders: `note:1 @ 3 (2 holders)`
777
+ * (or `note:1 (1 holder)`).
778
+ */
779
+ async rooms() {
780
+ return this.elementBy(testId("dovetail-inspector-room")).texts();
781
+ }
782
+ /** The number of holders of each room (`Connection.holders`), in the order of `rooms()`. */
783
+ async holders() {
784
+ const rooms = await this.elementBy(testId("dovetail-inspector-room")).all();
785
+ return Promise.all(rooms.map(async (room) => Number(await room.attribute("data-holders"))));
786
+ }
787
+ /** The number of writes in the queue. */
788
+ async queued() {
789
+ return Number(await this.self.attribute("data-queued"));
790
+ }
791
+ /** Each dead letter: `upsert note 1 (422): The title is empty`. */
792
+ async deadLetters() {
793
+ return this.elementBy(testId("dovetail-inspector-dead-letter")).texts();
794
+ }
795
+ /** Each ledger error: `upsert note 1 (422): The title is empty`. */
796
+ async errors() {
797
+ return this.elementBy(testId("dovetail-inspector-error")).texts();
798
+ }
799
+ /** Each peer of each presence room: `board:1: Ben (online)`. */
800
+ async peers() {
801
+ return this.elementBy(testId("dovetail-inspector-peer")).texts();
802
+ }
803
+ /** Each document: `note:1 body: synced` or `note:1 body: syncing`. */
804
+ async docs() {
805
+ return this.elementBy(testId("dovetail-inspector-doc")).texts();
806
+ }
807
+ };
808
+ _init15 = __decoratorStart(_a15);
809
+ InspectorHarness = __decorateElement(_init15, 0, "InspectorHarness", _InspectorHarness_decorators, InspectorHarness);
810
+ __runInitializers(_init15, 1, InspectorHarness);
811
+
812
+ export { ActivityFeedHarness, AvatarStackHarness, ConnectionBadgeHarness, DeadLettersHarness, DemoPaneHarness, DovetailHarness, EditorHarness, FakeClock, FakeHub, InboxButtonHarness, InboxHarness, InspectorHarness, LiveCursorsHarness, NetworkSwitch, NotificationRowHarness, SyncStatusHarness, ToastBridgeHarness, TypingHarness, installFakeIndexedDB };
813
+ //# sourceMappingURL=index.js.map
814
+ //# sourceMappingURL=index.js.map