Skip to content

Commit caa5601

Browse files
authored
[CI-4670]- Add data-cnstrc-result-id data attribute to the results container (#171)
* [CI-4670]- Add data-cnstrc-result-id data attribute to the results container * updated test
1 parent 3bac81c commit caa5601

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

spec/components/CioPlpGrid/CioPlpGrid.server.test.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ describe('Testing Component on the server: CioPlpGrid', () => {
8686
);
8787

8888
expect(html).toContain('data-cnstrc-search');
89-
expect(html).toContain('data-cnstrc-num-results="357"');
89+
expect(html).toContain(`data-cnstrc-num-results="${mockSearchData.response.totalNumResults}"`);
90+
expect(html).toContain(`data-cnstrc-result-id="${mockSearchData.resultId}"`);
9091
});
9192
});

spec/components/CioPlpGrid/CioPlpGrid.test.jsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,13 @@ describe('Testing Component: CioPlpGrid', () => {
251251
const totalNumResults = getAttributeFromContainer('data-cnstrc-num-results');
252252
const filterName = getAttributeFromContainer('data-cnstrc-filter-name');
253253
const filterValue = getAttributeFromContainer('data-cnstrc-filter-value');
254+
const resultId = getAttributeFromContainer('data-cnstrc-result-id');
254255

255256
expect(container.querySelector('[data-cnstrc-browse]')).toBeInTheDocument();
256257
expect(totalNumResults).toEqual(String(mockBrowseData.response.totalNumResults));
257258
expect(filterName).toEqual(String(mockBrowseData.request.browse_filter_name));
258259
expect(filterValue).toEqual(String(mockBrowseData.request.browse_filter_value));
260+
expect(resultId).toEqual(String(mockBrowseData.resultId));
259261
});
260262
});
261263

@@ -308,6 +310,9 @@ describe('Testing Component: CioPlpGrid', () => {
308310
.querySelector('[data-cnstrc-num-results]')
309311
.getAttribute('data-cnstrc-num-results'),
310312
).toEqual(String(mockSearchData.response.totalNumResults));
313+
expect(
314+
container.querySelector('[data-cnstrc-result-id]').getAttribute('data-cnstrc-result-id'),
315+
).toEqual(String(mockSearchData.resultId));
311316
});
312317
});
313318

@@ -331,6 +336,9 @@ describe('Testing Component: CioPlpGrid', () => {
331336
.querySelector('[data-cnstrc-num-results]')
332337
.getAttribute('data-cnstrc-num-results'),
333338
).toEqual('0');
339+
expect(
340+
container.querySelector('[data-cnstrc-result-id]').getAttribute('data-cnstrc-result-id'),
341+
).toEqual('test-zero-results');
334342
});
335343
});
336344
});

src/utils/dataAttributeHelpers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export function getPlpContainerCnstrcDataAttributes(
3939
dataCnstrc = {
4040
'data-cnstrc-browse': true,
4141
'data-cnstrc-num-results': data.response.totalNumResults,
42+
'data-cnstrc-result-id': data.resultId,
4243
'data-cnstrc-filter-name': filterName!,
4344
'data-cnstrc-filter-value': filterValue!,
4445
};
@@ -47,6 +48,7 @@ export function getPlpContainerCnstrcDataAttributes(
4748
case 'search':
4849
dataCnstrc = {
4950
'data-cnstrc-search': true,
51+
'data-cnstrc-result-id': data.resultId,
5052
'data-cnstrc-num-results': data.response.totalNumResults,
5153
};
5254
break;

0 commit comments

Comments
 (0)