@tapcart/mobile-components 0.12.12 → 0.12.14

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.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=quantity-picker.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quantity-picker.test.d.ts","sourceRoot":"","sources":["../../tests/quantity-picker.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,50 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { render, screen } from "@testing-library/react";
3
+ import { QuantityPicker } from "../components/ui/quantity-picker";
4
+ jest.mock("../components/ui/icon", () => ({
5
+ Icon: ({ url }) => (_jsx("img", { "data-testid": "icon", src: url, alt: "" })),
6
+ }));
7
+ const baseProps = {
8
+ decreaseIconUrl: "decrease.svg",
9
+ increaseIconUrl: "increase.svg",
10
+ deleteIconUrl: "delete.svg",
11
+ isDeleteOnly: false,
12
+ iconColor: "#000",
13
+ onDecreaseClick: jest.fn(),
14
+ onIncreaseClick: jest.fn(),
15
+ setValue: jest.fn(),
16
+ };
17
+ describe("QuantityPicker safeValue", () => {
18
+ it("displays a valid finite value", () => {
19
+ render(_jsx(QuantityPicker, Object.assign({}, baseProps, { value: 5 })));
20
+ expect(screen.getByText("5")).toBeTruthy();
21
+ });
22
+ it("falls back to 1 when value is NaN", () => {
23
+ render(_jsx(QuantityPicker, Object.assign({}, baseProps, { value: NaN })));
24
+ expect(screen.getByText("1")).toBeTruthy();
25
+ });
26
+ it("falls back to 1 when value is Infinity", () => {
27
+ render(_jsx(QuantityPicker, Object.assign({}, baseProps, { value: Infinity })));
28
+ expect(screen.getByText("1")).toBeTruthy();
29
+ });
30
+ it("falls back to 1 when value is -Infinity", () => {
31
+ render(_jsx(QuantityPicker, Object.assign({}, baseProps, { value: -Infinity })));
32
+ expect(screen.getByText("1")).toBeTruthy();
33
+ });
34
+ it("shows delete icon when safeValue is 1", () => {
35
+ render(_jsx(QuantityPicker, Object.assign({}, baseProps, { value: 1 })));
36
+ const icons = screen.getAllByTestId("icon");
37
+ // decrease button is the first icon; at quantity 1 it should use deleteIconUrl
38
+ expect(icons[0].getAttribute("src")).toBe("delete.svg");
39
+ });
40
+ it("shows decrease icon when safeValue is greater than 1", () => {
41
+ render(_jsx(QuantityPicker, Object.assign({}, baseProps, { value: 3 })));
42
+ const icons = screen.getAllByTestId("icon");
43
+ expect(icons[0].getAttribute("src")).toBe("decrease.svg");
44
+ });
45
+ it("shows delete icon (not decrease) when a non-finite value falls back to 1", () => {
46
+ render(_jsx(QuantityPicker, Object.assign({}, baseProps, { value: NaN })));
47
+ const icons = screen.getAllByTestId("icon");
48
+ expect(icons[0].getAttribute("src")).toBe("delete.svg");
49
+ });
50
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=quantity-pickerNEW.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quantity-pickerNEW.test.d.ts","sourceRoot":"","sources":["../../tests/quantity-pickerNEW.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,70 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { render, screen } from "@testing-library/react";
3
+ import { QuantityPickerNEW } from "../components/ui/quantity-pickerNEW";
4
+ jest.mock("../components/ui/icon", () => ({
5
+ Icon: ({ url }) => (_jsx("img", { "data-testid": "icon", src: url, alt: "" })),
6
+ }));
7
+ jest.mock("../components/ui/loading-dots", () => ({
8
+ LoadingDots: () => null,
9
+ }));
10
+ const baseProps = {
11
+ decreaseIconUrl: "decrease.svg",
12
+ increaseIconUrl: "increase.svg",
13
+ deleteIconUrl: "delete.svg",
14
+ isDeleteOnly: false,
15
+ iconColor: "#000",
16
+ onDecreaseClick: jest.fn(),
17
+ onIncreaseClick: jest.fn(),
18
+ onValueSet: jest.fn(),
19
+ onAdjustQuantity: jest.fn(),
20
+ };
21
+ describe("QuantityPickerNEW safeValue", () => {
22
+ it("displays a valid finite value in the input", () => {
23
+ render(_jsx(QuantityPickerNEW, Object.assign({}, baseProps, { value: 5 })));
24
+ const input = screen.getByRole("spinbutton");
25
+ expect(input.value).toBe("5");
26
+ });
27
+ it("falls back to 1 when value is NaN", () => {
28
+ render(_jsx(QuantityPickerNEW, Object.assign({}, baseProps, { value: NaN })));
29
+ const input = screen.getByRole("spinbutton");
30
+ expect(input.value).toBe("1");
31
+ });
32
+ it("falls back to 1 when value is Infinity", () => {
33
+ render(_jsx(QuantityPickerNEW, Object.assign({}, baseProps, { value: Infinity })));
34
+ const input = screen.getByRole("spinbutton");
35
+ expect(input.value).toBe("1");
36
+ });
37
+ it("falls back to 1 when value is -Infinity", () => {
38
+ render(_jsx(QuantityPickerNEW, Object.assign({}, baseProps, { value: -Infinity })));
39
+ const input = screen.getByRole("spinbutton");
40
+ expect(input.value).toBe("1");
41
+ });
42
+ it("shows delete icon when safeValue is 1", () => {
43
+ render(_jsx(QuantityPickerNEW, Object.assign({}, baseProps, { value: 1 })));
44
+ const icons = screen.getAllByTestId("icon");
45
+ expect(icons[0].getAttribute("src")).toBe("delete.svg");
46
+ });
47
+ it("shows decrease icon when safeValue is greater than 1", () => {
48
+ render(_jsx(QuantityPickerNEW, Object.assign({}, baseProps, { value: 3 })));
49
+ const icons = screen.getAllByTestId("icon");
50
+ expect(icons[0].getAttribute("src")).toBe("decrease.svg");
51
+ });
52
+ it("shows delete icon (not decrease) when a non-finite value falls back to 1", () => {
53
+ render(_jsx(QuantityPickerNEW, Object.assign({}, baseProps, { value: NaN })));
54
+ const icons = screen.getAllByTestId("icon");
55
+ expect(icons[0].getAttribute("src")).toBe("delete.svg");
56
+ });
57
+ it("disables the increase button when safeValue equals max", () => {
58
+ render(_jsx(QuantityPickerNEW, Object.assign({}, baseProps, { value: 10, max: 10 })));
59
+ const buttons = screen.getAllByRole("button");
60
+ // increase button is the last button
61
+ const increaseButton = buttons[buttons.length - 1];
62
+ expect(increaseButton.disabled).toBe(true);
63
+ });
64
+ it("does not disable the increase button when safeValue is below max", () => {
65
+ render(_jsx(QuantityPickerNEW, Object.assign({}, baseProps, { value: 5, max: 10 })));
66
+ const buttons = screen.getAllByRole("button");
67
+ const increaseButton = buttons[buttons.length - 1];
68
+ expect(increaseButton.disabled).toBe(false);
69
+ });
70
+ });
@@ -1,4 +1,63 @@
1
- import { getDestinationHandler, getTextStyle, parseBCP47Locale, } from "../lib/utils";
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { getDestinationHandler, getTextStyle, parseBCP47Locale, shareContent, } from "../lib/utils";
11
+ describe("shareContent", () => {
12
+ let mockTapcartAction;
13
+ beforeEach(() => {
14
+ mockTapcartAction = jest.fn();
15
+ Object.defineProperty(global.navigator, "share", {
16
+ configurable: true,
17
+ writable: true,
18
+ value: undefined,
19
+ });
20
+ });
21
+ afterEach(() => {
22
+ jest.clearAllMocks();
23
+ });
24
+ it("calls navigator.share with text when available", () => __awaiter(void 0, void 0, void 0, function* () {
25
+ const mockShare = jest.fn().mockResolvedValue(undefined);
26
+ Object.defineProperty(global.navigator, "share", {
27
+ configurable: true,
28
+ value: mockShare,
29
+ });
30
+ yield shareContent("Check this out https://shop.com/products/hat", mockTapcartAction);
31
+ expect(mockShare).toHaveBeenCalledWith({
32
+ text: "Check this out https://shop.com/products/hat",
33
+ });
34
+ expect(mockTapcartAction).not.toHaveBeenCalled();
35
+ }));
36
+ it("falls back to tapcartAction when navigator.share is unavailable", () => __awaiter(void 0, void 0, void 0, function* () {
37
+ yield shareContent("Check this out https://shop.com/products/hat", mockTapcartAction);
38
+ expect(mockTapcartAction).toHaveBeenCalledWith("app/share", {
39
+ text: "Check this out https://shop.com/products/hat",
40
+ });
41
+ }));
42
+ it("falls back to tapcartAction when tapcartAction is undefined", () => __awaiter(void 0, void 0, void 0, function* () {
43
+ yield expect(shareContent("text", undefined)).resolves.toBeUndefined();
44
+ }));
45
+ it("swallows errors from navigator.share and does not call tapcartAction", () => __awaiter(void 0, void 0, void 0, function* () {
46
+ const mockShare = jest.fn().mockRejectedValue(new Error("AbortError"));
47
+ Object.defineProperty(global.navigator, "share", {
48
+ configurable: true,
49
+ value: mockShare,
50
+ });
51
+ const consoleSpy = jest.spyOn(console, "error").mockImplementation(() => { });
52
+ yield shareContent("text", mockTapcartAction);
53
+ expect(consoleSpy).toHaveBeenCalledWith("Could not initiate share", expect.any(Error));
54
+ expect(mockTapcartAction).not.toHaveBeenCalled();
55
+ consoleSpy.mockRestore();
56
+ }));
57
+ it("falls back to tapcartAction when tapcartAction is null", () => __awaiter(void 0, void 0, void 0, function* () {
58
+ yield expect(shareContent("text", null)).resolves.toBeUndefined();
59
+ }));
60
+ });
2
61
  describe("DESTINATION_HANDLERS", () => {
3
62
  describe("url handler", () => {
4
63
  const mockActions = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tapcart/mobile-components",
3
- "version": "0.12.12",
3
+ "version": "0.12.14",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "style": "dist/styles.css",