Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9305f69

Browse files
author
Viktor Zavala
committedMar 4, 2025·
[CI-4083] Add tests to check custom variant is read correctly from sessionStorage
1 parent 01f635a commit 9305f69

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed
 

‎spec/Components/CioAutocomplete/CioAutocomplete.test.tsx

+60-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-console */
22
import '@testing-library/jest-dom';
33
import React from 'react';
4-
import { render } from '@testing-library/react';
4+
import { render, screen, fireEvent } from '@testing-library/react';
55
import { CioAutocomplete } from '../../../src';
66
import { mockCioClientJS } from '../../test-utils';
77
import { apiKey as DEMO_API_KEY, onSubmitDefault as onSubmit } from '../../../src/constants';
@@ -126,4 +126,63 @@ describe('CioAutocomplete Client-Side Rendering', () => {
126126

127127
expect(console.error).not.toHaveBeenCalled();
128128
});
129+
describe('Custom UI variant', () => {
130+
afterEach(() => {
131+
window.sessionStorage.removeItem('_constructorio_custom_autosuggest_ui_');
132+
});
133+
134+
it('Renders the default CioAutocomplete when no custom UI variant is set', async () => {
135+
render(<CioAutocomplete apiKey={DEMO_API_KEY} onSubmit={() => {}} />);
136+
137+
const searchInput = screen.getByRole('combobox');
138+
139+
fireEvent.change(searchInput, { target: { value: 'pants' } });
140+
141+
const options = (await screen.findAllByRole('option', undefined, { timeout: 5000 })).filter(
142+
(elem) => elem.getAttribute('data-cnstrc-item-section') === 'Search Suggestions'
143+
);
144+
145+
options.forEach((option) => {
146+
const suggestionCount = option.querySelector('.cio-suggestion-count');
147+
expect(suggestionCount).not.toBeInTheDocument();
148+
});
149+
});
150+
151+
it('Takes custom UI variant from session storage and applies features based on the variant', async () => {
152+
window.sessionStorage.setItem(
153+
'_constructorio_custom_autosuggest_ui_',
154+
'custom_autosuggest_ui_result_count'
155+
);
156+
157+
const props = {
158+
apiKey: DEMO_API_KEY,
159+
onSubmit: () => {},
160+
sections: [
161+
{
162+
indexSectionName: 'Search Suggestions',
163+
numResults: 8,
164+
},
165+
{
166+
indexSectionName: 'Products',
167+
numResults: 6,
168+
},
169+
],
170+
};
171+
172+
render(<CioAutocomplete {...props} />);
173+
174+
const searchInput = screen.getByRole('combobox');
175+
176+
fireEvent.change(searchInput, { target: { value: 'pants' } });
177+
178+
const options = (await screen.findAllByRole('option')).filter(
179+
(elem) => elem.getAttribute('data-cnstrc-item-section') === 'Search Suggestions'
180+
);
181+
182+
options.forEach((option) => {
183+
const suggestionCount = option.querySelector('.cio-suggestion-count');
184+
expect(suggestionCount).toBeInTheDocument();
185+
});
186+
});
187+
});
129188
});

0 commit comments

Comments
 (0)
Please sign in to comment.