Skip to content

Commit 1e392e7

Browse files
authored
Merge pull request #2686 from SalesforceCommerceCloud/bendvc/update-pwa-developer-agent-only
[Chore🧹] Update `feature/pwa-developer-agent-only` from `develop`
2 parents 28d92ef + b11a6c9 commit 1e392e7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+8256
-4138
lines changed

.cursor/rules/testing/unit-tests-generic.mdc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,26 @@ description: USE WHEN writing unit tests for components in template packages
33
globs: ["packages/template-*/*/components/**/*.test.{js,jsx,ts,tsx}"]
44
alwaysApply: false
55
---
6+
USE WHEN writing unit tests for components in template packages
67

78
# 🧪 Generic Component Test Rules
89

10+
# CRITICAL: AI Attribution Requirements
11+
* **IMPORTANT** All individual test methods generated or modified by Cursor MUST include an AI attribution comment directly above the test stating the following:
12+
"DO NOT REMOVE THIS COMMENT! This test was generated by Cursor". The comment should go on the test method and not the test class. Failure to add an AI Attribution Comment will be considered a failure of test generation.
13+
* The AI attribution comment MUST include a comment declaring the LLM model that was used in writing the test on its own line.
14+
15+
*Sample AI Attribution Comment*
16+
```
17+
/*
18+
* DO NOT REMOVE THIS COMMENT! This test was generated by Cursor
19+
* This test was generated with the following model: Claude 3.5 Sonnet
20+
*/
21+
test('renders component correctly', () => {
22+
// test implementation
23+
})
24+
```
25+
926
## Structure & Best Practices
1027
- Use `describe` blocks to group tests, `test` for individual cases
1128
- Use `beforeEach` for setup, clear mocks after each test
@@ -34,3 +51,23 @@ describe('MyComponent', () => {
3451
})
3552
})
3653
```
54+
55+
## Running Tests
56+
After creating unit tests, **ALWAYS run the tests** to verify they pass and provide feedback on test results.
57+
58+
### Command Format:
59+
```bash
60+
cd packages/<package-name> && npm run test -- '<relative-path-to-test-file> --coverage=false'
61+
```
62+
63+
### Examples:
64+
```bash
65+
# Run specific test file from packages directory
66+
cd packages/template-retail-react-app && npm run test -- 'app/components/drawer-menu/drawer-menu.test.js --coverage=false'
67+
```
68+
69+
### After Running Tests:
70+
- Report if tests **pass** or **fail**
71+
- If tests fail, provide the error messages and fix any issues
72+
- Confirm test coverage is appropriate for the component's core functionality
73+
- Suggest any additional tests if critical functionality is missing

.cursor/rules/testing/unit-tests-template-retail-react-app.mdc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ description: USE WHEN writing unit tests in template-retail-react-app components
33
globs: ["packages/template-retail-react-app/app/components/**/*.test.{js,jsx,ts,tsx}"]
44
alwaysApply: false
55
---
6-
76
# 🛍️ Retail React App Test Rules
87

98
## Package-Specific Requirements
@@ -15,6 +14,10 @@ alwaysApply: false
1514
## API Mocking
1615
- Use `prependHandlersToServer` or `msw` for API mocking
1716

17+
## Mock Data Usage
18+
19+
- **Mandatory**: Always use existing mock data from `@salesforce/retail-react-app/app/mocks/` if it is available. This ensures consistency across tests and reduces redundancy. Creating new mock data should only be considered if the required data is not already present in the mocks directory.
20+
1821
```js
1922
import {screen} from '@testing-library/react'
2023
import {renderWithProviders} from '@salesforce/retail-react-app/app/utils/test-utils'

packages/commerce-sdk-react/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
## v3.4.0-dev.0 (May 23, 2025)
2+
3+
- Optionally disable auth init in CommerceApiProvider [#2629](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2629)
24
- Now compatible with either React 17 and 18 [#2506](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2506)
35
- Gracefully handle missing SDK Clients in CommerceApiProvider [#2539](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2539)
46
- Refactor commerce-sdk-react to allow injecting ApiClients [#2519](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2519)

packages/commerce-sdk-react/src/provider.test.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,20 @@ describe('provider', () => {
7272
expect(element).toBeInTheDocument()
7373
expect(element.textContent?.includes('/mobify/slas/private')).toBeTruthy()
7474
})
75+
76+
test('does not call Auth.ready() when disableAuthInit is true', () => {
77+
renderWithProviders(<h1>Auth not initialized!</h1>, {disableAuthInit: true})
78+
expect(screen.getByText('Auth not initialized!')).toBeInTheDocument()
79+
expect(Auth).toHaveBeenCalledTimes(1)
80+
const authInstance = (Auth as jest.Mock).mock.instances[0]
81+
expect(authInstance.ready).toHaveBeenCalledTimes(0)
82+
})
83+
84+
test('calls Auth.ready() when disableAuthInit is false', () => {
85+
renderWithProviders(<h1>Auth initialized!</h1>, {disableAuthInit: false})
86+
expect(screen.getByText('Auth initialized!')).toBeInTheDocument()
87+
expect(Auth).toHaveBeenCalledTimes(1)
88+
const authInstance = (Auth as jest.Mock).mock.instances[0]
89+
expect(authInstance.ready).toHaveBeenCalledTimes(1)
90+
})
7591
})

packages/commerce-sdk-react/src/provider.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export interface CommerceApiProviderProps extends ApiClientConfigParams {
4949
refreshTokenRegisteredCookieTTL?: number
5050
refreshTokenGuestCookieTTL?: number
5151
apiClients?: ApiClients
52+
disableAuthInit?: boolean
5253
}
5354

5455
/**
@@ -132,7 +133,8 @@ const CommerceApiProvider = (props: CommerceApiProviderProps): ReactElement => {
132133
passwordlessLoginCallbackURI,
133134
refreshTokenRegisteredCookieTTL,
134135
refreshTokenGuestCookieTTL,
135-
apiClients
136+
apiClients,
137+
disableAuthInit = false
136138
} = props
137139

138140
// Set the logger based on provided configuration, or default to the console object if no logger is provided
@@ -270,7 +272,11 @@ const CommerceApiProvider = (props: CommerceApiProviderProps): ReactElement => {
270272
])
271273

272274
// Initialize the session
273-
useEffect(() => void auth.ready(), [auth])
275+
useEffect(() => {
276+
if (!disableAuthInit) {
277+
void auth.ready()
278+
}
279+
}, [auth, disableAuthInit])
274280

275281
return (
276282
<ConfigContext.Provider

packages/pwa-kit-create-app/CHANGELOG.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
## v3.11.0-dev.0 (May 23, 2025)
2+
- Add `program.json` + Support for Agent-Friendly CLI Input via stdio [#2662](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2662)
3+
- Change the default ECOM instance in the generated application [#2610](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2610)
4+
- Load active data scripts on demand only [#2623](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2623)
25

36
## v3.10.0 (May 22, 2025)
4-
- Add Data Cloud API configuration to `default.js`. [#2318] (https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2229)
7+
- Add Data Cloud API configuration to `default.js`. [#2318](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2318)
58
- Fix dependencies vulnerabilities [#2338](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2338)
69

710
## v3.9.1 (Mar 05, 2025)
811
- Update PWA-Kit SDKs to v3.9.1 [#2301](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2301)
912

1013
## v3.9.0 (Feb 18, 2025)
1114

12-
- Update `default.js` and `ssr.js` template to support new passwordless, social, and reset password flows. [#2263] (https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2263)
15+
- Update `default.js` and `ssr.js` template to support new passwordless, social, and reset password flows. [#2263](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2263)
1316
- Support Node 22 [#2218](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2218)
14-
- Update `default.js` template to include new login configurations [#2079] (https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2079)
17+
- Update `default.js` template to include new login configurations [#2079](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2079)
1518
- Handle import error when ssr.js imports from template retail react app [#2270](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2270)
1619

1720
## v3.8.0 (Oct 28, 2024)

packages/pwa-kit-create-app/assets/bootstrap/js/overrides/app/constants.js.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import {
1717
DEFAULT_LIMIT_VALUES,
1818
DEFAULT_SEARCH_PARAMS
19-
} from '{{preset.templateSource.id}}/app/constants'
19+
} from '{{template.source.name}}/app/constants'
2020

2121
// original value is 25
2222
DEFAULT_LIMIT_VALUES[0] = 3
@@ -26,4 +26,4 @@ export const CUSTOM_HOME_TITLE = '🎉 Hello Extensible React Template!'
2626

2727
export {DEFAULT_LIMIT_VALUES, DEFAULT_SEARCH_PARAMS}
2828

29-
export * from '{{preset.templateSource.id}}/app/constants'
29+
export * from '{{template.source.name}}/app/constants'

packages/pwa-kit-create-app/assets/bootstrap/js/overrides/app/pages/home/index.jsx.hbs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ import {useIntl, FormattedMessage} from 'react-intl'
99
import {useLocation} from 'react-router-dom'
1010

1111
// Components
12-
import {Box, Button, Stack, Link} from '{{preset.templateSource.id}}/app/components/shared/ui'
12+
import {Box, Button, Stack, Link} from '{{template.source.name}}/app/components/shared/ui'
1313

1414
// Project Components
15-
import Hero from '{{preset.templateSource.id}}/app/components/hero'
16-
import Seo from '{{preset.templateSource.id}}/app/components/seo'
17-
import Section from '{{preset.templateSource.id}}/app/components/section'
18-
import ProductScroller from '{{preset.templateSource.id}}/app/components/product-scroller'
15+
import Hero from '{{template.source.name}}/app/components/hero'
16+
import Seo from '{{template.source.name}}/app/components/seo'
17+
import Section from '{{template.source.name}}/app/components/section'
18+
import ProductScroller from '{{template.source.name}}/app/components/product-scroller'
1919

2020
// Others
2121
import {getAssetUrl} from '@salesforce/pwa-kit-react-sdk/ssr/universal/utils'
2222

2323
//Hooks
24-
import useEinstein from '{{preset.templateSource.id}}/app/hooks/use-einstein'
24+
import useEinstein from '{{template.source.name}}/app/hooks/use-einstein'
2525

2626
// Constants
2727
import {

packages/pwa-kit-create-app/assets/bootstrap/js/overrides/app/routes.jsx.hbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import loadable from '@loadable/component'
1515
import {getConfig} from '@salesforce/pwa-kit-runtime/utils/ssr-config'
1616

1717
// Components
18-
import {Skeleton} from '{{preset.templateSource.id}}/app/components/shared/ui'
19-
import {configureRoutes} from '{{preset.templateSource.id}}/app/utils/routes-utils'
20-
import {routes as _routes} from '{{preset.templateSource.id}}/app/routes'
18+
import {Skeleton} from '{{template.source.name}}/app/components/shared/ui'
19+
import {configureRoutes} from '{{template.source.name}}/app/utils/routes-utils'
20+
import {routes as _routes} from '{{template.source.name}}/app/routes'
2121

2222
const fallback = <Skeleton height="75vh" width="100%" />
2323

packages/pwa-kit-create-app/assets/bootstrap/js/overrides/app/ssr.js.hbs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ const {handler} = runtime.createHandler(options, (app) => {
289289
directives: {
290290
'img-src': [
291291
// Default source for product images - replace with your CDN
292-
'*.commercecloud.salesforce.com'
292+
'*.commercecloud.salesforce.com',
293+
'*.demandware.net'
293294
],
294295
'script-src': [
295296
// Used by the service worker in /worker/main.js

0 commit comments

Comments
 (0)