* feat: add personalized recommendations (#1024)
* use Algolia for personalized recommendations
* show personalized recommendations to use that have consented
to functional cookies
* update tests
VAN-1599
* Revert "fix: special characters in redirect url getting decoded to space (#1029)" (#1030)
This reverts commit fc62241332.
* feat: update recommendations page design (#1036)
VAN-1598
* feat: add events for recommendations (#1039)
* feat: remove static recommendations
---------
Co-authored-by: Syed Sajjad Hussain Shah <52817156+syedsajjadkazmii@users.noreply.github.com>
57 lines
2.3 KiB
JavaScript
57 lines
2.3 KiB
JavaScript
import { renderHook } from '@testing-library/react-hooks';
|
|
import algoliasearchHelper from 'algoliasearch-helper';
|
|
|
|
import mockedRecommendedProducts from './mockedData';
|
|
import CreateAlgoliaSearchHelperMock from './test_utils/test_utils';
|
|
import isOneTrustFunctionalCookieEnabled from '../../../data/oneTrust';
|
|
import useAlgoliaRecommendations from '../hooks/useAlgoliaRecommendations';
|
|
|
|
jest.mock('algoliasearch-helper');
|
|
|
|
jest.mock('../../../data/oneTrust');
|
|
|
|
jest.mock('../../../data/algolia', () => ({
|
|
initializeSearchClient: jest.fn(),
|
|
getLocationRestrictionFilter: jest.fn((countryCode) => `NOT BLOCKED IN ${countryCode}`),
|
|
}));
|
|
|
|
jest.mock('../algoliaResultsParser', () => jest.fn((course) => course));
|
|
|
|
describe('useAlgoliaRecommendations Tests', () => {
|
|
const MockSearchHelperWithData = new CreateAlgoliaSearchHelperMock(mockedRecommendedProducts);
|
|
const MockSearchHelperWithoutData = new CreateAlgoliaSearchHelperMock();
|
|
|
|
it('should fetch recommendations only if functional cookies are set', async () => {
|
|
isOneTrustFunctionalCookieEnabled.mockImplementation(() => true);
|
|
algoliasearchHelper.mockImplementation(() => MockSearchHelperWithData);
|
|
const { result } = renderHook(
|
|
() => useAlgoliaRecommendations('PK', 'Introductory'),
|
|
);
|
|
|
|
expect(result.current.recommendations).toEqual(mockedRecommendedProducts);
|
|
expect(result.current.isLoading).toBe(false);
|
|
});
|
|
|
|
it('should not fetch recommendations if functional cookies are not set', async () => {
|
|
isOneTrustFunctionalCookieEnabled.mockImplementation(() => false);
|
|
algoliasearchHelper.mockImplementation(() => MockSearchHelperWithData);
|
|
const { result } = renderHook(
|
|
() => useAlgoliaRecommendations('PK', 'Introductory'),
|
|
);
|
|
|
|
expect(result.current.recommendations).toEqual([]);
|
|
expect(result.current.isLoading).toBe(false);
|
|
});
|
|
|
|
it('should return empty list if no recommendations returned from Algolia', async () => {
|
|
isOneTrustFunctionalCookieEnabled.mockImplementation(() => true);
|
|
algoliasearchHelper.mockImplementation(() => MockSearchHelperWithoutData);
|
|
const { result } = renderHook(
|
|
() => useAlgoliaRecommendations('PK', 'Introductory'),
|
|
);
|
|
|
|
expect(result.current.recommendations).toEqual([]);
|
|
expect(result.current.isLoading).toBe(false);
|
|
});
|
|
});
|