From 86412e15bd2c61a9bd933faf40d3dcdb404861c5 Mon Sep 17 00:00:00 2001 From: simonmilord Date: Thu, 31 Oct 2024 17:02:20 -0400 Subject: [PATCH] fix unit test, muted console.error --- .../quanticStandaloneSearchBox.test.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/quantic/force-app/main/default/lwc/quanticStandaloneSearchBox/__tests__/quanticStandaloneSearchBox.test.js b/packages/quantic/force-app/main/default/lwc/quanticStandaloneSearchBox/__tests__/quanticStandaloneSearchBox.test.js index 492042fa427..4cc556dff21 100644 --- a/packages/quantic/force-app/main/default/lwc/quanticStandaloneSearchBox/__tests__/quanticStandaloneSearchBox.test.js +++ b/packages/quantic/force-app/main/default/lwc/quanticStandaloneSearchBox/__tests__/quanticStandaloneSearchBox.test.js @@ -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'); @@ -38,6 +39,7 @@ const defaultOptions = { textarea: false, disableRecentQueries: false, keepFiltersOnSearch: false, + redirectUrl: '/global-search/%40uri', }; function createTestComponent(options = defaultOptions) { @@ -90,6 +92,7 @@ function cleanup() { describe('c-quantic-standalone-search-box', () => { beforeAll(() => { + jest.spyOn(console, 'error').mockImplementation(() => {}); mockSuccessfulHeadlessInitialization(); }); @@ -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();