Skip to content

Commit

Permalink
fix unit test, muted console.error
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonMilord committed Oct 31, 2024
1 parent 2ed2b5e commit 86412e1
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import QuanticStandaloneSearchBox from 'c/quanticStandaloneSearchBox';
// @ts-ignore
import {createElement} from 'lwc';
import * as mockHeadlessLoader from 'c/quanticHeadlessLoader';
import {CurrentPageReference} from 'lightning/navigation';

jest.mock('c/quanticHeadlessLoader');

Expand Down Expand Up @@ -38,6 +39,7 @@ const defaultOptions = {
textarea: false,
disableRecentQueries: false,
keepFiltersOnSearch: false,
redirectUrl: '/global-search/%40uri',
};

function createTestComponent(options = defaultOptions) {
Expand Down Expand Up @@ -90,6 +92,7 @@ function cleanup() {

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

Expand All @@ -105,6 +108,30 @@ describe('c-quantic-standalone-search-box', () => {
).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';
Object.defineProperty(window, 'location', {
writable: true,
value: {href: nonStandaloneURL},
});
const element = createTestComponent({
...defaultOptions,
keepFiltersOnSearch: false,
});
// eslint-disable-next-line @lwc/lwc/no-unexpected-wire-adapter-usages
CurrentPageReference.emit({url: nonStandaloneURL});
await flushPromises();

const searchBox = element.shadowRoot.querySelector(
'c-quantic-search-box'
);

expect(searchBox).not.toBeNull();
expect(searchBox.keepFiltersOnSearch).toEqual(false);
});
});

describe('controller initialization', () => {
it('should subscribe to the headless state changes', async () => {
createTestComponent();
Expand Down

0 comments on commit 86412e1

Please sign in to comment.