@akinon/pz-theme 2.0.163-beta.0 → 2.0.163
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 -4
- package/package.json +4 -4
- package/src/__tests__/commerce-channel-frozen.test.ts +12 -1
- package/src/__tests__/section-list-identity.test.tsx +113 -0
- package/src/blocks/__tests__/favourites-grid-impression.test.tsx +217 -0
- package/src/blocks/__tests__/group-block-list-click.test.tsx +90 -0
- package/src/blocks/favourites-grid-block.tsx +16 -18
- package/src/blocks/group-block.tsx +14 -2
- package/src/blocks/item-template.tsx +1 -0
- package/src/blocks/product-block-utils.tsx +5 -1
- package/src/blocks/product-recommendations-block.tsx +45 -13
- package/src/hooks/__tests__/use-list-impression.test.tsx +228 -0
- package/src/hooks/__tests__/use-section-seen.test.tsx +55 -2
- package/src/hooks/use-list-impression.ts +116 -0
- package/src/hooks/use-section-seen.ts +22 -2
- package/src/sections/__tests__/posts-slider-select-item.test.tsx +205 -0
- package/src/sections/__tests__/section-wrapper-list.test.tsx +148 -0
- package/src/sections/posts-slider-section.tsx +62 -2
- package/src/sections/section-wrapper.tsx +32 -2
- package/src/theme-block.tsx +6 -0
- package/src/theme-section-data-context.tsx +33 -0
- package/src/theme-section.tsx +60 -2
- package/src/utils/__tests__/section-impressions.test.ts +68 -0
- package/src/utils/iterator-price-shapes.test.ts +13 -0
- package/src/utils/iterator-utils.ts +2 -1
- package/src/utils/section-impressions.ts +37 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { reportsOwnImpressions } from '../section-impressions';
|
|
2
|
+
import type { Block } from '../../theme-block';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A section reports its products as one list impression unless a block in
|
|
6
|
+
* it already does (ZERO-5305): one view_item_list per list, never two.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const block = (
|
|
10
|
+
type: string,
|
|
11
|
+
properties: Record<string, unknown> = {},
|
|
12
|
+
blocks: Block[] = []
|
|
13
|
+
) =>
|
|
14
|
+
({
|
|
15
|
+
id: `${type}-1`,
|
|
16
|
+
type,
|
|
17
|
+
label: type,
|
|
18
|
+
value: '',
|
|
19
|
+
properties,
|
|
20
|
+
styles: {},
|
|
21
|
+
order: 0,
|
|
22
|
+
hidden: false,
|
|
23
|
+
blocks
|
|
24
|
+
} as unknown as Block);
|
|
25
|
+
|
|
26
|
+
describe('reportsOwnImpressions (ZERO-5305)', () => {
|
|
27
|
+
it('leaves the listing and favourites grids their own reports, however deep', () => {
|
|
28
|
+
expect(reportsOwnImpressions([block('product-grid')])).toBe(true);
|
|
29
|
+
expect(
|
|
30
|
+
reportsOwnImpressions([
|
|
31
|
+
block('group', {}, [block('group', {}, [block('favourites-grid')])])
|
|
32
|
+
])
|
|
33
|
+
).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('leaves a recommendations strip drawing the section’s rows its own report', () => {
|
|
37
|
+
expect(
|
|
38
|
+
reportsOwnImpressions([
|
|
39
|
+
block('product-recommendations', { source: 'section' })
|
|
40
|
+
])
|
|
41
|
+
).toBe(true);
|
|
42
|
+
expect(
|
|
43
|
+
reportsOwnImpressions([
|
|
44
|
+
block('product-recommendations', {
|
|
45
|
+
source: { desktop: 'section', mobile: 'collection' }
|
|
46
|
+
})
|
|
47
|
+
])
|
|
48
|
+
).toBe(true);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('still reports the section’s rows next to a strip with a source of its own', () => {
|
|
52
|
+
expect(
|
|
53
|
+
reportsOwnImpressions([
|
|
54
|
+
block('product-recommendations', { source: 'recently-viewed' })
|
|
55
|
+
])
|
|
56
|
+
).toBe(false);
|
|
57
|
+
expect(reportsOwnImpressions([block('product-recommendations')])).toBe(
|
|
58
|
+
false
|
|
59
|
+
);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('reports a plain carousel’s rows itself', () => {
|
|
63
|
+
expect(reportsOwnImpressions([block('group', {}, [block('image')])])).toBe(
|
|
64
|
+
false
|
|
65
|
+
);
|
|
66
|
+
expect(reportsOwnImpressions(undefined)).toBe(false);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
@@ -359,6 +359,19 @@ describe('a collection row published in the listing row shape', () => {
|
|
|
359
359
|
false
|
|
360
360
|
);
|
|
361
361
|
});
|
|
362
|
+
|
|
363
|
+
it('numbers each scoped row, for the position a card click reports (ZERO-5305)', () => {
|
|
364
|
+
const expanded = buildIteratorBlock({
|
|
365
|
+
iteratorBlock: cardIterator({}, [text('name', { dataBinding: 'item.name' })]),
|
|
366
|
+
sectionDataSource: source([
|
|
367
|
+
omnitronRow(7, '2999.00', ''),
|
|
368
|
+
omnitronRow(8, '1999.00', '')
|
|
369
|
+
]),
|
|
370
|
+
pageContext: null
|
|
371
|
+
} as never);
|
|
372
|
+
|
|
373
|
+
expect(expanded.blocks?.map((clone) => clone.itemScopeIndex)).toEqual([0, 1]);
|
|
374
|
+
});
|
|
362
375
|
});
|
|
363
376
|
|
|
364
377
|
describe('a repeat inside a collection row', () => {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Block } from '../theme-block';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Whether a block inside a section already reports the section's products
|
|
5
|
+
* as a list impression of its own (ZERO-5305), so the section must not report
|
|
6
|
+
* them a second time:
|
|
7
|
+
*
|
|
8
|
+
* - the listing grid and the favourites grid report their own pages;
|
|
9
|
+
* - a recommendations strip drawing the SECTION's rows (`source: section`)
|
|
10
|
+
* reports them under its title.
|
|
11
|
+
*
|
|
12
|
+
* A strip with a source of its own (a collection by id, recently viewed,
|
|
13
|
+
* favourites) shows other products, so the section's rows still need their
|
|
14
|
+
* own report. The source is read at every breakpoint: a strip that draws the
|
|
15
|
+
* section's rows anywhere draws them.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const OWN_IMPRESSION_GRIDS = new Set(['product-grid', 'favourites-grid']);
|
|
19
|
+
|
|
20
|
+
const drawsSectionRows = (block: Block): boolean => {
|
|
21
|
+
const source = (block.properties as Record<string, unknown> | undefined)
|
|
22
|
+
?.source;
|
|
23
|
+
const values =
|
|
24
|
+
source && typeof source === 'object'
|
|
25
|
+
? Object.values(source as Record<string, unknown>)
|
|
26
|
+
: [source];
|
|
27
|
+
|
|
28
|
+
return values.some((value) => value === 'section');
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const reportsOwnImpressions = (blocks: Block[] | undefined): boolean =>
|
|
32
|
+
(blocks ?? []).some(
|
|
33
|
+
(block) =>
|
|
34
|
+
OWN_IMPRESSION_GRIDS.has(block.type) ||
|
|
35
|
+
(block.type === 'product-recommendations' && drawsSectionRows(block)) ||
|
|
36
|
+
reportsOwnImpressions(block.blocks)
|
|
37
|
+
);
|