@terreno/ui 0.14.1 → 0.14.2

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.
@@ -451,5 +451,104 @@ describe("WebAddressAutocomplete", () => {
451
451
  fe.changeText(inputs[0], "new value");
452
452
  expect(handleAddressChange).toHaveBeenCalledWith("new value");
453
453
  });
454
+
455
+ it("cleans up the global callback on unmount", async () => {
456
+ const handleAutoCompleteChange = mock((_arg: AddressInterface) => {});
457
+
458
+ const {unmount} = renderWithTheme(
459
+ <WebAddressAutocomplete
460
+ googleMapsApiKey="cleanup-key"
461
+ handleAddressChange={() => {}}
462
+ handleAutoCompleteChange={handleAutoCompleteChange}
463
+ inputValue=""
464
+ />
465
+ );
466
+
467
+ await act(async () => {
468
+ await new Promise((resolve) => setTimeout(resolve, 0));
469
+ });
470
+
471
+ const win = (globalThis as Record<string, Record<string, unknown>>).window;
472
+ expect(win.initAutocomplete).toBeDefined();
473
+
474
+ unmount();
475
+
476
+ expect(win.initAutocomplete).toBeNull();
477
+ });
478
+
479
+ it("handles place_changed with includeCounty flag", async () => {
480
+ const handleAutoCompleteChange = mock((_arg: AddressInterface) => {});
481
+
482
+ let placeChangedCb: (() => void) | undefined;
483
+ const autocompleteConstructor = mock((_input: unknown, _opts: unknown) => ({
484
+ addListener: (event: string, cb: () => void) => {
485
+ if (event === "place_changed") {
486
+ placeChangedCb = cb;
487
+ }
488
+ },
489
+ getPlace: () => ({
490
+ address_components: [
491
+ {long_name: "10", short_name: "10", types: ["street_number"]},
492
+ {long_name: "Oak St", short_name: "Oak St", types: ["route"]},
493
+ {long_name: "Portland", short_name: "Portland", types: ["locality"]},
494
+ {long_name: "Oregon", short_name: "OR", types: ["administrative_area_level_1"]},
495
+ {long_name: "97201", short_name: "97201", types: ["postal_code"]},
496
+ {
497
+ long_name: "Multnomah County",
498
+ short_name: "Multnomah",
499
+ types: ["administrative_area_level_2"],
500
+ },
501
+ ],
502
+ }),
503
+ }));
504
+
505
+ const win = (globalThis as Record<string, Record<string, unknown>>).window;
506
+ win.google = {
507
+ maps: {places: {Autocomplete: autocompleteConstructor}},
508
+ };
509
+
510
+ renderWithTheme(
511
+ <WebAddressAutocomplete
512
+ googleMapsApiKey="county-key"
513
+ handleAddressChange={() => {}}
514
+ handleAutoCompleteChange={handleAutoCompleteChange}
515
+ includeCounty
516
+ inputValue=""
517
+ />
518
+ );
519
+
520
+ await act(async () => {
521
+ await new Promise((resolve) => setTimeout(resolve, 10));
522
+ });
523
+
524
+ expect(autocompleteConstructor).toHaveBeenCalled();
525
+ expect(placeChangedCb).toBeDefined();
526
+
527
+ placeChangedCb?.();
528
+ expect(handleAutoCompleteChange).toHaveBeenCalled();
529
+ });
530
+ });
531
+
532
+ describe("without googleMapsApiKey", () => {
533
+ it("sets scriptLoaded to false and renders plain TextField", async () => {
534
+ const handleAddressChange = mock(() => {});
535
+ const {UNSAFE_getAllByType} = renderWithTheme(
536
+ <WebAddressAutocomplete
537
+ handleAddressChange={handleAddressChange}
538
+ handleAutoCompleteChange={() => {}}
539
+ inputValue="test value"
540
+ />
541
+ );
542
+
543
+ await act(async () => {
544
+ await new Promise((resolve) => setTimeout(resolve, 10));
545
+ });
546
+
547
+ const {TextInput} = require("react-native");
548
+ const inputs = UNSAFE_getAllByType(TextInput);
549
+ expect(inputs.length).toBeGreaterThan(0);
550
+ fireEvent.changeText(inputs[0], "new value");
551
+ expect(handleAddressChange).toHaveBeenCalledWith("new value");
552
+ });
454
553
  });
455
554
  });
@@ -185,8 +185,6 @@ describe("useWebDropdownAnchor", () => {
185
185
 
186
186
  it("measures the trigger and updates anchor state when the ref has measureInWindow", () => {
187
187
  const {result} = renderHook(() => useWebDropdownAnchor());
188
- // Simulate a mounted native View by assigning a measureInWindow shim to the
189
- // ref. The hook does not care whether the node is a real View instance.
190
188
  const measureInWindow = mock((cb: (x: number, y: number, w: number, h: number) => void) => {
191
189
  cb(10, 20, 100, 40);
192
190
  });
@@ -200,4 +198,32 @@ describe("useWebDropdownAnchor", () => {
200
198
  expect(onMeasured.mock.calls[0][0]).toEqual({height: 40, width: 100, x: 10, y: 20});
201
199
  expect(result.current.anchor).toEqual({height: 40, width: 100, x: 10, y: 20});
202
200
  });
201
+
202
+ it("exercises the Pressable style callback for hover/pressed states", () => {
203
+ const {root} = renderWithTheme(
204
+ <WebDropdownMenu
205
+ anchor={{height: 40, width: 100, x: 0, y: 50}}
206
+ onClose={() => {}}
207
+ onSelect={() => {}}
208
+ options={[
209
+ {label: "A", value: "a"},
210
+ {label: "B", value: "b"},
211
+ ]}
212
+ visible
213
+ />
214
+ );
215
+ // Find a Pressable with the style callback
216
+ const pressables = root.findAll(
217
+ (n) => typeof n.props.style === "function" && n.props["aria-role"] === "button"
218
+ );
219
+ expect(pressables.length).toBeGreaterThan(0);
220
+ // Call the style function with different states to exercise all branches
221
+ const styleFn = pressables[0].props.style;
222
+ const normalStyle = styleFn({hovered: false, pressed: false});
223
+ expect(normalStyle).toHaveProperty("paddingHorizontal");
224
+ const hoveredStyle = styleFn({hovered: true, pressed: false});
225
+ expect(hoveredStyle).toHaveProperty("paddingHorizontal");
226
+ const pressedStyle = styleFn({hovered: false, pressed: true});
227
+ expect(pressedStyle).toHaveProperty("paddingHorizontal");
228
+ });
203
229
  });
@@ -544,3 +544,128 @@ exports[`Banner renders with button and icon 1`] = `
544
544
  "type": "View",
545
545
  }
546
546
  `;
547
+
548
+ exports[`Banner renders with button loading state 1`] = `
549
+ {
550
+ "$$typeof": Symbol(react.test.json),
551
+ "children": [
552
+ {
553
+ "$$typeof": Symbol(react.test.json),
554
+ "children": [
555
+ {
556
+ "$$typeof": Symbol(react.test.json),
557
+ "children": [
558
+ "Banner loading",
559
+ ],
560
+ "props": {
561
+ "style": {
562
+ "color": "#FFFFFF",
563
+ "flexShrink": 1,
564
+ "flexWrap": "wrap",
565
+ "fontWeight": "bold",
566
+ "textAlign": "center",
567
+ },
568
+ },
569
+ "type": "Text",
570
+ },
571
+ {
572
+ "$$typeof": Symbol(react.test.json),
573
+ "children": [
574
+ {
575
+ "$$typeof": Symbol(react.test.json),
576
+ "children": [
577
+ {
578
+ "$$typeof": Symbol(react.test.json),
579
+ "children": [
580
+ {
581
+ "$$typeof": Symbol(react.test.json),
582
+ "children": [
583
+ {
584
+ "$$typeof": Symbol(react.test.json),
585
+ "children": [
586
+ "Loading",
587
+ ],
588
+ "props": {
589
+ "style": {
590
+ "fontSize": 12,
591
+ },
592
+ },
593
+ "type": "Text",
594
+ },
595
+ ],
596
+ "props": {
597
+ "style": {
598
+ "flexDirection": "row-reverse",
599
+ },
600
+ "testID": undefined,
601
+ },
602
+ "type": "View",
603
+ },
604
+ ],
605
+ "props": {
606
+ "style": {
607
+ "flexDirection": "row",
608
+ },
609
+ "testID": undefined,
610
+ },
611
+ "type": "View",
612
+ },
613
+ ],
614
+ "props": {
615
+ "accessibilityHint": "Press to perform action Loading",
616
+ "aria-label": "Loading",
617
+ "aria-role": "button",
618
+ "onPress": [Function: debounced],
619
+ "style": {
620
+ "alignItems": "center",
621
+ "alignSelf": "stretch",
622
+ "backgroundColor": "#FFFFFF",
623
+ "borderRadius": 360,
624
+ "flexDirection": "column",
625
+ "justifyContent": "center",
626
+ "paddingHorizontal": 12,
627
+ "paddingVertical": 4,
628
+ },
629
+ },
630
+ "type": "Pressable",
631
+ },
632
+ ],
633
+ "props": {
634
+ "style": {
635
+ "paddingLeft": 16,
636
+ "paddingRight": 10,
637
+ },
638
+ "testID": undefined,
639
+ },
640
+ "type": "View",
641
+ },
642
+ ],
643
+ "props": {
644
+ "style": {
645
+ "alignItems": "center",
646
+ "flex": 1,
647
+ "flexDirection": "row",
648
+ "justifyContent": "center",
649
+ },
650
+ "testID": undefined,
651
+ },
652
+ "type": "View",
653
+ },
654
+ ],
655
+ "props": {
656
+ "style": {
657
+ "alignItems": "center",
658
+ "backgroundColor": "#2B6072",
659
+ "borderRadius": 4,
660
+ "flexDirection": "row",
661
+ "height": "auto",
662
+ "margin": "auto",
663
+ "minHeight": 32,
664
+ "padding": 4,
665
+ "width": "100%",
666
+ },
667
+ "testID": undefined,
668
+ },
669
+ "type": "View",
670
+ }
671
+ `;
@@ -9498,3 +9498,369 @@ exports[`DataTable renders empty data 1`] = `
9498
9498
  "type": "View",
9499
9499
  }
9500
9500
  `;
9501
+
9502
+ exports[`DataTable renders with custom column component map 1`] = `
9503
+ {
9504
+ "$$typeof": Symbol(react.test.json),
9505
+ "children": [
9506
+ {
9507
+ "$$typeof": Symbol(react.test.json),
9508
+ "children": [
9509
+ {
9510
+ "$$typeof": Symbol(react.test.json),
9511
+ "children": [
9512
+ {
9513
+ "$$typeof": Symbol(react.test.json),
9514
+ "children": [
9515
+ {
9516
+ "$$typeof": Symbol(react.test.json),
9517
+ "children": [
9518
+ {
9519
+ "$$typeof": Symbol(react.test.json),
9520
+ "children": [
9521
+ "Custom",
9522
+ ],
9523
+ "props": {
9524
+ "aria-label": "Table title: Custom",
9525
+ "aria-role": "header",
9526
+ "ellipsizeMode": "tail",
9527
+ "numberOfLines": 3,
9528
+ "style": {
9529
+ "color": "#1C1C1C",
9530
+ "flexWrap": "wrap",
9531
+ "fontFamily": "text",
9532
+ "fontSize": 10,
9533
+ "fontWeight": "700",
9534
+ "lineHeight": 16,
9535
+ "overflow": "hidden",
9536
+ "textAlign": "left",
9537
+ "textTransform": "uppercase",
9538
+ },
9539
+ },
9540
+ "type": "Text",
9541
+ },
9542
+ {
9543
+ "$$typeof": Symbol(react.test.json),
9544
+ "children": null,
9545
+ "props": {
9546
+ "style": {
9547
+ "alignItems": "center",
9548
+ "flexDirection": "row",
9549
+ },
9550
+ "testID": undefined,
9551
+ },
9552
+ "type": "View",
9553
+ },
9554
+ ],
9555
+ "props": {
9556
+ "style": {
9557
+ "alignItems": "center",
9558
+ "backgroundColor": "#FFFFFF",
9559
+ "borderBottomColor": "#CDCDCD",
9560
+ "borderBottomWidth": 1,
9561
+ "flexDirection": "row",
9562
+ "height": 54,
9563
+ "justifyContent": "space-between",
9564
+ "padding": 16,
9565
+ "width": 100,
9566
+ },
9567
+ "testID": undefined,
9568
+ },
9569
+ "type": "View",
9570
+ },
9571
+ {
9572
+ "$$typeof": Symbol(react.test.json),
9573
+ "children": [
9574
+ {
9575
+ "$$typeof": Symbol(react.test.json),
9576
+ "children": [
9577
+ "Name",
9578
+ ],
9579
+ "props": {
9580
+ "aria-label": "Table title: Name",
9581
+ "aria-role": "header",
9582
+ "ellipsizeMode": "tail",
9583
+ "numberOfLines": 3,
9584
+ "style": {
9585
+ "color": "#1C1C1C",
9586
+ "flexWrap": "wrap",
9587
+ "fontFamily": "text",
9588
+ "fontSize": 10,
9589
+ "fontWeight": "700",
9590
+ "lineHeight": 16,
9591
+ "overflow": "hidden",
9592
+ "textAlign": "left",
9593
+ "textTransform": "uppercase",
9594
+ },
9595
+ },
9596
+ "type": "Text",
9597
+ },
9598
+ {
9599
+ "$$typeof": Symbol(react.test.json),
9600
+ "children": null,
9601
+ "props": {
9602
+ "style": {
9603
+ "alignItems": "center",
9604
+ "flexDirection": "row",
9605
+ },
9606
+ "testID": undefined,
9607
+ },
9608
+ "type": "View",
9609
+ },
9610
+ ],
9611
+ "props": {
9612
+ "style": {
9613
+ "alignItems": "center",
9614
+ "backgroundColor": "#FFFFFF",
9615
+ "borderBottomColor": "#CDCDCD",
9616
+ "borderBottomWidth": 1,
9617
+ "flexDirection": "row",
9618
+ "height": 54,
9619
+ "justifyContent": "space-between",
9620
+ "padding": 16,
9621
+ "width": 100,
9622
+ },
9623
+ "testID": undefined,
9624
+ },
9625
+ "type": "View",
9626
+ },
9627
+ ],
9628
+ "props": {
9629
+ "horizontal": true,
9630
+ "onScroll": [Function],
9631
+ "ref": {
9632
+ "current": null,
9633
+ },
9634
+ "scrollEventThrottle": 16,
9635
+ "showsHorizontalScrollIndicator": false,
9636
+ "style": {
9637
+ "marginLeft": 0,
9638
+ },
9639
+ },
9640
+ "type": "ScrollView",
9641
+ },
9642
+ ],
9643
+ "props": {
9644
+ "style": {
9645
+ "flexDirection": "row",
9646
+ "position": "relative",
9647
+ },
9648
+ "testID": undefined,
9649
+ },
9650
+ "type": "View",
9651
+ },
9652
+ {
9653
+ "$$typeof": Symbol(react.test.json),
9654
+ "children": [
9655
+ {
9656
+ "$$typeof": Symbol(react.test.json),
9657
+ "children": [
9658
+ {
9659
+ "$$typeof": Symbol(react.test.json),
9660
+ "children": [
9661
+ {
9662
+ "$$typeof": Symbol(react.test.json),
9663
+ "children": [
9664
+ {
9665
+ "$$typeof": Symbol(react.test.json),
9666
+ "children": [
9667
+ {
9668
+ "$$typeof": Symbol(react.test.json),
9669
+ "children": [
9670
+ {
9671
+ "$$typeof": Symbol(react.test.json),
9672
+ "children": [
9673
+ {
9674
+ "$$typeof": Symbol(react.test.json),
9675
+ "children": [
9676
+ {
9677
+ "$$typeof": Symbol(react.test.json),
9678
+ "children": [
9679
+ "Custom",
9680
+ ],
9681
+ "props": {
9682
+ "numberOfLines": 0,
9683
+ "selectable": undefined,
9684
+ "style": {
9685
+ "color": "#1C1C1C",
9686
+ "fontFamily": "text-regular",
9687
+ "fontSize": 14,
9688
+ "textAlign": "left",
9689
+ },
9690
+ "testID": undefined,
9691
+ },
9692
+ "type": "Text",
9693
+ },
9694
+ ],
9695
+ "props": {},
9696
+ "type": "View",
9697
+ },
9698
+ ],
9699
+ "props": {
9700
+ "style": {
9701
+ "backgroundColor": "#FFFFFF",
9702
+ "borderBottomColor": "#CDCDCD",
9703
+ "borderBottomWidth": 1,
9704
+ "height": 54,
9705
+ "justifyContent": "center",
9706
+ "overflow": "hidden",
9707
+ "padding": 16,
9708
+ "position": "relative",
9709
+ "width": 100,
9710
+ "zIndex": 1,
9711
+ },
9712
+ "testID": undefined,
9713
+ },
9714
+ "type": "View",
9715
+ },
9716
+ {
9717
+ "$$typeof": Symbol(react.test.json),
9718
+ "children": [
9719
+ {
9720
+ "$$typeof": Symbol(react.test.json),
9721
+ "children": [
9722
+ {
9723
+ "$$typeof": Symbol(react.test.json),
9724
+ "children": [
9725
+ {
9726
+ "$$typeof": Symbol(react.test.json),
9727
+ "children": [
9728
+ "Alice",
9729
+ ],
9730
+ "props": {
9731
+ "numberOfLines": 0,
9732
+ "selectable": undefined,
9733
+ "style": {
9734
+ "color": "#1C1C1C",
9735
+ "fontFamily": "text-regular",
9736
+ "fontSize": 14,
9737
+ "textAlign": "left",
9738
+ },
9739
+ "testID": undefined,
9740
+ },
9741
+ "type": "Text",
9742
+ },
9743
+ ],
9744
+ "props": {},
9745
+ "type": "View",
9746
+ },
9747
+ ],
9748
+ "props": {
9749
+ "onPointerEnter": [Function: AsyncFunction],
9750
+ "onPointerLeave": [Function: AsyncFunction],
9751
+ "style": {
9752
+ "display": "flex",
9753
+ "flexGrow": 1,
9754
+ "flexShrink": 1,
9755
+ "justifyContent": "center",
9756
+ },
9757
+ "testID": undefined,
9758
+ },
9759
+ "type": "View",
9760
+ },
9761
+ ],
9762
+ "props": {
9763
+ "style": {
9764
+ "backgroundColor": "#FFFFFF",
9765
+ "borderBottomColor": "#CDCDCD",
9766
+ "borderBottomWidth": 1,
9767
+ "height": 54,
9768
+ "justifyContent": "center",
9769
+ "overflow": "hidden",
9770
+ "padding": 16,
9771
+ "position": "relative",
9772
+ "width": 100,
9773
+ "zIndex": 1,
9774
+ },
9775
+ "testID": undefined,
9776
+ },
9777
+ "type": "View",
9778
+ },
9779
+ ],
9780
+ "props": {
9781
+ "style": {
9782
+ "borderBottomColor": "#CDCDCD",
9783
+ "borderBottomWidth": 1,
9784
+ "flexDirection": "row",
9785
+ "height": 54,
9786
+ },
9787
+ "testID": undefined,
9788
+ },
9789
+ "type": "View",
9790
+ },
9791
+ ],
9792
+ "props": {
9793
+ "style": undefined,
9794
+ "testID": undefined,
9795
+ },
9796
+ "type": "View",
9797
+ },
9798
+ ],
9799
+ "props": {
9800
+ "horizontal": true,
9801
+ "onScroll": [Function],
9802
+ "ref": {
9803
+ "current": null,
9804
+ },
9805
+ "scrollEventThrottle": 16,
9806
+ "showsHorizontalScrollIndicator": true,
9807
+ "style": {
9808
+ "flex": 1,
9809
+ "marginLeft": 0,
9810
+ },
9811
+ },
9812
+ "type": "ScrollView",
9813
+ },
9814
+ ],
9815
+ "props": {
9816
+ "style": {
9817
+ "flexDirection": "row",
9818
+ "position": "relative",
9819
+ },
9820
+ "testID": undefined,
9821
+ },
9822
+ "type": "View",
9823
+ },
9824
+ ],
9825
+ "props": {
9826
+ "style": {
9827
+ "flex": 1,
9828
+ },
9829
+ },
9830
+ "type": "ScrollView",
9831
+ },
9832
+ ],
9833
+ "props": {
9834
+ "style": {
9835
+ "flex": 1,
9836
+ "minHeight": 0,
9837
+ },
9838
+ "testID": undefined,
9839
+ },
9840
+ "type": "View",
9841
+ },
9842
+ ],
9843
+ "props": {
9844
+ "style": {
9845
+ "borderColor": "#CDCDCD",
9846
+ "borderWidth": 1,
9847
+ "flex": 1,
9848
+ "height": "100%",
9849
+ "minHeight": 0,
9850
+ },
9851
+ "testID": undefined,
9852
+ },
9853
+ "type": "View",
9854
+ },
9855
+ ],
9856
+ "props": {
9857
+ "style": {
9858
+ "display": "flex",
9859
+ "flexDirection": "column",
9860
+ "height": "100%",
9861
+ },
9862
+ "testID": undefined,
9863
+ },
9864
+ "type": "View",
9865
+ }
9866
+ `;