@graphcommerce/magento-product 11.0.0-canary.47 → 11.0.0-canary.48
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 +12 -0
- package/components/AddProductsToCart/AddProductsToCartForm.test.tsx +61 -0
- package/components/AddProductsToCart/AddProductsToCartForm.tsx +1 -1
- package/components/AddProductsToCart/index.ts +1 -0
- package/components/ProductListItems/filteredProductList.test.tsx +15 -0
- package/components/ProductListItems/filteredProductList.tsx +1 -1
- package/components/ProductPagePrice/index.ts +1 -0
- package/index.test.ts +22 -0
- package/package.json +13 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 11.0.0-canary.48
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#2699](https://github.com/graphcommerce-org/graphcommerce/pull/2699) [`f28586b`](https://github.com/graphcommerce-org/graphcommerce/commit/f28586b061f48cce3f3a70f7ec2c57f13868f8e1) - The packages export the modules that shops import from the package root: the types of `RichText`, `GetAddressesDocument`, `isSameAddress`, `isCartAddressACustomerAddress`, `AvailableShippingMethodFragment`, `AccountAddressFragment`, `CreateCustomerAddressDocument`, `UpdateCustomerAddressDocument`, `ValidatedPasswordElement`, `useCustomizableOptionPrice`, `UseAddProductsToCartActionFragment`, `useProductFiltersProSearchInput`, `useSearchPageAndParam`, `AddWishlistItemToCartProps` and `safeJsonLdReplacer`. ([@bramvanderholst](https://github.com/bramvanderholst))
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- [#2695](https://github.com/graphcommerce-org/graphcommerce/pull/2695) [`3c8eeb1`](https://github.com/graphcommerce-org/graphcommerce/commit/3c8eeb1962a63969f8dfb07d5efc5c0ce1a41aa1) - `AddProductsToCartForm` keeps the `defaultValues` prop, so the product page selects the variant of the URL again. ([@bramvanderholst](https://github.com/bramvanderholst))
|
|
12
|
+
|
|
13
|
+
- [#2700](https://github.com/graphcommerce-org/graphcommerce/pull/2700) [`5a1be63`](https://github.com/graphcommerce-org/graphcommerce/commit/5a1be637b734f5e0536999ebb0fc8ddcb69d96fb) - The links of a product list leave out the query string of the request. For `/shoes?gclid=abc`, the links were `/shoes?gclid=abc/page/2`, and crawlers followed them without end. ([@DivaniNL](https://github.com/DivaniNL))
|
|
14
|
+
|
|
3
15
|
## 11.0.0-canary.47
|
|
4
16
|
|
|
5
17
|
## 11.0.0-canary.46
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
|
|
3
|
+
import { ApolloClient, ApolloLink, ApolloProvider, InMemoryCache } from '@graphcommerce/graphql'
|
|
4
|
+
import { act } from 'react'
|
|
5
|
+
import { createRoot } from 'react-dom/client'
|
|
6
|
+
import { afterAll, beforeAll, expect, it, vi } from 'vitest'
|
|
7
|
+
import { AddProductsToCartForm } from './AddProductsToCartForm'
|
|
8
|
+
import { useFormAddProductsToCart } from './useFormAddProductsToCart'
|
|
9
|
+
|
|
10
|
+
vi.mock('next/router', () => ({
|
|
11
|
+
useRouter: () => ({ locale: 'en', pathname: '/p/[url]', push: vi.fn(), replace: vi.fn() }),
|
|
12
|
+
}))
|
|
13
|
+
vi.mock('./AddProductsToCartSnackbar', () => ({ AddProductsToCartSnackbar: () => null }))
|
|
14
|
+
vi.mock('@graphcommerce/magento-customer/hooks/useCustomerSession', async (importOriginal) => ({
|
|
15
|
+
...(await importOriginal<object>()),
|
|
16
|
+
useCustomerSession: () => ({ loggedIn: false }),
|
|
17
|
+
}))
|
|
18
|
+
|
|
19
|
+
beforeAll(() => {
|
|
20
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
afterAll(() => {
|
|
24
|
+
Reflect.deleteProperty(globalThis, 'IS_REACT_ACT_ENVIRONMENT')
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
function FormValues() {
|
|
28
|
+
return <output>{JSON.stringify(useFormAddProductsToCart().getValues())}</output>
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
it('keeps the defaultValues of the form', async () => {
|
|
32
|
+
const client = new ApolloClient({
|
|
33
|
+
cache: new InMemoryCache(),
|
|
34
|
+
link: ApolloLink.empty(),
|
|
35
|
+
defaultOptions: { preview: {} },
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
const container = window.document.createElement('div')
|
|
39
|
+
const root = createRoot(container)
|
|
40
|
+
await act(async () =>
|
|
41
|
+
root.render(
|
|
42
|
+
<ApolloProvider client={client}>
|
|
43
|
+
<AddProductsToCartForm
|
|
44
|
+
redirect='added'
|
|
45
|
+
defaultValues={{
|
|
46
|
+
cartItems: [{ sku: 'configurable', quantity: 1, selected_options: ['variant'] }],
|
|
47
|
+
}}
|
|
48
|
+
>
|
|
49
|
+
<FormValues />
|
|
50
|
+
</AddProductsToCartForm>
|
|
51
|
+
</ApolloProvider>,
|
|
52
|
+
),
|
|
53
|
+
)
|
|
54
|
+
const values: unknown = JSON.parse(container.querySelector('output')?.textContent ?? '{}')
|
|
55
|
+
await act(async () => root.unmount())
|
|
56
|
+
|
|
57
|
+
expect(values).toEqual({
|
|
58
|
+
redirect: 'added',
|
|
59
|
+
cartItems: [{ sku: 'configurable', quantity: 1, selected_options: ['variant'] }],
|
|
60
|
+
})
|
|
61
|
+
})
|
|
@@ -52,7 +52,7 @@ export function AddProductsToCartForm(props: AddProductsToCartFormProps) {
|
|
|
52
52
|
AddProductsToCartDocument,
|
|
53
53
|
{
|
|
54
54
|
...formProps,
|
|
55
|
-
defaultValues: { redirect },
|
|
55
|
+
defaultValues: { ...formProps.defaultValues, redirect },
|
|
56
56
|
// We're stripping out incomplete entered options.
|
|
57
57
|
onBeforeSubmit: async (variables) => {
|
|
58
58
|
const variables2 = (await formProps.onBeforeSubmit?.(variables)) ?? variables
|
|
@@ -7,6 +7,7 @@ export * from './AddProductsToCartSnackbar'
|
|
|
7
7
|
export * from './AddProductsToCartSnackbarMessage'
|
|
8
8
|
export * from './AddProductsToCartQuantity'
|
|
9
9
|
export * from './useAddProductsToCartAction'
|
|
10
|
+
export * from './UseAddProductsToCartAction.gql'
|
|
10
11
|
export * from './useFormAddProductsToCart'
|
|
11
12
|
export * from './toUserErrors'
|
|
12
13
|
export * from './findAddedItems'
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { renderToString } from 'react-dom/server'
|
|
2
|
+
import { expect, it, vi } from 'vitest'
|
|
3
|
+
import { productListLink } from '../../hooks/useProductListLink'
|
|
4
|
+
import { useRouterFilterParams } from './filteredProductList'
|
|
5
|
+
|
|
6
|
+
vi.mock('next/router', () => ({ useRouter: () => ({ asPath: '/shoes?gclid=abc' }) }))
|
|
7
|
+
|
|
8
|
+
function PageTwoLink() {
|
|
9
|
+
const { params } = useRouterFilterParams({ filterTypes: {} })
|
|
10
|
+
return params ? productListLink({ ...params, currentPage: 2 }) : null
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
it('leaves the query string of the request out of the pagination links', () => {
|
|
14
|
+
expect(renderToString(<PageTwoLink />)).toBe('/shoes/page/2')
|
|
15
|
+
})
|
|
@@ -94,7 +94,7 @@ export function useRouterFilterParams(props: {
|
|
|
94
94
|
const router = useRouter()
|
|
95
95
|
|
|
96
96
|
const path = router.asPath.startsWith('/c/') ? router.asPath.slice(3) : router.asPath.slice(1)
|
|
97
|
-
const [url, query] = extractUrlQuery({ url: path.split(
|
|
97
|
+
const [url, query] = extractUrlQuery({ url: path.split(/[?#]/)[0].split('/') })
|
|
98
98
|
if (!url || !query || !filterTypes) return { params, shallow: false }
|
|
99
99
|
|
|
100
100
|
const searchParam = url.startsWith('search') ? decodeURI(url.split('/')[1] ?? '') : null
|
package/index.test.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url'
|
|
2
|
+
import ts from 'typescript'
|
|
3
|
+
|
|
4
|
+
it('exports the modules that a shop imports', () => {
|
|
5
|
+
const root = fileURLToPath(new URL('.', import.meta.url))
|
|
6
|
+
const files = ts.sys
|
|
7
|
+
.readDirectory(root, ['.ts', '.tsx'])
|
|
8
|
+
.filter((file) => !file.includes('/node_modules/') && !/\.test\.tsx?$/.test(file))
|
|
9
|
+
const program = ts.createProgram(files, {
|
|
10
|
+
noEmit: true,
|
|
11
|
+
noResolve: true,
|
|
12
|
+
jsx: ts.JsxEmit.ReactJSX,
|
|
13
|
+
})
|
|
14
|
+
const checker = program.getTypeChecker()
|
|
15
|
+
const index = program.getSourceFile(`${root}index.ts`)
|
|
16
|
+
const moduleSymbol = index && checker.getSymbolAtLocation(index)
|
|
17
|
+
const exported = moduleSymbol ? checker.getExportsOfModule(moduleSymbol).map((s) => s.name) : []
|
|
18
|
+
|
|
19
|
+
expect(exported).toEqual(
|
|
20
|
+
expect.arrayContaining(['UseAddProductsToCartActionFragment', 'useCustomizableOptionPrice']),
|
|
21
|
+
)
|
|
22
|
+
})
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/magento-product",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "11.0.0-canary.
|
|
5
|
+
"version": "11.0.0-canary.48",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -18,18 +18,18 @@
|
|
|
18
18
|
"typescript": "5.9.3"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
|
-
"@graphcommerce/ecommerce-ui": "^11.0.0-canary.
|
|
22
|
-
"@graphcommerce/eslint-config-pwa": "^11.0.0-canary.
|
|
23
|
-
"@graphcommerce/framer-next-pages": "^11.0.0-canary.
|
|
24
|
-
"@graphcommerce/framer-scroller": "^11.0.0-canary.
|
|
25
|
-
"@graphcommerce/graphql": "^11.0.0-canary.
|
|
26
|
-
"@graphcommerce/graphql-mesh": "^11.0.0-canary.
|
|
27
|
-
"@graphcommerce/image": "^11.0.0-canary.
|
|
28
|
-
"@graphcommerce/magento-cart": "^11.0.0-canary.
|
|
29
|
-
"@graphcommerce/magento-store": "^11.0.0-canary.
|
|
30
|
-
"@graphcommerce/next-ui": "^11.0.0-canary.
|
|
31
|
-
"@graphcommerce/prettier-config-pwa": "^11.0.0-canary.
|
|
32
|
-
"@graphcommerce/typescript-config-pwa": "^11.0.0-canary.
|
|
21
|
+
"@graphcommerce/ecommerce-ui": "^11.0.0-canary.48",
|
|
22
|
+
"@graphcommerce/eslint-config-pwa": "^11.0.0-canary.48",
|
|
23
|
+
"@graphcommerce/framer-next-pages": "^11.0.0-canary.48",
|
|
24
|
+
"@graphcommerce/framer-scroller": "^11.0.0-canary.48",
|
|
25
|
+
"@graphcommerce/graphql": "^11.0.0-canary.48",
|
|
26
|
+
"@graphcommerce/graphql-mesh": "^11.0.0-canary.48",
|
|
27
|
+
"@graphcommerce/image": "^11.0.0-canary.48",
|
|
28
|
+
"@graphcommerce/magento-cart": "^11.0.0-canary.48",
|
|
29
|
+
"@graphcommerce/magento-store": "^11.0.0-canary.48",
|
|
30
|
+
"@graphcommerce/next-ui": "^11.0.0-canary.48",
|
|
31
|
+
"@graphcommerce/prettier-config-pwa": "^11.0.0-canary.48",
|
|
32
|
+
"@graphcommerce/typescript-config-pwa": "^11.0.0-canary.48",
|
|
33
33
|
"@lingui/core": "^5",
|
|
34
34
|
"@lingui/macro": "^5",
|
|
35
35
|
"@lingui/react": "^5",
|