@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.
@@ -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', () => {
@@ -1723,7 +1723,8 @@ export const buildIteratorBlock = ({
1723
1723
  ? {
1724
1724
  itemScopeProduct: resolveCollectionRowProduct(
1725
1725
  rawItem as Record<string, unknown>
1726
- )
1726
+ ),
1727
+ itemScopeIndex: index
1727
1728
  }
1728
1729
  : {})
1729
1730
  };
@@ -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
+ );