-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(quantic): added support to the custom sort property in the quant…
…ic facet component (#4600) ## [SFINT-5316](https://coveord.atlassian.net/browse/SFINT-5316) - Exposed the property `customSort` in the Quantic Facet, this property allows the end user to specify a custom order of the facet values. #### Example: with `customSort` set to `[]`: <img width="648" alt="Screenshot 2024-10-28 at 9 12 24 AM" src="https://github.com/user-attachments/assets/726106a7-9d18-4793-b08d-c809806e6ac9"> #### Example: with `customSort` set to `['HTML', 'incident']`: <img width="648" alt="Screenshot 2024-10-28 at 9 11 37 AM" src="https://github.com/user-attachments/assets/ae3190e6-3e68-408a-a144-b0ff6ae4752d"> - This new logic is being unit tested. the unit tests of remaining logic of the component will be added in a later PR after doing the migration to the E2E Playwright tests. [SFINT-5316]: https://coveord.atlassian.net/browse/SFINT-5316?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ --------- Co-authored-by: Simon Milord <[email protected]> Co-authored-by: Etienne Rocheleau <[email protected]>
- Loading branch information
1 parent
52f4a6b
commit 44563fd
Showing
5 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
packages/quantic/force-app/main/default/lwc/quanticFacet/__tests__/quanticFacet.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* eslint-disable no-import-assign */ | ||
// @ts-ignore | ||
import {createElement} from 'lwc'; | ||
import QuanticFacet from 'c/quanticFacet'; | ||
import * as mockHeadlessLoader from 'c/quanticHeadlessLoader'; | ||
|
||
jest.mock('c/quanticHeadlessLoader'); | ||
|
||
function createTestComponent(options = {}) { | ||
prepareHeadlessState(); | ||
|
||
const element = createElement('c-quantic-facet', { | ||
is: QuanticFacet, | ||
}); | ||
for (const [key, value] of Object.entries(options)) { | ||
element[key] = value; | ||
} | ||
|
||
document.body.appendChild(element); | ||
return element; | ||
} | ||
|
||
const functionsMocks = { | ||
buildFacet: jest.fn(() => ({ | ||
subscribe: jest.fn((callback) => callback()), | ||
state: { | ||
values: [], | ||
}, | ||
})), | ||
buildSearchStatus: jest.fn(() => ({ | ||
subscribe: jest.fn((callback) => callback()), | ||
state: {}, | ||
})), | ||
}; | ||
|
||
function prepareHeadlessState() { | ||
// @ts-ignore | ||
mockHeadlessLoader.getHeadlessBundle = () => { | ||
return { | ||
buildFacet: functionsMocks.buildFacet, | ||
buildSearchStatus: functionsMocks.buildSearchStatus, | ||
}; | ||
}; | ||
} | ||
|
||
// Helper function to wait until the microtask queue is empty. | ||
function flushPromises() { | ||
// eslint-disable-next-line @lwc/lwc/no-async-operation | ||
return new Promise((resolve) => setTimeout(resolve, 0)); | ||
} | ||
|
||
const exampleEngine = { | ||
id: 'dummy engine', | ||
}; | ||
let isInitialized = false; | ||
|
||
function mockSuccessfulHeadlessInitialization() { | ||
// @ts-ignore | ||
mockHeadlessLoader.initializeWithHeadless = (element, _, initialize) => { | ||
if (element instanceof QuanticFacet && !isInitialized) { | ||
isInitialized = true; | ||
initialize(exampleEngine); | ||
} | ||
}; | ||
} | ||
|
||
function cleanup() { | ||
// The jsdom instance is shared across test cases in a single file so reset the DOM | ||
while (document.body.firstChild) { | ||
document.body.removeChild(document.body.firstChild); | ||
} | ||
jest.clearAllMocks(); | ||
isInitialized = false; | ||
} | ||
|
||
describe('c-quantic-facet', () => { | ||
beforeAll(() => { | ||
mockSuccessfulHeadlessInitialization(); | ||
}); | ||
|
||
afterEach(() => { | ||
cleanup(); | ||
}); | ||
|
||
describe('controller initialization', () => { | ||
it('should initialize the controller with the correct customSort value', async () => { | ||
const exampleCustomSortValues = ['test']; | ||
createTestComponent({customSort: exampleCustomSortValues}); | ||
await flushPromises(); | ||
|
||
expect(functionsMocks.buildFacet).toHaveBeenCalledTimes(1); | ||
expect(functionsMocks.buildFacet).toHaveBeenCalledWith( | ||
exampleEngine, | ||
expect.objectContaining({ | ||
options: expect.objectContaining({ | ||
customSort: exampleCustomSortValues, | ||
}), | ||
}) | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters