@coveo/headless-react 2.5.6 → 2.5.7-pre.fea54aaf11
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/__tests__/component-test-utils.d.ts +6 -0
- package/dist/__tests__/component-test-utils.js +16 -0
- package/dist/__tests__/component-test-utils.js.map +1 -0
- package/dist/__tests__/mock-navigator-context-provider.d.ts +2 -0
- package/dist/__tests__/mock-navigator-context-provider.js +7 -0
- package/dist/__tests__/mock-navigator-context-provider.js.map +1 -0
- package/dist/__tests__/mock-products.d.ts +3 -0
- package/dist/__tests__/mock-products.js +33 -0
- package/dist/__tests__/mock-products.js.map +1 -0
- package/dist/__tests__/mock-ssr-controller-definitions.d.ts +16 -0
- package/dist/__tests__/mock-ssr-controller-definitions.js +19 -0
- package/dist/__tests__/mock-ssr-controller-definitions.js.map +1 -0
- package/dist/__tests__/mock-ssr-engine.d.ts +2 -0
- package/dist/__tests__/mock-ssr-engine.js +7 -0
- package/dist/__tests__/mock-ssr-engine.js.map +1 -0
- package/dist/__tests__/setup.d.ts +1 -0
- package/dist/__tests__/setup.js +9 -0
- package/dist/__tests__/setup.js.map +1 -0
- package/dist/__tests__/test-utils.d.ts +10 -0
- package/dist/__tests__/test-utils.js +21 -0
- package/dist/__tests__/test-utils.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Product } from '@coveo/headless/ssr-commerce';
|
|
2
|
+
export declare const createProductListComponent: (productCount?: number) => {
|
|
3
|
+
ProductListComponent: () => import("react/jsx-runtime").JSX.Element;
|
|
4
|
+
mockProducts: Product[];
|
|
5
|
+
};
|
|
6
|
+
export declare const createTestComponent: (testId: string, content?: string) => () => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { generateMockProducts } from './mock-products.js';
|
|
3
|
+
export const createProductListComponent = (productCount = 5) => {
|
|
4
|
+
const mockProducts = generateMockProducts(productCount);
|
|
5
|
+
function ProductListComponent() {
|
|
6
|
+
return (_jsx("ul", { "data-testid": "product-list", children: mockProducts.map((product) => (_jsx("li", { "data-testid": "product-item", children: product.ec_name }, product.ec_product_id))) }));
|
|
7
|
+
}
|
|
8
|
+
return { ProductListComponent, mockProducts };
|
|
9
|
+
};
|
|
10
|
+
export const createTestComponent = (testId, content = 'Test Content') => {
|
|
11
|
+
function TestComponent() {
|
|
12
|
+
return _jsx("div", { "data-testid": testId, children: content });
|
|
13
|
+
}
|
|
14
|
+
return TestComponent;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=component-test-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-test-utils.js","sourceRoot":"","sources":["../../src/__tests__/component-test-utils.tsx"],"names":[],"mappings":";AACA,OAAO,EAAC,oBAAoB,EAAC,MAAM,oBAAoB,CAAC;AAExD,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,YAAY,GAAG,CAAC,EAAE,EAAE;IAC7D,MAAM,YAAY,GAAG,oBAAoB,CAAC,YAAY,CAAC,CAAC;IAExD,SAAS,oBAAoB;QAC3B,OAAO,CACL,4BAAgB,cAAc,YAC3B,YAAY,CAAC,GAAG,CAAC,CAAC,OAAgB,EAAE,EAAE,CAAC,CACtC,4BAA4C,cAAc,YACvD,OAAO,CAAC,OAAO,IADT,OAAO,CAAC,aAAa,CAEzB,CACN,CAAC,GACC,CACN,CAAC;IACJ,CAAC;IAED,OAAO,EAAC,oBAAoB,EAAE,YAAY,EAAC,CAAC;AAC9C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,MAAc,EACd,OAAO,GAAG,cAAc,EACxB,EAAE;IACF,SAAS,aAAa;QACpB,OAAO,6BAAkB,MAAM,YAAG,OAAO,GAAO,CAAC;IACnD,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const createMockCommerceNavigatorContextProvider = () => () => ({
|
|
2
|
+
clientId: 'test-commerce-client',
|
|
3
|
+
location: 'https://commerce.test.com',
|
|
4
|
+
referrer: 'https://search.test.com',
|
|
5
|
+
userAgent: 'Test Commerce Agent',
|
|
6
|
+
});
|
|
7
|
+
//# sourceMappingURL=mock-navigator-context-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock-navigator-context-provider.js","sourceRoot":"","sources":["../../src/__tests__/mock-navigator-context-provider.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,0CAA0C,GACrD,GAA6B,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;IACrC,QAAQ,EAAE,sBAAsB;IAChC,QAAQ,EAAE,2BAA2B;IACrC,QAAQ,EAAE,yBAAyB;IACnC,SAAS,EAAE,qBAAqB;CACjC,CAAC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
// Product factory for commerce tests
|
|
3
|
+
export const createMockProduct = (overrides = {}) => ({
|
|
4
|
+
additionalFields: {},
|
|
5
|
+
children: [],
|
|
6
|
+
clickUri: '',
|
|
7
|
+
ec_brand: 'Test Brand',
|
|
8
|
+
ec_category: ['Test Category'],
|
|
9
|
+
ec_color: 'Test Color',
|
|
10
|
+
ec_description: 'Test Description',
|
|
11
|
+
ec_gender: 'Test Gender',
|
|
12
|
+
ec_images: [],
|
|
13
|
+
ec_in_stock: true,
|
|
14
|
+
ec_item_group_id: 'test-group',
|
|
15
|
+
ec_listing: 'test-listing',
|
|
16
|
+
ec_name: 'Test Product',
|
|
17
|
+
ec_price: 99.99,
|
|
18
|
+
ec_product_id: randomUUID(),
|
|
19
|
+
ec_promo_price: 79.99,
|
|
20
|
+
ec_rating: 4.5,
|
|
21
|
+
ec_shortdesc: 'Test short description',
|
|
22
|
+
ec_thumbnails: [],
|
|
23
|
+
permanentid: randomUUID(),
|
|
24
|
+
position: 1,
|
|
25
|
+
totalNumberOfChildren: 0,
|
|
26
|
+
...overrides,
|
|
27
|
+
});
|
|
28
|
+
// Test data generators
|
|
29
|
+
export const generateMockProducts = (count) => Array.from({ length: count }, (_, index) => createMockProduct({
|
|
30
|
+
ec_name: `Product ${index + 1}`,
|
|
31
|
+
position: index + 1,
|
|
32
|
+
}));
|
|
33
|
+
//# sourceMappingURL=mock-products.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock-products.js","sourceRoot":"","sources":["../../src/__tests__/mock-products.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC;AAGvC,qCAAqC;AACrC,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,YAA8B,EAAE,EACvB,EAAE,CAAC,CAAC;IACb,gBAAgB,EAAE,EAAE;IACpB,QAAQ,EAAE,EAAE;IACZ,QAAQ,EAAE,EAAE;IACZ,QAAQ,EAAE,YAAY;IACtB,WAAW,EAAE,CAAC,eAAe,CAAC;IAC9B,QAAQ,EAAE,YAAY;IACtB,cAAc,EAAE,kBAAkB;IAClC,SAAS,EAAE,aAAa;IACxB,SAAS,EAAE,EAAE;IACb,WAAW,EAAE,IAAI;IACjB,gBAAgB,EAAE,YAAY;IAC9B,UAAU,EAAE,cAAc;IAC1B,OAAO,EAAE,cAAc;IACvB,QAAQ,EAAE,KAAK;IACf,aAAa,EAAE,UAAU,EAAE;IAC3B,cAAc,EAAE,KAAK;IACrB,SAAS,EAAE,GAAG;IACd,YAAY,EAAE,wBAAwB;IACtC,aAAa,EAAE,EAAE;IACjB,WAAW,EAAE,UAAU,EAAE;IACzB,QAAQ,EAAE,CAAC;IACX,qBAAqB,EAAE,CAAC;IACxB,GAAG,SAAS;CACb,CAAC,CAAC;AAEH,uBAAuB;AACvB,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,KAAa,EAAa,EAAE,CAC/D,KAAK,CAAC,IAAI,CAAC,EAAC,MAAM,EAAE,KAAK,EAAC,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CACvC,iBAAiB,CAAC;IAChB,OAAO,EAAE,WAAW,KAAK,GAAG,CAAC,EAAE;IAC/B,QAAQ,EAAE,KAAK,GAAG,CAAC;CACpB,CAAC,CACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Controller } from '@coveo/headless';
|
|
2
|
+
type SolutionTypeAvailabilities = {
|
|
3
|
+
listing?: boolean;
|
|
4
|
+
search?: boolean;
|
|
5
|
+
standalone?: boolean;
|
|
6
|
+
recommendation?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare function buildMockController(): Controller;
|
|
9
|
+
export declare function defineMockCommerceController(options?: SolutionTypeAvailabilities): {
|
|
10
|
+
build: import("vitest").Mock<(_engine: any) => Controller>;
|
|
11
|
+
listing: boolean;
|
|
12
|
+
search: boolean;
|
|
13
|
+
standalone: boolean;
|
|
14
|
+
recommendation: boolean;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { vi } from 'vitest';
|
|
2
|
+
export function buildMockController() {
|
|
3
|
+
return {
|
|
4
|
+
subscribe: vi.fn(() => vi.fn()),
|
|
5
|
+
state: {},
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export function defineMockCommerceController(options) {
|
|
9
|
+
return {
|
|
10
|
+
build: vi.fn((_engine) => {
|
|
11
|
+
return buildMockController();
|
|
12
|
+
}),
|
|
13
|
+
listing: options?.listing ?? true,
|
|
14
|
+
search: options?.search ?? true,
|
|
15
|
+
standalone: options?.standalone ?? true,
|
|
16
|
+
recommendation: options?.recommendation ?? true,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=mock-ssr-controller-definitions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock-ssr-controller-definitions.js","sourceRoot":"","sources":["../../src/__tests__/mock-ssr-controller-definitions.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,EAAE,EAAC,MAAM,QAAQ,CAAC;AAS1B,MAAM,UAAU,mBAAmB;IACjC,OAAO;QACL,SAAS,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC/B,KAAK,EAAE,EAAE;KACI,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,4BAA4B,CAC1C,OAAoC;IAEpC,OAAO;QACL,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE;YACvB,OAAO,mBAAmB,EAAE,CAAC;QAC/B,CAAC,CAAC;QACF,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,IAAI;QACjC,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,IAAI;QAC/B,UAAU,EAAE,OAAO,EAAE,UAAU,IAAI,IAAI;QACvC,cAAc,EAAE,OAAO,EAAE,cAAc,IAAI,IAAI;KAChD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock-ssr-engine.js","sourceRoot":"","sources":["../../src/__tests__/mock-ssr-engine.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,EAAE,EAAC,MAAM,QAAQ,CAAC;AAE1B,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,EAAE,CAC3C,CAAC;IACC,KAAK,EAAE,EAAE;IACT,SAAS,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,+BAA+B;IAChE,QAAQ,EAAE,EAAE,CAAC,EAAE,EAAE;CAClB,CAA8B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../src/__tests__/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAC,SAAS,EAAE,UAAU,EAAE,EAAE,EAAC,MAAM,QAAQ,CAAC;AAEjD,UAAU,CAAC,GAAG,EAAE;IACd,EAAE,CAAC,aAAa,EAAE,CAAC;AACrB,CAAC,CAAC,CAAC;AAEH,SAAS,CAAC,GAAG,EAAE;IACb,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type RenderResult } from '@testing-library/react';
|
|
2
|
+
import type { ReactElement } from 'react';
|
|
3
|
+
interface ProviderWrapperOptions {
|
|
4
|
+
controllers?: unknown;
|
|
5
|
+
engine?: unknown;
|
|
6
|
+
provider?: React.ComponentType<any>;
|
|
7
|
+
}
|
|
8
|
+
export declare function renderWithProvider(ui: ReactElement, options?: ProviderWrapperOptions): RenderResult;
|
|
9
|
+
export declare const waitForAsyncUpdates: () => Promise<void>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
export function renderWithProvider(ui, options) {
|
|
4
|
+
return render(ui, {
|
|
5
|
+
wrapper: createProviderWrapper(options),
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
export const waitForAsyncUpdates = async () => {
|
|
9
|
+
// Wait for React to flush all pending updates
|
|
10
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
11
|
+
// Wait for microtasks
|
|
12
|
+
await new Promise((resolve) => queueMicrotask(resolve));
|
|
13
|
+
};
|
|
14
|
+
function createProviderWrapper(options) {
|
|
15
|
+
return function ProviderWrapper({ children }) {
|
|
16
|
+
return options?.provider ? (_jsx(options.provider, { controllers: options?.controllers, engine: options?.engine, children: children })) : (
|
|
17
|
+
// biome-ignore lint/complexity/noUselessFragments: Fragment Required
|
|
18
|
+
_jsx(_Fragment, { children: children }));
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=test-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-utils.js","sourceRoot":"","sources":["../../src/__tests__/test-utils.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAoB,MAAM,EAAC,MAAM,wBAAwB,CAAC;AAUjE,MAAM,UAAU,kBAAkB,CAChC,EAAgB,EAChB,OAAgC;IAEhC,OAAO,MAAM,CAAC,EAAE,EAAE;QAChB,OAAO,EAAE,qBAAqB,CAAC,OAAO,CAAC;KACxC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,IAAI,EAAE;IAC5C,8CAA8C;IAC9C,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;IACvD,sBAAsB;IACtB,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;AAChE,CAAC,CAAC;AAEF,SAAS,qBAAqB,CAAC,OAAgC;IAC7D,OAAO,SAAS,eAAe,CAAC,EAAC,QAAQ,EAAoB;QAC3D,OAAO,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,CACzB,KAAC,OAAO,CAAC,QAAQ,IACf,WAAW,EAAE,OAAO,EAAE,WAAW,EACjC,MAAM,EAAE,OAAO,EAAE,MAAM,YAEtB,QAAQ,GACQ,CACpB,CAAC,CAAC,CAAC;QACF,qEAAqE;QACrE,4BAAG,QAAQ,GAAI,CAChB,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED