Skip to content

Commit

Permalink
applied feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonMilord committed Oct 30, 2024
1 parent 8c0b7a3 commit 28e3f5e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const defaultOptions = {
numberOfSuggestions: 7,
textarea: false,
disableRecentQueries: false,
disableClearFilters: false,
keepFiltersOnSearch: false,
};

function createTestComponent(options = defaultOptions) {
Expand Down Expand Up @@ -106,53 +106,35 @@ describe('c-quantic-search-box', () => {
expect(functionsMocks.subscribe).toHaveBeenCalledTimes(1);
});

describe('when disableClearFilters is false (default)', () => {
describe('when keepFiltersOnSearch is false (default)', () => {
it('should properly initialize the controller with clear filters enabled', async () => {
const expectedDefaultOptions = {
clearFilters: true,
numberOfSuggestions: 7,
highlightOptions: {
notMatchDelimiters: {
open: '<b>',
close: '</b>',
},
},
};
const element = createTestComponent();
createTestComponent();
await flushPromises();

expect(element.disableClearFilters).toBe(false);
expect(functionsMocks.buildSearchBox).toHaveBeenCalledTimes(1);
expect(functionsMocks.buildSearchBox).toHaveBeenCalledWith(
exampleEngine,
{options: expectedDefaultOptions}
expect.objectContaining({
options: expect.objectContaining({clearFilters: true}),
})
);
});
});

describe('when disableClearFilters is true', () => {
describe('when keepFiltersOnSearch is true', () => {
it('should properly initialize the controller with clear filters disabled', async () => {
const expectedDefaultOptions = {
clearFilters: false,
numberOfSuggestions: 7,
highlightOptions: {
notMatchDelimiters: {
open: '<b>',
close: '</b>',
},
},
};
const element = createTestComponent({
createTestComponent({
...defaultOptions,
disableClearFilters: true,
keepFiltersOnSearch: true,
});
await flushPromises();

expect(element.disableClearFilters).toBe(true);
expect(functionsMocks.buildSearchBox).toHaveBeenCalledTimes(1);
expect(functionsMocks.buildSearchBox).toHaveBeenCalledWith(
exampleEngine,
{options: expectedDefaultOptions}
expect.objectContaining({
options: expect.objectContaining({clearFilters: false}),
})
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ export default class QuanticSearchBox extends LightningElement {
*/
@api disableRecentQueries = false;
/**
* Whether to disable clearing all active query filters when the end user submits a new query from the search box.
* Whether to keep all active query filters when the end user submits a new query from the search box.
* @api
* @type {boolean}
* @defaultValue false
*/
@api disableClearFilters = false;
@api keepFiltersOnSearch = false;

/** @type {SearchBoxState} */
@track state;
Expand Down Expand Up @@ -107,7 +107,7 @@ export default class QuanticSearchBox extends LightningElement {
close: '</b>',
},
},
clearFilters: !this.disableClearFilters,
clearFilters: !this.keepFiltersOnSearch,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ export default class QuanticStandaloneSearchBox extends NavigationMixin(
*/
@api numberOfSuggestions = 5;
/**
* Whether to disable clearing all active query filters when the end user submits a new query from the standalone search box.
* Whether to keep all active query filters when the end user submits a new query from the standalone search box.
* @api
* @type {boolean}
* @defaultValue false
*/
@api disableClearFilters = false;
@api keepFiltersOnSearch = false;
/**
* The url of the search page to redirect to when a query is made.
* The target search page should contain a `QuanticSearchInterface` with the same engine ID as the one specified for this component.
Expand Down Expand Up @@ -178,7 +178,7 @@ export default class QuanticStandaloneSearchBox extends NavigationMixin(
close: '</b>',
},
},
clearFilters: !this.disableClearFilters,
clearFilters: !this.keepFiltersOnSearch,
redirectionUrl: 'http://placeholder.com',
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
without-submit-button={withoutSubmitButton}
number-of-suggestions={numberOfSuggestions}
textarea={textarea}
keep-filters-on-search={keepFiltersOnSearch}
></c-quantic-search-box>
</template>
</template>

0 comments on commit 28e3f5e

Please sign in to comment.