@salesforce/retail-react-app 10.3.0-nightly-20261008080708 → 10.3.0-preview.1
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 +4 -5
- package/app/components/_app/index.jsx +3 -145
- package/app/components/_app/index.test.js +2 -100
- package/app/components/inline-agent-widget/index.jsx +3 -17
- package/app/components/shopper-agent/index.jsx +6 -13
- package/app/components/shopper-agent/index.test.js +0 -59
- package/app/hooks/use-inline-agent-widget.js +1 -49
- package/app/mocks/page-designer.js +0 -26
- package/app/page-designer/layouts/index.js +0 -1
- package/app/page-designer/registry.js +0 -8
- package/app/pages/product-detail/index.jsx +1 -10
- package/app/routes.jsx +0 -6
- package/app/ssr.js +0 -23
- package/app/static/inline-agent-widget.umd.js +28 -26
- package/package.json +8 -8
- package/app/page-designer/content/announcement-banner/index.jsx +0 -148
- package/app/page-designer/content/announcement-banner/index.test.js +0 -57
- package/app/page-designer/content/index.js +0 -8
- package/app/page-designer/layouts/header/index.jsx +0 -33
- package/app/page-designer/layouts/header/index.test.js +0 -38
- package/app/page-designer/preview-page.js +0 -28
- package/app/page-designer/preview-page.test.js +0 -26
- package/app/pages/component-preview/index.jsx +0 -73
- package/app/pages/component-preview/index.test.js +0 -117
- package/app/utils/inline-agent-widget-utils.js +0 -74
- package/app/utils/inline-agent-widget-utils.test.js +0 -87
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2024, Salesforce, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
MAX_PDP_QUESTIONS,
|
|
10
|
-
parsePdpQuestions
|
|
11
|
-
} from '@salesforce/retail-react-app/app/utils/inline-agent-widget-utils'
|
|
12
|
-
|
|
13
|
-
describe('parsePdpQuestions', () => {
|
|
14
|
-
let warnSpy
|
|
15
|
-
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {})
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
afterEach(() => {
|
|
21
|
-
warnSpy.mockRestore()
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
test('parses a JSON-encoded array of strings (SCAPI c_pdpQuestions shape)', () => {
|
|
25
|
-
const raw =
|
|
26
|
-
'["What does SmartTrack do?", "Does it track sleep automatically?", "Tell me about the reminders to move."]'
|
|
27
|
-
expect(parsePdpQuestions(raw)).toEqual([
|
|
28
|
-
'What does SmartTrack do?',
|
|
29
|
-
'Does it track sleep automatically?',
|
|
30
|
-
'Tell me about the reminders to move.'
|
|
31
|
-
])
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
test('returns [] for null / undefined / empty / non-string input', () => {
|
|
35
|
-
expect(parsePdpQuestions(undefined)).toEqual([])
|
|
36
|
-
expect(parsePdpQuestions(null)).toEqual([])
|
|
37
|
-
expect(parsePdpQuestions('')).toEqual([])
|
|
38
|
-
expect(parsePdpQuestions(42)).toEqual([])
|
|
39
|
-
expect(parsePdpQuestions(['already', 'parsed'])).toEqual([])
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
test('returns [] (does not throw) for non-JSON input and warns so merchandisers can debug', () => {
|
|
43
|
-
expect(() => parsePdpQuestions('not-json')).not.toThrow()
|
|
44
|
-
expect(parsePdpQuestions('not-json')).toEqual([])
|
|
45
|
-
expect(warnSpy).toHaveBeenCalledWith(
|
|
46
|
-
expect.stringContaining('malformed c_pdpQuestions: not valid JSON'),
|
|
47
|
-
'not-json',
|
|
48
|
-
expect.any(Error)
|
|
49
|
-
)
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
test('returns [] when the JSON parses to something other than an array, and warns', () => {
|
|
53
|
-
expect(parsePdpQuestions('"just a string"')).toEqual([])
|
|
54
|
-
expect(parsePdpQuestions('{"q":"x"}')).toEqual([])
|
|
55
|
-
expect(parsePdpQuestions('null')).toEqual([])
|
|
56
|
-
// 3 non-array parses → 3 warns, each surfacing the parsed value
|
|
57
|
-
expect(warnSpy).toHaveBeenCalledTimes(3)
|
|
58
|
-
expect(warnSpy).toHaveBeenCalledWith(
|
|
59
|
-
expect.stringContaining('parsed value is not an array'),
|
|
60
|
-
expect.anything()
|
|
61
|
-
)
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
test('does NOT warn on valid empty / non-string input (silent no-op)', () => {
|
|
65
|
-
parsePdpQuestions(undefined)
|
|
66
|
-
parsePdpQuestions(null)
|
|
67
|
-
parsePdpQuestions('')
|
|
68
|
-
parsePdpQuestions('[]')
|
|
69
|
-
expect(warnSpy).not.toHaveBeenCalled()
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
test('drops non-string entries and trims / dedupes / caps at 5', () => {
|
|
73
|
-
expect(parsePdpQuestions('["ok", 42, null, " padded ", "ok", "kept"]')).toEqual([
|
|
74
|
-
'ok',
|
|
75
|
-
'padded',
|
|
76
|
-
'kept'
|
|
77
|
-
])
|
|
78
|
-
const many = JSON.stringify(['Q1', 'Q2', 'Q3', 'Q4', 'Q5', 'Q6'])
|
|
79
|
-
const out = parsePdpQuestions(many)
|
|
80
|
-
expect(out).toHaveLength(MAX_PDP_QUESTIONS)
|
|
81
|
-
expect(out).toEqual(['Q1', 'Q2', 'Q3', 'Q4', 'Q5'])
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
test('respects an explicit maxCount override', () => {
|
|
85
|
-
expect(parsePdpQuestions('["A","B","C","D"]', 2)).toEqual(['A', 'B'])
|
|
86
|
-
})
|
|
87
|
-
})
|