Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions spec/components/CioPlpGrid/CioPlpGrid.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,40 @@ describe('Testing Component: CioPlpGrid', () => {
});
});

it('Should render redirect data when a search redirect response is received', async () => {
// Mock redirect data
const mockRedirectData = {
redirect: {
data: {
url: 'https://example.com/redirect-url',
},
},
};

const mockOnRedirect = jest.fn();
jest.spyOn(require('../../../src/hooks/useCioPlpContext'), 'useCioPlpContext').mockReturnValue({
callbacks: {
onRedirect: mockOnRedirect,
},
});

useCioPlp.mockReturnValue({
status: RequestStatus.SUCCESS,
isSearchPage: true,
data: mockRedirectData,
});

render(
<CioPlp apiKey={DEMO_API_KEY}>
<CioPlpGrid />
</CioPlp>,
);

await waitFor(() => {
expect(mockOnRedirect).toHaveBeenCalledWith('https://example.com/redirect-url');
});
});

it('Should render results with data attributes when data is fetched for Browse', async () => {
useRequestConfigs.mockImplementation(() => ({
getRequestConfigs: () => ({ filterName: 'group_id', filterValue: '1030' }),
Expand Down
2 changes: 1 addition & 1 deletion src/components/CioPlpGrid/CioPlpGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default function CioPlpGrid(props: CioPlpGridWithRenderProps) {
} = useCioPlpContext();

if (isPlpSearchDataRedirect(data)) {
const redirectUrl = data.redirect.redirect.data.url;
const redirectUrl = data.redirect.data.url;

if (onRedirect) {
onRedirect(redirectUrl);
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export interface PlpSearchDataRedirect {
resultId: string;
request: SearchRequestType;
rawApiResponse: SearchResponse;
redirect: Redirect;
redirect: Redirect['redirect'];
}

export interface PlpSearchResponse {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export function transformSearchResponse(res: SearchResponse): Nullable<PlpSearch
return {
resultId,
request,
redirect: response.redirect as Redirect,
redirect: response.redirect as Redirect['redirect'],
rawApiResponse: res,
} as PlpSearchDataRedirect; // Type override due to partials in client-js
}
Expand Down
Loading