Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(quantic): issue with date filter and numeric filters when used with dependant facets #4680

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ function createTestComponent(options = defaultOptions) {

const functionsMocks = {
buildCategoryFacet: jest.fn(() => categoryFacetControllerMock),
buildFacetConditionsManager: jest.fn(),
stopWatching: jest.fn(),
buildFacetConditionsManager: jest.fn(() => ({
stopWatching: functionsMocks.stopWatching,
})),
buildSearchStatus: jest.fn(() => ({
subscribe: jest.fn((callback) => callback()),
state: {},
Expand Down Expand Up @@ -194,4 +197,24 @@ describe('c-quantic-category-facet', () => {
);
});
});

describe('when the component is disconnected', () => {
it('should make the condition manager stop watching the facet', async () => {
const exampleFacetDependency = {
parentFacetId: 'filetype',
expectedValue: 'txt',
};
const element = createTestComponent({
...defaultOptions,
dependsOn: exampleFacetDependency,
});
await flushPromises();
expect(functionsMocks.buildFacetConditionsManager).toHaveBeenCalledTimes(
1
);

document.body.removeChild(element);
expect(functionsMocks.stopWatching).toHaveBeenCalledTimes(1);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {api, LightningElement, track} from 'lwc';
/** @typedef {import("coveo").CategoryFacetValue} CategoryFacetValue */
/** @typedef {import("coveo").SearchStatus} SearchStatus */
/** @typedef {import("coveo").SearchEngine} SearchEngine */
/** @typedef {import("coveo").FacetConditionsManager} FacetConditionsManager */
/** @typedef {import('../quanticUtils/facetDependenciesUtils').DependsOn} DependsOn */
/**
* @typedef FocusTarget
Expand Down Expand Up @@ -219,6 +220,8 @@ export default class QuanticCategoryFacet extends LightningElement {
focusShouldBeInFacet = false;
/** @type {boolean} */
hasInitializationError = false;
/** @type {FacetConditionsManager} */
categoryfacetConditionsManager;

labels = {
clear,
Expand Down Expand Up @@ -256,6 +259,7 @@ export default class QuanticCategoryFacet extends LightningElement {
disconnectedCallback() {
this.unsubscribe?.();
this.unsubscribeSearchStatus?.();
this.categoryfacetConditionsManager?.stopWatching();
}

/**
Expand Down Expand Up @@ -327,15 +331,13 @@ export default class QuanticCategoryFacet extends LightningElement {
}

initFacetConditionManager(engine) {
this.facetConditionsManager = this.headless.buildFacetConditionsManager(
engine,
{
this.categoryfacetConditionsManager =
this.headless.buildFacetConditionsManager(engine, {
facetId: this.facet.state.facetId,
conditions: generateFacetDependencyConditions({
[this.dependsOn.parentFacetId]: this.dependsOn.expectedValue,
}),
}
);
});
}

get values() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ function createTestComponent(options = defaultOptions) {

const functionsMocks = {
buildDateFacet: jest.fn(() => dateFacetControllerMock),
buildFacetConditionsManager: jest.fn(),
stopWatching: jest.fn(),
buildFacetConditionsManager: jest.fn(() => ({
stopWatching: functionsMocks.stopWatching,
})),
buildSearchStatus: jest.fn(() => ({
subscribe: jest.fn((callback) => callback()),
state: {},
Expand Down Expand Up @@ -189,4 +192,24 @@ describe('c-quantic-date-facet', () => {
functionsMocks.buildDateFacet.mockReturnValue(dateFacetControllerMock);
});
});

describe('when the component is disconnected', () => {
it('should make the condition manager stop watching the facet', async () => {
const exampleFacetDependency = {
parentFacetId: 'filetype',
expectedValue: 'txt',
};
const element = createTestComponent({
...defaultOptions,
dependsOn: exampleFacetDependency,
});
await flushPromises();
expect(functionsMocks.buildFacetConditionsManager).toHaveBeenCalledTimes(
1
);

document.body.removeChild(element);
expect(functionsMocks.stopWatching).toHaveBeenCalledTimes(1);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {LightningElement, track, api} from 'lwc';
/** @typedef {import("coveo").DateFacetValue} DateFacetValue */
/** @typedef {import("coveo").SearchStatus} SearchStatus */
/** @typedef {import("coveo").SearchEngine} SearchEngine */
/** @typedef {import("coveo").FacetConditionsManager} FacetConditionsManager */
/** @typedef {import('../quanticUtils/facetDependenciesUtils').DependsOn} DependsOn */
/**
* @typedef FocusTarget
Expand Down Expand Up @@ -160,6 +161,8 @@ export default class QuanticDateFacet extends LightningElement {
focusShouldBeInFacet = false;
/** @type {boolean} */
hasInitializationError = false;
/** @type {FacetConditionsManager} */
dateFacetConditionsManager;

labels = {
clearFilter,
Expand Down Expand Up @@ -214,6 +217,7 @@ export default class QuanticDateFacet extends LightningElement {
disconnectedCallback() {
this.unsubscribe?.();
this.unsubscribeSearchStatus?.();
this.dateFacetConditionsManager?.stopWatching();
}

updateState() {
Expand All @@ -235,7 +239,7 @@ export default class QuanticDateFacet extends LightningElement {
}

initFacetConditionManager(engine) {
this.facetConditionsManager = this.headless.buildFacetConditionsManager(
this.dateFacetConditionsManager = this.headless.buildFacetConditionsManager(
engine,
{
facetId: this.facet.state.facetId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ function createTestComponent(options = defaultOptions) {

const functionsMocks = {
buildFacet: jest.fn(() => facetControllerMock),
buildFacetConditionsManager: jest.fn(),
stopWatching: jest.fn(),
buildFacetConditionsManager: jest.fn(() => ({
stopWatching: functionsMocks.stopWatching,
})),
buildSearchStatus: jest.fn(() => ({
subscribe: jest.fn((callback) => callback()),
state: {},
Expand Down Expand Up @@ -210,4 +213,24 @@ describe('c-quantic-facet', () => {
functionsMocks.buildFacet.mockReturnValue(facetControllerMock);
});
});

describe('when the component is disconnected', () => {
it('should make the condition manager stop watching the facet', async () => {
const exampleFacetDependency = {
parentFacetId: 'filetype',
expectedValue: 'txt',
};
const element = createTestComponent({
...defaultOptions,
dependsOn: exampleFacetDependency,
});
await flushPromises();
expect(functionsMocks.buildFacetConditionsManager).toHaveBeenCalledTimes(
1
);

document.body.removeChild(element);
expect(functionsMocks.stopWatching).toHaveBeenCalledTimes(1);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {LightningElement, track, api} from 'lwc';
/** @typedef {import("coveo").FacetValue} FacetValue */
/** @typedef {import("coveo").SearchStatus} SearchStatus */
/** @typedef {import("coveo").SearchEngine} SearchEngine */
/** @typedef {import("coveo").FacetConditionsManager} FacetConditionsManager */
/** @typedef {import('../quanticUtils/facetDependenciesUtils').DependsOn} DependsOn */
/**
* @typedef FocusTarget
Expand Down Expand Up @@ -229,6 +230,8 @@ export default class QuanticFacet extends LightningElement {
focusShouldBeInFacet = false;
/** @type {boolean} */
hasInitializationError = false;
/** @type {FacetConditionsManager} */
facetConditionsManager;

labels = {
showMore,
Expand Down Expand Up @@ -319,6 +322,7 @@ export default class QuanticFacet extends LightningElement {
disconnectedCallback() {
this.unsubscribe?.();
this.unsubscribeSearchStatus?.();
this.facetConditionsManager?.stopWatching();
}

updateState() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const selectors = {
};

const exampleFacetId = 'example facet id';
const exampleFilterId = `${exampleFacetId}_input`;
const defaultOptions = {
field: 'example field',
};
Expand Down Expand Up @@ -47,7 +48,16 @@ function createTestComponent(options = defaultOptions) {

const functionsMocks = {
buildNumericFacet: jest.fn(() => numericFacetControllerMock),
buildFacetConditionsManager: jest.fn(),
buildNumericFilter: jest.fn(() => ({
subscribe: jest.fn((callback) => callback()),
state: {
facetId: exampleFilterId,
},
})),
stopWatching: jest.fn(),
buildFacetConditionsManager: jest.fn(() => ({
stopWatching: functionsMocks.stopWatching,
})),
buildSearchStatus: jest.fn(() => ({
subscribe: jest.fn((callback) => callback()),
state: {},
Expand All @@ -59,6 +69,7 @@ function prepareHeadlessState() {
mockHeadlessLoader.getHeadlessBundle = () => {
return {
buildNumericFacet: functionsMocks.buildNumericFacet,
buildNumericFilter: functionsMocks.buildNumericFilter,
buildSearchStatus: functionsMocks.buildSearchStatus,
buildFacetConditionsManager: functionsMocks.buildFacetConditionsManager,
};
Expand Down Expand Up @@ -113,29 +124,40 @@ describe('c-quantic-numeric-facet', () => {
createTestComponent({
...defaultOptions,
dependsOn: exampleFacetDependency,
withInput: true,
});
await flushPromises();

expect(functionsMocks.buildNumericFacet).toHaveBeenCalledTimes(1);
expect(functionsMocks.buildNumericFilter).toHaveBeenCalledTimes(1);
expect(functionsMocks.buildFacetConditionsManager).toHaveBeenCalledTimes(
1
2
);
expect(functionsMocks.buildFacetConditionsManager).toHaveBeenCalledWith(
exampleEngine,
{
facetId: exampleFacetId,
}
);
expect(functionsMocks.buildFacetConditionsManager).toHaveBeenCalledWith(
exampleEngine,
{
facetId: exampleFilterId,
}
);

expect(generateFacetDependencyConditions).toHaveBeenCalledTimes(1);
expect(generateFacetDependencyConditions).toHaveBeenCalledTimes(2);
expect(generateFacetDependencyConditions).toHaveBeenCalledWith({
[exampleFacetDependency.parentFacetId]:
exampleFacetDependency.expectedValue,
});
});

it('should not build the controller when the dependsOn property is not set', async () => {
createTestComponent();
createTestComponent({
...defaultOptions,
withInput: true,
});
await flushPromises();

expect(functionsMocks.buildNumericFacet).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -191,4 +213,25 @@ describe('c-quantic-numeric-facet', () => {
);
});
});

describe('when the component is disconnected', () => {
it('should make the condition manager stop watching the facet', async () => {
const exampleFacetDependency = {
parentFacetId: 'filetype',
expectedValue: 'txt',
};
const element = createTestComponent({
...defaultOptions,
dependsOn: exampleFacetDependency,
withInput: true,
});
await flushPromises();
expect(functionsMocks.buildFacetConditionsManager).toHaveBeenCalledTimes(
2
);

document.body.removeChild(element);
expect(functionsMocks.stopWatching).toHaveBeenCalledTimes(2);
});
});
});
Loading
Loading