twd-js 1.6.3 → 1.6.5
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/bundled.es.js +301 -301
- package/dist/index.cjs.js +33 -33
- package/dist/index.d.ts +624 -0
- package/dist/index.es.js +1474 -1427
- package/dist/mock-sw.js +1 -1
- package/dist/runner-ci.d.ts +27 -0
- package/dist/runner.d.ts +62 -0
- package/dist/ui.d.ts +9 -0
- package/dist/vite-plugin.d.ts +66 -0
- package/package.json +2 -2
- /package/dist/{src/bundled.d.ts → bundled.d.ts} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,625 @@
|
|
|
1
|
+
import { configure } from '@testing-library/dom';
|
|
2
|
+
import { default as default_2 } from '@testing-library/user-event';
|
|
3
|
+
import { expect } from 'chai';
|
|
4
|
+
import { JSX } from 'react/jsx-runtime';
|
|
5
|
+
import { screen as screen_2 } from '@testing-library/dom';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* All assertion names, including negated ones.
|
|
9
|
+
*/
|
|
10
|
+
declare type AnyAssertion = Negatable_2<AssertionName>;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* All assertion names, including negated ones.
|
|
14
|
+
*/
|
|
15
|
+
declare type AnyURLAssertion = Negatable<URLAssertionName>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Maps assertion name to its argument tuple.
|
|
19
|
+
*/
|
|
20
|
+
declare type ArgsFor<A extends AnyAssertion> = A extends `not.${infer Base extends AssertionName}` ? AssertionArgs[Base] : A extends AssertionName ? AssertionArgs[A] : never;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Argument types for each assertion.
|
|
24
|
+
*/
|
|
25
|
+
declare type AssertionArgs = {
|
|
26
|
+
"have.text": [expected: string];
|
|
27
|
+
"contain.text": [expected: string];
|
|
28
|
+
"be.empty": [];
|
|
29
|
+
"have.attr": [attr: string, value: string];
|
|
30
|
+
"have.value": [value: string];
|
|
31
|
+
"be.disabled": [];
|
|
32
|
+
"be.enabled": [];
|
|
33
|
+
"be.checked": [];
|
|
34
|
+
"be.selected": [];
|
|
35
|
+
"be.focused": [];
|
|
36
|
+
"be.visible": [];
|
|
37
|
+
"have.class": [className: string];
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Types and interfaces for the TWD testing library.
|
|
42
|
+
*
|
|
43
|
+
* @module twd-types
|
|
44
|
+
*/
|
|
45
|
+
/**
|
|
46
|
+
* All supported assertion names for the `should` function.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* api.should("have.text", "Hello");
|
|
50
|
+
* api.should("be.empty");
|
|
51
|
+
*/
|
|
52
|
+
declare type AssertionName = "have.text" | "contain.text" | "be.empty" | "have.attr" | "have.value" | "be.disabled" | "be.enabled" | "be.checked" | "be.selected" | "be.focused" | "be.visible" | "have.class";
|
|
53
|
+
|
|
54
|
+
export declare const configureScreenDom: typeof configure;
|
|
55
|
+
|
|
56
|
+
export declare const defaultTheme: TWDTheme;
|
|
57
|
+
|
|
58
|
+
export { expect }
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Initialize Vite test loading.
|
|
62
|
+
* @param testModules - The test modules to load.
|
|
63
|
+
* @param component - The React component to render the sidebar.
|
|
64
|
+
* @param createRoot - Function to create a React root.
|
|
65
|
+
* @param theme - Optional theme customization
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* if (import.meta.env.DEV) {
|
|
69
|
+
* const testModules = import.meta.glob("./example.twd.test.ts");
|
|
70
|
+
* const { initTests, TWDSidebar } = await import('twd-js');
|
|
71
|
+
* await initTests(testModules, <TWDSidebar open={true} position="left" />, createRoot, {
|
|
72
|
+
* primary: '#ff0000',
|
|
73
|
+
* background: '#ffffff'
|
|
74
|
+
* });
|
|
75
|
+
* }
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare const initTests: (testModules: TestModule, Component: React.ReactNode, createRoot: (el: HTMLElement) => {
|
|
79
|
+
render: (el: React.ReactNode) => void;
|
|
80
|
+
}, theme?: Partial<TWDTheme>) => Promise<void>;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Injects theme CSS variables into the document
|
|
84
|
+
* This should be called once when the sidebar is initialized
|
|
85
|
+
*/
|
|
86
|
+
export declare function injectTheme(theme?: Partial<TWDTheme>): void;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Negatable assertion names (e.g., 'not.have.text').
|
|
90
|
+
*/
|
|
91
|
+
declare type Negatable<T extends string> = T | `not.${T}`;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Negatable assertion names (e.g., 'not.have.text').
|
|
95
|
+
*/
|
|
96
|
+
declare type Negatable_2<T extends string> = T | `not.${T}`;
|
|
97
|
+
|
|
98
|
+
declare interface Options {
|
|
99
|
+
/** HTTP method to match (e.g. `"GET"`, `"POST"`). */
|
|
100
|
+
method: string;
|
|
101
|
+
/** URL string or RegExp to match against the request URL. */
|
|
102
|
+
url: string | RegExp;
|
|
103
|
+
/** The mocked response body returned to the client. */
|
|
104
|
+
response: unknown;
|
|
105
|
+
/** HTTP status code for the mocked response (default: `200`). */
|
|
106
|
+
status?: number;
|
|
107
|
+
/** Headers to include in the mocked response. */
|
|
108
|
+
responseHeaders?: Record<string, string>;
|
|
109
|
+
/** Whether the `url` field should be treated as a regex pattern. */
|
|
110
|
+
urlRegex?: boolean;
|
|
111
|
+
/** Delay in milliseconds before returning the mocked response. */
|
|
112
|
+
delay?: number;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
declare type Rule = {
|
|
116
|
+
/** HTTP method to match (e.g. `"GET"`, `"POST"`). */
|
|
117
|
+
method: string;
|
|
118
|
+
/** URL string or RegExp to match against the request URL. */
|
|
119
|
+
url: string | RegExp;
|
|
120
|
+
/** The mocked response body returned to the client. */
|
|
121
|
+
response: unknown;
|
|
122
|
+
/** Unique identifier for this mock rule, used with `waitForRequest`. */
|
|
123
|
+
alias: string;
|
|
124
|
+
/** Whether this rule has been matched by an actual request. Set automatically by the service worker. */
|
|
125
|
+
executed?: boolean;
|
|
126
|
+
/**
|
|
127
|
+
* The parsed request body sent by the client.
|
|
128
|
+
* For JSON requests this is the parsed object, for form data an object of key/value pairs, for text a string.
|
|
129
|
+
* Access fields directly: `rule.request.email`, **not** `rule.request.body.email`.
|
|
130
|
+
*/
|
|
131
|
+
request?: any;
|
|
132
|
+
/** HTTP status code for the mocked response (default: `200`). */
|
|
133
|
+
status?: number;
|
|
134
|
+
/** Headers to include in the mocked response. */
|
|
135
|
+
responseHeaders?: Record<string, string>;
|
|
136
|
+
/** Whether the `url` field should be treated as a regex pattern. */
|
|
137
|
+
urlRegex?: boolean;
|
|
138
|
+
/** Delay in milliseconds before returning the mocked response. */
|
|
139
|
+
delay?: number;
|
|
140
|
+
/** Number of times this rule has been matched. Updated automatically by the service worker. */
|
|
141
|
+
hitCount?: number;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
declare type ScreenDom = typeof screen_2;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* screenDom - Scoped queries that exclude the TWD sidebar
|
|
148
|
+
*
|
|
149
|
+
* Searches only within the main app container (typically #root).
|
|
150
|
+
* Use this for most queries to avoid matching elements in the sidebar.
|
|
151
|
+
*
|
|
152
|
+
* Note: This will NOT find portal-rendered elements (modals, dialogs) that are
|
|
153
|
+
* rendered outside the root container. For portals, use `screenDomGlobal` instead.
|
|
154
|
+
*/
|
|
155
|
+
export declare const screenDom: ScreenDom;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* screenDomGlobal - Global queries that search the entire document.body
|
|
159
|
+
*
|
|
160
|
+
* Searches all elements in document.body, including portal-rendered elements
|
|
161
|
+
* (modals, dialogs, tooltips, etc.).
|
|
162
|
+
*
|
|
163
|
+
* ⚠️ WARNING: This may also match elements inside the TWD sidebar if your selectors
|
|
164
|
+
* are not specific enough. Use more specific queries (e.g., getByRole with name)
|
|
165
|
+
* to avoid matching sidebar elements.
|
|
166
|
+
*
|
|
167
|
+
* Use this when:
|
|
168
|
+
* - Querying portal-rendered elements (modals, dialogs)
|
|
169
|
+
* - You need to search outside the root container
|
|
170
|
+
*
|
|
171
|
+
* Example:
|
|
172
|
+
* ```ts
|
|
173
|
+
* // For a modal rendered via portal
|
|
174
|
+
* const modal = screenDomGlobal.getByRole('dialog', { name: 'Confirm' });
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
export declare const screenDomGlobal: ScreenDom;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Overloads for the `should` function, for best IntelliSense.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* twd.should("have.text", "Hello");
|
|
184
|
+
* twd.should("be.empty");
|
|
185
|
+
* twd.should("have.class", "active");
|
|
186
|
+
*/
|
|
187
|
+
declare type ShouldFn = {
|
|
188
|
+
(name: "have.text", expected: string): TWDElemAPI;
|
|
189
|
+
(name: "not.have.text", expected: string): TWDElemAPI;
|
|
190
|
+
(name: "contain.text", expected: string): TWDElemAPI;
|
|
191
|
+
(name: "not.contain.text", expected: string): TWDElemAPI;
|
|
192
|
+
(name: "be.empty"): TWDElemAPI;
|
|
193
|
+
(name: "not.be.empty"): TWDElemAPI;
|
|
194
|
+
(name: "have.attr", attr: string, value: string): TWDElemAPI;
|
|
195
|
+
(name: "not.have.attr", attr: string, value: string): TWDElemAPI;
|
|
196
|
+
(name: "have.value", value: string): TWDElemAPI;
|
|
197
|
+
(name: "not.have.value", value: string): TWDElemAPI;
|
|
198
|
+
(name: "be.disabled"): TWDElemAPI;
|
|
199
|
+
(name: "not.be.disabled"): TWDElemAPI;
|
|
200
|
+
(name: "be.enabled"): TWDElemAPI;
|
|
201
|
+
(name: "not.be.enabled"): TWDElemAPI;
|
|
202
|
+
(name: "be.checked"): TWDElemAPI;
|
|
203
|
+
(name: "not.be.checked"): TWDElemAPI;
|
|
204
|
+
(name: "be.selected"): TWDElemAPI;
|
|
205
|
+
(name: "not.be.selected"): TWDElemAPI;
|
|
206
|
+
(name: "be.focused"): TWDElemAPI;
|
|
207
|
+
(name: "not.be.focused"): TWDElemAPI;
|
|
208
|
+
(name: "be.visible"): TWDElemAPI;
|
|
209
|
+
(name: "not.be.visible"): TWDElemAPI;
|
|
210
|
+
(name: "have.class", className: string): TWDElemAPI;
|
|
211
|
+
(name: "not.have.class", className: string): TWDElemAPI;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* A record of test module paths to their loader functions.
|
|
216
|
+
* Each function returns a promise that resolves when the module is loaded.
|
|
217
|
+
* This is typically used with Vite's `import.meta.glob` to dynamically import test modules.
|
|
218
|
+
* @example
|
|
219
|
+
* ```ts
|
|
220
|
+
* const testModules = {
|
|
221
|
+
* './test1.twd.test.ts': () => import('./test1.twd.test.ts'),
|
|
222
|
+
* './test2.twd.test.ts': () => import('./test2.twd.test.ts'),
|
|
223
|
+
* };
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
declare type TestModule = Record<string, () => Promise<unknown>>;
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Mini Cypress-style helpers for DOM testing.
|
|
230
|
+
* @namespace twd
|
|
231
|
+
*/
|
|
232
|
+
export declare const twd: TWDAPI;
|
|
233
|
+
|
|
234
|
+
declare interface TWDAPI {
|
|
235
|
+
/**
|
|
236
|
+
* Finds an element by selector and returns the TWD API for it.
|
|
237
|
+
* @param selector CSS selector
|
|
238
|
+
* @returns {Promise<TWDElemAPI>} The TWD API for the element
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```ts
|
|
242
|
+
* const btn = await twd.get("button");
|
|
243
|
+
*
|
|
244
|
+
* ```
|
|
245
|
+
*
|
|
246
|
+
*/
|
|
247
|
+
get: (selector: string) => Promise<TWDElemAPI>;
|
|
248
|
+
/**
|
|
249
|
+
* Sets the value of an input element and dispatches an input event. We recommend using this only for range, color, time inputs.
|
|
250
|
+
* @param el The input element
|
|
251
|
+
* @param value The value to set
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* ```ts
|
|
255
|
+
* const input = await twd.get("input[type='time']");
|
|
256
|
+
* twd.setInputValue(input.el, "13:30");
|
|
257
|
+
*
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
setInputValue: (el: Element, value: string) => void;
|
|
261
|
+
/**
|
|
262
|
+
* Finds multiple elements by selector and returns an array of TWD APIs for them.
|
|
263
|
+
* @param selector CSS selector
|
|
264
|
+
* @returns {Promise<TWDElemAPI[]>} Array of TWD APIs for the elements
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* ```ts
|
|
268
|
+
* const items = await twd.getAll(".item");
|
|
269
|
+
* items.at(0).should("be.visible");
|
|
270
|
+
* items.at(1).should("contain.text", "Hello");
|
|
271
|
+
* expect(items).to.have.length(3);
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
274
|
+
getAll: (selector: string) => Promise<TWDElemAPI[]>;
|
|
275
|
+
/**
|
|
276
|
+
* Simulates visiting a URL (SPA navigation).
|
|
277
|
+
* @param url The URL to visit
|
|
278
|
+
* @param [reload] Whether to force a reload even if already on the URL (optional)
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* ```ts
|
|
282
|
+
* twd.visit("/contact");
|
|
283
|
+
* // visit with reload
|
|
284
|
+
* twd.visit("/contact", true);
|
|
285
|
+
* ```
|
|
286
|
+
*/
|
|
287
|
+
visit: (url: string, reload?: boolean) => Promise<void>;
|
|
288
|
+
/**
|
|
289
|
+
* Mock a network request.
|
|
290
|
+
*
|
|
291
|
+
* @param alias Identifier for the mock rule. Useful for `waitFor()`.
|
|
292
|
+
* @param options Options to configure the mock:
|
|
293
|
+
* - `method`: HTTP method ("GET", "POST", …)
|
|
294
|
+
* - `url`: URL string or RegExp to match
|
|
295
|
+
* - `response`: Body of the mocked response
|
|
296
|
+
* - `status`: (optional) HTTP status code (default: 200)
|
|
297
|
+
* - `responseHeaders`: (optional) Response headers
|
|
298
|
+
* - `delay`: (optional) Delay in ms before returning the response
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
* ```ts
|
|
302
|
+
* mockRequest("getUser", {
|
|
303
|
+
* method: "GET",
|
|
304
|
+
* url: /\/api\/user\/\d+/,
|
|
305
|
+
* response: { id: 1, name: "Kevin" },
|
|
306
|
+
* status: 200,
|
|
307
|
+
* responseHeaders: { "x-mock": "true" }
|
|
308
|
+
* });
|
|
309
|
+
* ```
|
|
310
|
+
*/
|
|
311
|
+
mockRequest: (alias: string, options: Options) => Promise<void>;
|
|
312
|
+
/**
|
|
313
|
+
* Wait for a mocked request to be made.
|
|
314
|
+
* @param alias The alias of the mock rule to wait for
|
|
315
|
+
* @param retries The number of retries to make
|
|
316
|
+
* @param retryDelay The delay between retries
|
|
317
|
+
* @return The matched rule (with body if applicable)
|
|
318
|
+
*
|
|
319
|
+
* @example
|
|
320
|
+
* ```ts
|
|
321
|
+
* const rule = await twd.waitFor("aliasId");
|
|
322
|
+
* console.log(rule.body);
|
|
323
|
+
* const rule = await twd.waitFor("aliasId", 5, 100);
|
|
324
|
+
* console.log(rule.body);
|
|
325
|
+
*
|
|
326
|
+
* ```
|
|
327
|
+
*/
|
|
328
|
+
waitForRequest: (alias: string, retries?: number, retryDelay?: number) => Promise<Rule>;
|
|
329
|
+
/**
|
|
330
|
+
* wait for a list of mocked requests to be made.
|
|
331
|
+
* @param aliases The aliases of the mock rules to wait for
|
|
332
|
+
* @returns The matched rules (with body if applicable)
|
|
333
|
+
* @example
|
|
334
|
+
* ```ts
|
|
335
|
+
* const rules = await waitForRequests(["getUser", "postComment"]);
|
|
336
|
+
* ```
|
|
337
|
+
*/
|
|
338
|
+
waitForRequests: (aliases: string[]) => Promise<Rule[]>;
|
|
339
|
+
/**
|
|
340
|
+
* URL-related assertions.
|
|
341
|
+
*
|
|
342
|
+
* @example
|
|
343
|
+
* ```ts
|
|
344
|
+
* twd.url().should("eq", "http://localhost:3000/contact");
|
|
345
|
+
* twd.url().should("contain.url", "/contact");
|
|
346
|
+
*
|
|
347
|
+
* ```
|
|
348
|
+
*/
|
|
349
|
+
url: () => URLCommandAPI;
|
|
350
|
+
/**
|
|
351
|
+
* Initializes request mocking (registers the service worker).
|
|
352
|
+
* @param [path] service worker absolute path (optional)
|
|
353
|
+
*
|
|
354
|
+
* @example
|
|
355
|
+
* ```ts
|
|
356
|
+
* await twd.initRequestMocking();
|
|
357
|
+
* // init with custom service worker path
|
|
358
|
+
* await twd.initRequestMocking('/test-path/mock-sw.js');
|
|
359
|
+
* ```
|
|
360
|
+
*/
|
|
361
|
+
initRequestMocking: (path?: string) => Promise<void>;
|
|
362
|
+
/**
|
|
363
|
+
* Clears all request mock rules.
|
|
364
|
+
*
|
|
365
|
+
* @example
|
|
366
|
+
* ```ts
|
|
367
|
+
* twd.clearRequestMockRules();
|
|
368
|
+
*
|
|
369
|
+
* ```
|
|
370
|
+
*/
|
|
371
|
+
clearRequestMockRules: () => void;
|
|
372
|
+
/**
|
|
373
|
+
* Gets all current request mock rules.
|
|
374
|
+
*
|
|
375
|
+
* @example
|
|
376
|
+
* ```ts
|
|
377
|
+
* const rules = twd.getRequestMockRules();
|
|
378
|
+
* console.log(rules);
|
|
379
|
+
* ```
|
|
380
|
+
*/
|
|
381
|
+
getRequestMockRules: () => Rule[];
|
|
382
|
+
/**
|
|
383
|
+
* Gets the number of times a specific mock rule was hit.
|
|
384
|
+
* @param alias The alias of the mock rule
|
|
385
|
+
* @returns The number of times the rule was matched
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* ```ts
|
|
389
|
+
* const count = twd.getRequestCount("getUser");
|
|
390
|
+
* expect(count).to.equal(2);
|
|
391
|
+
* ```
|
|
392
|
+
*/
|
|
393
|
+
getRequestCount: (alias: string) => number;
|
|
394
|
+
/**
|
|
395
|
+
* Gets a snapshot of all mock rule hit counts.
|
|
396
|
+
* @returns An object mapping rule aliases to their hit counts
|
|
397
|
+
*
|
|
398
|
+
* @example
|
|
399
|
+
* ```ts
|
|
400
|
+
* const counts = twd.getRequestCounts();
|
|
401
|
+
* expect(counts).to.deep.equal({ getUser: 2, listPosts: 1 });
|
|
402
|
+
* ```
|
|
403
|
+
*/
|
|
404
|
+
getRequestCounts: () => Record<string, number>;
|
|
405
|
+
/**
|
|
406
|
+
* Waits for a specified time.
|
|
407
|
+
* @param time Time in milliseconds to wait
|
|
408
|
+
* @returns A promise that resolves after the specified time
|
|
409
|
+
* @example
|
|
410
|
+
* ```ts
|
|
411
|
+
* await twd.wait(500); // wait for 500ms
|
|
412
|
+
* ```
|
|
413
|
+
*/
|
|
414
|
+
wait: (time: number) => Promise<void>;
|
|
415
|
+
/**
|
|
416
|
+
* Asserts something about the element.
|
|
417
|
+
* @param el The element to assert on
|
|
418
|
+
* @param name The name of the assertion.
|
|
419
|
+
* @param args Arguments for the assertion.
|
|
420
|
+
* @returns The same API for chaining.
|
|
421
|
+
* @example
|
|
422
|
+
* ```ts
|
|
423
|
+
* const button = await twd.get("button");
|
|
424
|
+
* const text = screenDom.getByText("Hello");
|
|
425
|
+
* twd.should(button.el, "have.text", "Hello");
|
|
426
|
+
* twd.should(text, "be.empty");
|
|
427
|
+
* twd.should(button.el, "have.class", "active");
|
|
428
|
+
* ```
|
|
429
|
+
*/
|
|
430
|
+
should: (el: Element, name: AnyAssertion, ...args: ArgsFor<AnyAssertion>) => void;
|
|
431
|
+
/**
|
|
432
|
+
* Mock a component.
|
|
433
|
+
* @param name The name of the component to mock
|
|
434
|
+
* @param component The component to mock
|
|
435
|
+
* @returns The mocked component
|
|
436
|
+
* @example
|
|
437
|
+
* ```ts
|
|
438
|
+
* twd.mockComponent("Button", Button);
|
|
439
|
+
* ```
|
|
440
|
+
*/
|
|
441
|
+
mockComponent: (name: string, component: React.ComponentType<any>) => void;
|
|
442
|
+
/**
|
|
443
|
+
* Clears all component mocks.
|
|
444
|
+
*
|
|
445
|
+
* @example
|
|
446
|
+
* ```ts
|
|
447
|
+
* twd.clearComponentMocks();
|
|
448
|
+
* ```
|
|
449
|
+
*/
|
|
450
|
+
clearComponentMocks: () => void;
|
|
451
|
+
/**
|
|
452
|
+
* Asserts that an element does not exist in the DOM.
|
|
453
|
+
* @param selector CSS selector of the element to check
|
|
454
|
+
* @returns A promise that resolves if the element does not exist, or rejects if it does
|
|
455
|
+
*
|
|
456
|
+
* @example
|
|
457
|
+
* ```ts
|
|
458
|
+
* await twd.notExists(".non-existent");
|
|
459
|
+
* ```
|
|
460
|
+
*/
|
|
461
|
+
notExists: (selector: string) => Promise<void>;
|
|
462
|
+
/**
|
|
463
|
+
* Simulates a viewport size by constraining body dimensions, overriding
|
|
464
|
+
* `window.innerWidth`/`window.innerHeight` and `window.matchMedia()`, and
|
|
465
|
+
* rewriting CSS `@media` rules to match the simulated dimensions.
|
|
466
|
+
* Call with no arguments to reset to the original viewport.
|
|
467
|
+
*
|
|
468
|
+
* @param width Viewport width in pixels
|
|
469
|
+
* @param height Viewport height in pixels (optional — omit to leave height unconstrained)
|
|
470
|
+
*
|
|
471
|
+
* @example
|
|
472
|
+
* ```ts
|
|
473
|
+
* twd.viewport(375, 667); // mobile
|
|
474
|
+
* twd.viewport(768); // tablet width, height unconstrained
|
|
475
|
+
* twd.viewport(); // reset
|
|
476
|
+
* ```
|
|
477
|
+
*/
|
|
478
|
+
viewport: (width?: number, height?: number) => void;
|
|
479
|
+
/**
|
|
480
|
+
* Resets the viewport to its original size (undoes a previous `twd.viewport()` call).
|
|
481
|
+
*
|
|
482
|
+
* @example
|
|
483
|
+
* ```ts
|
|
484
|
+
* twd.resetViewport();
|
|
485
|
+
* ```
|
|
486
|
+
*/
|
|
487
|
+
resetViewport: () => void;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* The main API returned by `twd.get()`.
|
|
492
|
+
*
|
|
493
|
+
* @example
|
|
494
|
+
* ```ts
|
|
495
|
+
* const btn = await twd.get("button");
|
|
496
|
+
* btn.should("have.text", "Clicked").click();
|
|
497
|
+
*
|
|
498
|
+
* ```
|
|
499
|
+
*
|
|
500
|
+
*/
|
|
501
|
+
declare interface TWDElemAPI {
|
|
502
|
+
/** The underlying DOM element. */
|
|
503
|
+
el: Element;
|
|
504
|
+
/**
|
|
505
|
+
* Asserts something about the element.
|
|
506
|
+
* @param name The name of the assertion.
|
|
507
|
+
* @param args Arguments for the assertion.
|
|
508
|
+
* @returns The same API for chaining.
|
|
509
|
+
*
|
|
510
|
+
* @example
|
|
511
|
+
* ```ts
|
|
512
|
+
* const btn = await twd.get("button");
|
|
513
|
+
* btn.should("have.text", "Click me").should("not.be.disabled");
|
|
514
|
+
*
|
|
515
|
+
* ```
|
|
516
|
+
*
|
|
517
|
+
*/
|
|
518
|
+
should: ShouldFn;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
export declare const TWDSidebar: ({ open, position, search }: TWDSidebarProps) => JSX.Element;
|
|
522
|
+
|
|
523
|
+
declare interface TWDSidebarProps {
|
|
524
|
+
/**
|
|
525
|
+
* Whether the sidebar is open by default
|
|
526
|
+
*/
|
|
527
|
+
open: boolean;
|
|
528
|
+
/**
|
|
529
|
+
* Sidebar position
|
|
530
|
+
* - left: Sidebar on the left side (default)
|
|
531
|
+
* - right: Sidebar on the right side
|
|
532
|
+
*
|
|
533
|
+
* @default "left"
|
|
534
|
+
*/
|
|
535
|
+
position?: "left" | "right";
|
|
536
|
+
/**
|
|
537
|
+
* Whether to show the search/filter input
|
|
538
|
+
*/
|
|
539
|
+
search?: boolean;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* TWD Theme Configuration
|
|
544
|
+
*
|
|
545
|
+
* This file defines CSS variables that can be customized by users
|
|
546
|
+
* to personalize their TWD UI experience.
|
|
547
|
+
*
|
|
548
|
+
* Users can override these variables by setting them in their CSS:
|
|
549
|
+
*
|
|
550
|
+
* ```css
|
|
551
|
+
* :root {
|
|
552
|
+
* --twd-primary: #2563eb;
|
|
553
|
+
* --twd-background: #1e293b;
|
|
554
|
+
* ... other variables
|
|
555
|
+
* }
|
|
556
|
+
*
|
|
557
|
+
*/
|
|
558
|
+
export declare interface TWDTheme {
|
|
559
|
+
primary: string;
|
|
560
|
+
background: string;
|
|
561
|
+
backgroundSecondary: string;
|
|
562
|
+
border: string;
|
|
563
|
+
borderLight: string;
|
|
564
|
+
text: string;
|
|
565
|
+
textSecondary: string;
|
|
566
|
+
textMuted: string;
|
|
567
|
+
describeBg: string;
|
|
568
|
+
describeText: string;
|
|
569
|
+
describeBorder: string;
|
|
570
|
+
success: string;
|
|
571
|
+
successBg: string;
|
|
572
|
+
error: string;
|
|
573
|
+
errorBg: string;
|
|
574
|
+
warning: string;
|
|
575
|
+
warningBg: string;
|
|
576
|
+
skip: string;
|
|
577
|
+
skipBg: string;
|
|
578
|
+
buttonPrimary: string;
|
|
579
|
+
buttonPrimaryText: string;
|
|
580
|
+
buttonSecondary: string;
|
|
581
|
+
buttonSecondaryText: string;
|
|
582
|
+
buttonBorder: string;
|
|
583
|
+
spacingXs: string;
|
|
584
|
+
spacingSm: string;
|
|
585
|
+
spacingMd: string;
|
|
586
|
+
spacingLg: string;
|
|
587
|
+
spacingXl: string;
|
|
588
|
+
fontSizeXs: string;
|
|
589
|
+
fontSizeSm: string;
|
|
590
|
+
fontSizeMd: string;
|
|
591
|
+
fontSizeLg: string;
|
|
592
|
+
fontWeightNormal: string;
|
|
593
|
+
fontWeightMedium: string;
|
|
594
|
+
fontWeightBold: string;
|
|
595
|
+
sidebarWidth: string;
|
|
596
|
+
borderRadius: string;
|
|
597
|
+
borderRadiusLg: string;
|
|
598
|
+
shadow: string;
|
|
599
|
+
shadowSm: string;
|
|
600
|
+
zIndexSidebar: string;
|
|
601
|
+
zIndexSticky: string;
|
|
602
|
+
animationDuration: string;
|
|
603
|
+
iconColor: string;
|
|
604
|
+
iconColorSecondary: string;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* All supported assertion names for the `should` function in url command
|
|
609
|
+
*
|
|
610
|
+
* @example
|
|
611
|
+
* twd.url().should("contain.url", "/new-page");
|
|
612
|
+
* twd.url().should("eq", "http://localhost:3000/new-page");
|
|
613
|
+
*/
|
|
614
|
+
declare type URLAssertionName = "eq" | "contain.url";
|
|
615
|
+
|
|
616
|
+
declare type URLCommandAPI = {
|
|
617
|
+
location: Location;
|
|
618
|
+
should: (name: AnyURLAssertion, value: string, retries?: number) => Promise<string>;
|
|
619
|
+
};
|
|
620
|
+
|
|
621
|
+
declare type UserEvent = typeof default_2;
|
|
622
|
+
|
|
623
|
+
export declare const userEvent: UserEvent;
|
|
624
|
+
|
|
1
625
|
export { }
|