@terreno/ui 57.17.0 → 57.18.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/package.json +2 -2
- package/src/IconButton.test.tsx +178 -0
package/package.json
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"@react-native-picker/picker": "2.11.4",
|
|
27
27
|
"@react-navigation/native": "^7.1.8",
|
|
28
28
|
"@shopify/react-native-skia": "2.6.5",
|
|
29
|
-
"@terreno/blocks": "57.
|
|
29
|
+
"@terreno/blocks": "57.18.0",
|
|
30
30
|
"d3-scale": "^4.0.2",
|
|
31
31
|
"d3-shape": "^3.2.0",
|
|
32
32
|
"emoji-datasource": "^16.0.0",
|
|
@@ -163,7 +163,7 @@
|
|
|
163
163
|
"test:coverage": "TZ=America/New_York bun run ../scripts/check-coverage.ts",
|
|
164
164
|
"types": "bun typedoc"
|
|
165
165
|
},
|
|
166
|
-
"version": "57.
|
|
166
|
+
"version": "57.18.0",
|
|
167
167
|
"bugs": {
|
|
168
168
|
"url": "https://github.com/TerrenoLabs/terreno/issues"
|
|
169
169
|
},
|
package/src/IconButton.test.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {describe, expect, it, mock} from "bun:test";
|
|
2
|
+
import {act, fireEvent, waitFor} from "@testing-library/react-native";
|
|
2
3
|
import type {ReactTestInstance} from "react-test-renderer";
|
|
3
4
|
|
|
4
5
|
import {IconButton} from "./IconButton";
|
|
@@ -267,4 +268,181 @@ describe("IconButton", () => {
|
|
|
267
268
|
).not.toThrow();
|
|
268
269
|
});
|
|
269
270
|
});
|
|
271
|
+
describe("interaction (real component)", () => {
|
|
272
|
+
// bunSetup replaces ./IconButton with a null mock; the query suffix loads the real module.
|
|
273
|
+
const loadIconButton = async (): Promise<typeof import("./IconButton").IconButton> => {
|
|
274
|
+
const actualIconButtonPath = "./IconButton.tsx?interaction";
|
|
275
|
+
const module = (await import(actualIconButtonPath)) as typeof import("./IconButton");
|
|
276
|
+
return module.IconButton;
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
it("runs onClick once when pressed without confirmation", async () => {
|
|
280
|
+
const ActualIconButton = await loadIconButton();
|
|
281
|
+
const handleClick = mock(() => Promise.resolve());
|
|
282
|
+
const {getByLabelText} = renderWithTheme(
|
|
283
|
+
<ActualIconButton accessibilityLabel="Save" iconName="check" onClick={handleClick} />
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
await act(async () => {
|
|
287
|
+
fireEvent.press(getByLabelText("Save"));
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
await waitFor(() => {
|
|
291
|
+
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
it("asks for confirmation first and runs onClick only after Confirm", async () => {
|
|
296
|
+
const ActualIconButton = await loadIconButton();
|
|
297
|
+
const handleClick = mock(() => Promise.resolve());
|
|
298
|
+
const {getByLabelText, getByText} = renderWithTheme(
|
|
299
|
+
<ActualIconButton
|
|
300
|
+
accessibilityLabel="Delete"
|
|
301
|
+
confirmationHeading="Delete item"
|
|
302
|
+
confirmationText="This cannot be undone."
|
|
303
|
+
iconName="trash"
|
|
304
|
+
onClick={handleClick}
|
|
305
|
+
withConfirmation
|
|
306
|
+
/>
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
expect(getByLabelText("Delete").props.accessibilityHint).toBe(
|
|
310
|
+
"Opens a confirmation dialog to confirm Delete"
|
|
311
|
+
);
|
|
312
|
+
await act(async () => {
|
|
313
|
+
fireEvent.press(getByLabelText("Delete"));
|
|
314
|
+
});
|
|
315
|
+
await waitFor(() => {
|
|
316
|
+
expect(getByText("This cannot be undone.")).toBeTruthy();
|
|
317
|
+
});
|
|
318
|
+
expect(handleClick).not.toHaveBeenCalled();
|
|
319
|
+
|
|
320
|
+
await act(async () => {
|
|
321
|
+
fireEvent.press(getByText("Confirm"));
|
|
322
|
+
});
|
|
323
|
+
await waitFor(() => {
|
|
324
|
+
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it("closes the confirmation without running onClick on Cancel", async () => {
|
|
329
|
+
const ActualIconButton = await loadIconButton();
|
|
330
|
+
const handleClick = mock(() => Promise.resolve());
|
|
331
|
+
const {getByLabelText, getByText} = renderWithTheme(
|
|
332
|
+
<ActualIconButton
|
|
333
|
+
accessibilityLabel="Archive"
|
|
334
|
+
iconName="box-archive"
|
|
335
|
+
onClick={handleClick}
|
|
336
|
+
withConfirmation
|
|
337
|
+
/>
|
|
338
|
+
);
|
|
339
|
+
|
|
340
|
+
await act(async () => {
|
|
341
|
+
fireEvent.press(getByLabelText("Archive"));
|
|
342
|
+
});
|
|
343
|
+
await waitFor(() => {
|
|
344
|
+
expect(getByText("Are you sure you want to continue?")).toBeTruthy();
|
|
345
|
+
});
|
|
346
|
+
await act(async () => {
|
|
347
|
+
fireEvent.press(getByText("Cancel"));
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
expect(handleClick).not.toHaveBeenCalled();
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it("colors each variant and state from the theme", async () => {
|
|
354
|
+
const ActualIconButton = await loadIconButton();
|
|
355
|
+
let theme = {} as ReturnType<typeof useTheme>["theme"];
|
|
356
|
+
const CaptureTheme = (): null => {
|
|
357
|
+
theme = useTheme().theme;
|
|
358
|
+
return null;
|
|
359
|
+
};
|
|
360
|
+
const {getByLabelText} = renderWithTheme(
|
|
361
|
+
<>
|
|
362
|
+
<CaptureTheme />
|
|
363
|
+
<ActualIconButton accessibilityLabel="primary" iconName="check" onClick={() => {}} />
|
|
364
|
+
<ActualIconButton
|
|
365
|
+
accessibilityLabel="secondary"
|
|
366
|
+
iconName="check"
|
|
367
|
+
onClick={() => {}}
|
|
368
|
+
variant="secondary"
|
|
369
|
+
/>
|
|
370
|
+
<ActualIconButton
|
|
371
|
+
accessibilityLabel="navigation"
|
|
372
|
+
iconName="check"
|
|
373
|
+
onClick={() => {}}
|
|
374
|
+
variant="navigation"
|
|
375
|
+
/>
|
|
376
|
+
<ActualIconButton
|
|
377
|
+
accessibilityLabel="destructive"
|
|
378
|
+
iconName="check"
|
|
379
|
+
onClick={() => {}}
|
|
380
|
+
variant="destructive"
|
|
381
|
+
/>
|
|
382
|
+
<ActualIconButton
|
|
383
|
+
accessibilityLabel="ghost"
|
|
384
|
+
iconName="check"
|
|
385
|
+
onClick={() => {}}
|
|
386
|
+
variant="ghost"
|
|
387
|
+
/>
|
|
388
|
+
<ActualIconButton
|
|
389
|
+
accessibilityLabel="disabled"
|
|
390
|
+
disabled
|
|
391
|
+
iconName="check"
|
|
392
|
+
onClick={() => {}}
|
|
393
|
+
/>
|
|
394
|
+
<ActualIconButton
|
|
395
|
+
accessibilityLabel="primary active"
|
|
396
|
+
iconName="check"
|
|
397
|
+
onClick={() => {}}
|
|
398
|
+
state="active"
|
|
399
|
+
/>
|
|
400
|
+
<ActualIconButton
|
|
401
|
+
accessibilityLabel="ghost active"
|
|
402
|
+
iconName="check"
|
|
403
|
+
onClick={() => {}}
|
|
404
|
+
state="active"
|
|
405
|
+
variant="ghost"
|
|
406
|
+
/>
|
|
407
|
+
<ActualIconButton
|
|
408
|
+
accessibilityLabel="small"
|
|
409
|
+
iconName="check"
|
|
410
|
+
indicator="error"
|
|
411
|
+
indicatorText="3"
|
|
412
|
+
onClick={() => {}}
|
|
413
|
+
size="sm"
|
|
414
|
+
/>
|
|
415
|
+
</>
|
|
416
|
+
);
|
|
417
|
+
|
|
418
|
+
expect(getByLabelText("primary")).toHaveStyle({backgroundColor: theme.surface.primary});
|
|
419
|
+
expect(getByLabelText("secondary")).toHaveStyle({
|
|
420
|
+
backgroundColor: theme.surface.neutralLight,
|
|
421
|
+
});
|
|
422
|
+
expect(getByLabelText("navigation")).toHaveStyle({backgroundColor: theme.text.inverted});
|
|
423
|
+
expect(getByLabelText("destructive")).toHaveStyle({backgroundColor: theme.text.inverted});
|
|
424
|
+
expect(getByLabelText("ghost")).toHaveStyle({backgroundColor: "transparent"});
|
|
425
|
+
expect(getByLabelText("disabled")).toHaveStyle({backgroundColor: theme.surface.disabled});
|
|
426
|
+
expect(getByLabelText("primary active")).toHaveStyle({
|
|
427
|
+
backgroundColor: theme.primitives.primary600,
|
|
428
|
+
});
|
|
429
|
+
expect(getByLabelText("ghost active")).toHaveStyle({backgroundColor: theme.surface.primary});
|
|
430
|
+
expect(getByLabelText("small")).toHaveStyle({height: 28, width: 28});
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
it("uses the tooltip text as the label when the label is empty", async () => {
|
|
434
|
+
const ActualIconButton = await loadIconButton();
|
|
435
|
+
const {getByLabelText} = renderWithTheme(
|
|
436
|
+
<ActualIconButton
|
|
437
|
+
accessibilityLabel=""
|
|
438
|
+
iconName="gear"
|
|
439
|
+
onClick={() => {}}
|
|
440
|
+
tooltipText="Settings"
|
|
441
|
+
/>
|
|
442
|
+
);
|
|
443
|
+
expect(getByLabelText("Settings").props.accessibilityHint).toBe(
|
|
444
|
+
"Press to perform Settings action"
|
|
445
|
+
);
|
|
446
|
+
});
|
|
447
|
+
});
|
|
270
448
|
});
|