@snowcone-app/ui 0.10.0 → 0.10.3
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/CHANGELOG.md +28 -0
- package/dist/index.cjs +99 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +100 -24
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/composed/HeroProductImage.tsx +13 -1
- package/src/composed/carousels/MobileProductCarousel.tsx +2 -0
- package/src/composed/carousels/types.ts +7 -0
- package/src/patterns/RealtimeProvider.tsx +117 -23
- package/src/patterns/__tests__/RealtimeProvider.blobLifecycle.test.tsx +1 -1
- package/src/patterns/__tests__/RealtimeProvider.cropDelivery.test.tsx +1 -1
- package/src/patterns/__tests__/RealtimeProvider.frameAcks.test.tsx +99 -0
- package/src/patterns/__tests__/RealtimeProvider.sessionShape.test.tsx +37 -1
- package/src/patterns/__tests__/RealtimeProvider.sizePicture.test.tsx +75 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Size pictures (json.linkedAs 'size-picture') in the realtime session: the session renders every ordinary picture
|
|
3
|
+
* plus the chosen size's picture (the box renders each mockup at the variant it lists, rendercenter rc#858). A size
|
|
4
|
+
* change sends ONE config with the new size's picture; the other sizes are never rendered and never pending.
|
|
5
|
+
*/
|
|
6
|
+
import { describe, expect, it, beforeEach, vi } from "vitest";
|
|
7
|
+
import React from "react";
|
|
8
|
+
import { render, waitFor, act, cleanup } from "@testing-library/react";
|
|
9
|
+
import { RealtimeProvider, useRealtime, type RealtimeContextValue } from "../RealtimeProvider";
|
|
10
|
+
|
|
11
|
+
const h = vi.hoisted(() => ({
|
|
12
|
+
selected: "gS",
|
|
13
|
+
selection: { size: "S" } as Record<string, string>,
|
|
14
|
+
sendConfig: vi.fn(),
|
|
15
|
+
stable: {
|
|
16
|
+
sendCanvasBlob: vi.fn(), sendColorBlob: vi.fn(), updateMockupIds: vi.fn(), updatePlacementSettings: vi.fn(),
|
|
17
|
+
connect: vi.fn(), disconnect: vi.fn(), flushPendingBlobs: vi.fn(), hasPendingBlobs: vi.fn(() => false),
|
|
18
|
+
getLatestSentVersions: vi.fn(() => ({})), rerender: vi.fn(() => true), isFrameSuperseded: vi.fn(() => false),
|
|
19
|
+
sendCanvasState: vi.fn(() => true), ackFrame: vi.fn(() => false),
|
|
20
|
+
},
|
|
21
|
+
}));
|
|
22
|
+
vi.mock("@snowcone-app/sdk/react", () => ({
|
|
23
|
+
useRealtimeMockup: () => ({
|
|
24
|
+
isConnected: true, isConfigured: true, renderError: null, acks: null, mockupResults: [],
|
|
25
|
+
sendConfig: h.sendConfig, getLastSentVersion: () => 0, ...h.stable,
|
|
26
|
+
}),
|
|
27
|
+
}));
|
|
28
|
+
vi.mock("@snowcone-app/sdk", () => {
|
|
29
|
+
const role = (m: any) => (m?.linkedAs === "size-picture" ? "size-picture" : "ordinary");
|
|
30
|
+
return {
|
|
31
|
+
mockupRole: role,
|
|
32
|
+
gallerySizePicture: (ms: any[], g: string) => ms.find((m) => role(m) === "size-picture" && m.gvids.includes(g)) ?? null,
|
|
33
|
+
resolveVariantId: () => h.selected,
|
|
34
|
+
resolvePreviewVariantId: () => "gXL", // the ordinary pictures list XL only (the hoodie)
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
vi.mock("../Product", () => {
|
|
38
|
+
const product = {
|
|
39
|
+
id: "XTNA6J",
|
|
40
|
+
placements: [{ label: "Front", type: "image" }],
|
|
41
|
+
mockups: [
|
|
42
|
+
{ id: "ORD001", gvids: ["gXL"] },
|
|
43
|
+
{ id: "YTGD3Q", gvids: ["gS"], linkedAs: "size-picture" },
|
|
44
|
+
{ id: "EVAD6V", gvids: ["gXL"], linkedAs: "size-picture" },
|
|
45
|
+
],
|
|
46
|
+
};
|
|
47
|
+
return { useProductOptional: () => ({ product, selection: h.selection }) };
|
|
48
|
+
});
|
|
49
|
+
vi.mock("../MockupBackground", () => ({ useMockupBackgroundOptional: () => undefined }));
|
|
50
|
+
|
|
51
|
+
let ctx: RealtimeContextValue;
|
|
52
|
+
function Capture() { ctx = useRealtime(); return null; }
|
|
53
|
+
function Harness({ v }: { v: number }) {
|
|
54
|
+
void v;
|
|
55
|
+
return <RealtimeProvider autoEnable delivery="full-frame"><Capture /></RealtimeProvider>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
beforeEach(() => { cleanup(); vi.clearAllMocks(); h.selected = "gS"; h.selection = { size: "S" }; });
|
|
59
|
+
|
|
60
|
+
describe("size pictures in the realtime session", () => {
|
|
61
|
+
it("renders the ordinary pictures + the chosen size's picture; a size change sends ONE config with the new one", async () => {
|
|
62
|
+
const { rerender } = render(<Harness v={1} />);
|
|
63
|
+
await waitFor(() => expect(h.sendConfig).toHaveBeenCalled());
|
|
64
|
+
expect(h.sendConfig.mock.calls.map((c) => c[0].mockupIds)).toEqual([["ORD001", "YTGD3Q"]]);
|
|
65
|
+
await act(async () => ctx.notifyPendingExport("Front"));
|
|
66
|
+
expect(ctx.isMockupLoading("YTGD3Q")).toBe(true);
|
|
67
|
+
expect(ctx.isMockupLoading("EVAD6V")).toBe(false); // another size's picture: never rendered, never pending
|
|
68
|
+
h.sendConfig.mockClear();
|
|
69
|
+
h.selected = "gXL";
|
|
70
|
+
h.selection = { size: "XL" }; // a new selection object, as the Product context makes on a pick
|
|
71
|
+
await act(async () => rerender(<Harness v={2} />));
|
|
72
|
+
await waitFor(() => expect(h.sendConfig).toHaveBeenCalled());
|
|
73
|
+
expect(h.sendConfig.mock.calls.map((c) => c[0].mockupIds)).toEqual([["ORD001", "EVAD6V"]]);
|
|
74
|
+
});
|
|
75
|
+
});
|