@akinon/pz-click-collect 2.0.10 → 2.0.11-rc.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/CHANGELOG.md +7 -0
- package/jest.config.js +20 -0
- package/package.json +7 -1
- package/src/__tests__/click-collect.test.tsx +96 -0
- package/src/__tests__/mocks/redux-store.ts +3 -0
- package/tsconfig.test.json +18 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @akinon/pz-click-collect
|
|
2
2
|
|
|
3
|
+
## 2.0.11-rc.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 823a4449: ZERO-4193: Upgrade TypeScript to version 5.2.2 across multiple packages
|
|
8
|
+
- 00b9f488: ZERO-4207: Add Jest configuration and initial tests for ClickCollect component
|
|
9
|
+
|
|
3
10
|
## 2.0.10
|
|
4
11
|
|
|
5
12
|
## 2.0.9
|
package/jest.config.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** @type {import('ts-jest').JestConfigWithTsJest} **/
|
|
2
|
+
module.exports = {
|
|
3
|
+
preset: 'ts-jest',
|
|
4
|
+
testEnvironment: 'node',
|
|
5
|
+
testMatch: ['**/?(*.)+(test).tsx'],
|
|
6
|
+
testPathIgnorePatterns: ['/node_modules/', '/src/__tests__/mocks/'],
|
|
7
|
+
moduleNameMapper: {
|
|
8
|
+
'^redux/store$': '<rootDir>/src/__tests__/mocks/redux-store.ts'
|
|
9
|
+
},
|
|
10
|
+
transform: {
|
|
11
|
+
'^.+.tsx?$': [
|
|
12
|
+
'ts-jest',
|
|
13
|
+
{
|
|
14
|
+
tsconfig: 'tsconfig.test.json',
|
|
15
|
+
diagnostics: false
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node']
|
|
20
|
+
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akinon/pz-click-collect",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.11-rc.0",
|
|
4
4
|
"main": "./src/index.tsx",
|
|
5
5
|
"module": "./src/index.tsx",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "jest",
|
|
9
|
+
"test:watch": "jest --watch"
|
|
10
|
+
},
|
|
7
11
|
"devDependencies": {
|
|
12
|
+
"@types/jest": "^29.5.14",
|
|
13
|
+
"@types/node": "^18.7.8",
|
|
8
14
|
"@types/react": "^18.0.15",
|
|
9
15
|
"@types/react-dom": "^18.0.6",
|
|
10
16
|
"react": "19.2.5",
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { renderToStaticMarkup } from 'react-dom/server';
|
|
3
|
+
import { ClickCollect, ClickCollectTranslationsProps } from '../index';
|
|
4
|
+
|
|
5
|
+
const state = {
|
|
6
|
+
checkout: {
|
|
7
|
+
deliveryOptions: [
|
|
8
|
+
{ pk: 1, delivery_option_type: 'customer' },
|
|
9
|
+
{ pk: 2, delivery_option_type: 'retail_store' }
|
|
10
|
+
],
|
|
11
|
+
retailStores: [],
|
|
12
|
+
preOrder: {
|
|
13
|
+
billing_address: { pk: 10 },
|
|
14
|
+
shipping_address: { pk: 11 },
|
|
15
|
+
retail_store: null,
|
|
16
|
+
delivery_option: { pk: 1 }
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const setDeliveryOption = jest.fn();
|
|
22
|
+
const setRetailStore = jest.fn();
|
|
23
|
+
const setShippingOption = jest.fn();
|
|
24
|
+
const setAddresses = jest.fn();
|
|
25
|
+
|
|
26
|
+
jest.mock('@akinon/next/components', () => ({
|
|
27
|
+
Icon: ({ name }: { name: string }) => <span data-icon={name}>{name}</span>,
|
|
28
|
+
LoaderSpinner: () => <span data-testid="click-collect-loader">loading</span>
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
jest.mock('@akinon/next/redux/hooks', () => ({
|
|
32
|
+
useAppSelector: (selector: (mockState: typeof state) => unknown) =>
|
|
33
|
+
selector(state)
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
jest.mock('@akinon/next/data/client/checkout', () => ({
|
|
37
|
+
useSetDeliveryOptionMutation: () => [setDeliveryOption, { isLoading: false }],
|
|
38
|
+
useSetRetailStoreMutation: () => [setRetailStore, { isLoading: false }],
|
|
39
|
+
useSetShippingOptionMutation: () => [setShippingOption, { isLoading: false }],
|
|
40
|
+
useSetAddressesMutation: () => [setAddresses, { isLoading: false }]
|
|
41
|
+
}));
|
|
42
|
+
|
|
43
|
+
jest.mock('redux/store', () => ({}), { virtual: true });
|
|
44
|
+
|
|
45
|
+
describe('ClickCollect', () => {
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
setDeliveryOption.mockReset();
|
|
48
|
+
setRetailStore.mockReset();
|
|
49
|
+
setShippingOption.mockReset();
|
|
50
|
+
setAddresses.mockReset();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('renders the default inactive state when no custom renderer is provided', () => {
|
|
54
|
+
const html = renderToStaticMarkup(
|
|
55
|
+
<ClickCollect
|
|
56
|
+
addressTypeParam="shippingAddressPk"
|
|
57
|
+
translations={{} as ClickCollectTranslationsProps}
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
expect(html).toContain('DELIVERY FROM THE STORE');
|
|
62
|
+
expect(html).toContain('click-collect-add-new-address');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('passes merged translations and inactive status to custom renderers', () => {
|
|
66
|
+
let capturedIsActive: boolean | null = null;
|
|
67
|
+
let capturedTranslations: ClickCollectTranslationsProps | null = null;
|
|
68
|
+
|
|
69
|
+
const html = renderToStaticMarkup(
|
|
70
|
+
<ClickCollect
|
|
71
|
+
addressTypeParam="shippingAddressPk"
|
|
72
|
+
translations={{
|
|
73
|
+
deliveryFromTheStore: 'Magazadan teslim',
|
|
74
|
+
deliveryStore: 'Teslim magazasi'
|
|
75
|
+
}}
|
|
76
|
+
renderer={{
|
|
77
|
+
renderContainer: ({ children, isActive }) => {
|
|
78
|
+
capturedIsActive = isActive;
|
|
79
|
+
return <section>{children}</section>;
|
|
80
|
+
},
|
|
81
|
+
renderInactiveState: ({ translations }) => {
|
|
82
|
+
capturedTranslations = translations;
|
|
83
|
+
return <span>{translations.deliveryFromTheStore}</span>;
|
|
84
|
+
}
|
|
85
|
+
}}
|
|
86
|
+
/>
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
expect(capturedIsActive).toBe(false);
|
|
90
|
+
expect(capturedTranslations).toEqual({
|
|
91
|
+
deliveryFromTheStore: 'Magazadan teslim',
|
|
92
|
+
deliveryStore: 'Teslim magazasi'
|
|
93
|
+
});
|
|
94
|
+
expect(html).toContain('Magazadan teslim');
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2019",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"jsx": "react-jsx",
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"allowSyntheticDefaultImports": true,
|
|
9
|
+
"isolatedModules": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"strict": false,
|
|
12
|
+
"baseUrl": ".",
|
|
13
|
+
"paths": {
|
|
14
|
+
"redux/store": ["src/__tests__/mocks/redux-store.ts"]
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"include": ["src/**/*.ts", "src/**/*.tsx"]
|
|
18
|
+
}
|