Skip to content

Commit

Permalink
fix log issue
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonMilord committed Nov 1, 2024
1 parent 86412e1 commit 2b53f90
Showing 1 changed file with 28 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,40 @@ import QuanticStandaloneSearchBox from 'c/quanticStandaloneSearchBox';
import {createElement} from 'lwc';
import * as mockHeadlessLoader from 'c/quanticHeadlessLoader';
import {CurrentPageReference} from 'lightning/navigation';
import getHeadlessConfiguration from '@salesforce/apex/HeadlessController.getHeadlessConfiguration';

const nonStandaloneURL = 'https://www.example.com/global-search/%40uri';
const defaultHeadlessConfiguration = JSON.stringify({
organization: 'testOrgId',
accessToken: 'testAccessToken',
});

jest.mock('c/quanticHeadlessLoader');

jest.mock(
'@salesforce/apex/HeadlessController.getHeadlessConfiguration',
() => ({
default: jest.fn(),
}),
{virtual: true}
);

mockHeadlessLoader.loadDependencies = () =>
new Promise((resolve) => {
resolve();
});

let isInitialized = false;

const exampleEngine = {
id: 'engineId__standalone',
id: 'engineId',
};

const functionsMocks = {
buildStandaloneSearchBox: jest.fn(() => ({
state: {},
subscribe: functionsMocks.subscribe,
})),
loadDependencies: jest.fn(
() =>
new Promise((resolve) => {
resolve();
})
),
subscribe: jest.fn((cb) => {
cb();
return functionsMocks.unsubscribe;
Expand All @@ -44,7 +58,6 @@ const defaultOptions = {

function createTestComponent(options = defaultOptions) {
prepareHeadlessState();

const element = createElement('c-quantic-standalone-search-box', {
is: QuanticStandaloneSearchBox,
});
Expand All @@ -56,12 +69,9 @@ function createTestComponent(options = defaultOptions) {
}

function prepareHeadlessState() {
// @ts-ignore
mockHeadlessLoader.loadDependencies = functionsMocks.loadDependencies;
// @ts-ignore
global.CoveoHeadless = {
buildStandaloneSearchBox: functionsMocks.buildStandaloneSearchBox,
subscribe: functionsMocks.subscribe,
};
}

Expand Down Expand Up @@ -91,8 +101,8 @@ function cleanup() {
}

describe('c-quantic-standalone-search-box', () => {
beforeAll(() => {
jest.spyOn(console, 'error').mockImplementation(() => {});
beforeEach(() => {
getHeadlessConfiguration.mockResolvedValue(defaultHeadlessConfiguration);
mockSuccessfulHeadlessInitialization();
});

Expand All @@ -101,20 +111,18 @@ describe('c-quantic-standalone-search-box', () => {
});

it('construct itself without throwing', () => {
expect(() =>
createElement('c-quantic-standalone-search-box', {
is: QuanticStandaloneSearchBox,
})
).not.toThrow();
expect(() => createTestComponent()).not.toThrow();
});

describe('when the current page reference changes', () => {
it('should properly pass the keepFiltersOnSearch property to the quanticSearchBox', async () => {
const nonStandaloneURL = 'https://www.example.com/global-search/%40uri';
beforeAll(() => {
Object.defineProperty(window, 'location', {
writable: true,
value: {href: nonStandaloneURL},
});
});

it('should properly pass the keepFiltersOnSearch property to the quanticSearchBox', async () => {
const element = createTestComponent({
...defaultOptions,
keepFiltersOnSearch: false,
Expand Down

0 comments on commit 2b53f90

Please sign in to comment.