diff --git a/packages/quantic/cypress/e2e/default-1/sort/sort.cypress.ts b/packages/quantic/cypress/e2e/default-1/sort/sort.cypress.ts index 27144d1265b..0a094dfa656 100644 --- a/packages/quantic/cypress/e2e/default-1/sort/sort.cypress.ts +++ b/packages/quantic/cypress/e2e/default-1/sort/sort.cypress.ts @@ -33,8 +33,35 @@ describe('quantic-sort', () => { ]; const sortOptionValues = sortOptions.map((option) => option.value); + const customSortOptions = [ + { + label: 'Date ascending', + value: 'date ascending', + criterion: { + by: 'date', + order: 'ascending', + }, + }, + { + label: 'Views Descending', + value: '@ytviewcount descending', + criterion: { + by: 'field', + field: 'ytviewcount', + order: 'descending', + }, + }, + { + label: 'No Sort', + value: 'nosort', + }, + ]; + const customSortOptionsValues = customSortOptions.map( + (option) => option.value + ); interface SortOptions { useCase: string; + customSortOptionsEnabled: boolean; } function visitSort(options: Partial, waitForSearch = true) { @@ -104,6 +131,41 @@ describe('quantic-sort', () => { }); }); + describe('when passing custom options as slots to the component', () => { + it('should display the custom options properly', () => { + visitSort({useCase: param.useCase, customSortOptionsEnabled: true}); + + Expect.displaySortDropdown(true); + Expect.labelContains('Sort by'); + + Actions.openDropdown(); + + Expect.containsOptions(customSortOptionsValues); + Expect.optionsEqual(customSortOptions); + }); + + customSortOptions.forEach(({label, value}) => { + describe('when selecting a custom option', () => { + it(`should update the shown selected option to ${label}`, () => { + visitSort({ + useCase: param.useCase, + customSortOptionsEnabled: true, + }); + Actions.selectOption(value); + + Expect.selectedOption(value); + + Expect.completeSearchRequest( + 'resultsSort', + param.useCase, + (body) => Expect.sortCriteriaInSearchRequest(body, value) + ); + Expect.logSortResults(value); + }); + }); + }); + }); + if (param.useCase === useCaseEnum.search) { describe('when loading sort selection from URL', () => { sortOptionValues diff --git a/packages/quantic/force-app/examples/main/lwc/exampleQuanticSort/exampleQuanticSort.html b/packages/quantic/force-app/examples/main/lwc/exampleQuanticSort/exampleQuanticSort.html index 579e7519f90..a38f8dd66cb 100644 --- a/packages/quantic/force-app/examples/main/lwc/exampleQuanticSort/exampleQuanticSort.html +++ b/packages/quantic/force-app/examples/main/lwc/exampleQuanticSort/exampleQuanticSort.html @@ -3,7 +3,7 @@ title={pageTitle} description={pageDescription} show-preview={isConfigured}> - +
@@ -11,7 +11,16 @@
- + + \ No newline at end of file diff --git a/packages/quantic/force-app/examples/main/lwc/exampleQuanticSort/exampleQuanticSort.js b/packages/quantic/force-app/examples/main/lwc/exampleQuanticSort/exampleQuanticSort.js index 18d069994a0..d8a0338b165 100644 --- a/packages/quantic/force-app/examples/main/lwc/exampleQuanticSort/exampleQuanticSort.js +++ b/packages/quantic/force-app/examples/main/lwc/exampleQuanticSort/exampleQuanticSort.js @@ -16,12 +16,53 @@ export default class ExampleQuanticSort extends LightningElement { 'Define which use case to test. Possible values are: search, insight', defaultValue: 'search', }, + { + attribute: 'customSortOptionsEnabled', + label: 'Custom Sort Options Enabled', + description: 'Enable the custom Sort options', + defaultValue: false, + }, + ]; + + customSortOptionsArray = [ + { + label: 'Date ascending', + value: 'date ascending', + criterion: { + by: 'date', + order: 'ascending', + }, + }, + { + label: 'Views Descending', + value: '@ytviewcount descending', + criterion: { + by: 'field', + field: 'ytviewcount', + order: 'descending', + }, + }, + { + label: 'No Sort', + value: 'nosort', + criterion: { + by: 'nosort', + }, + }, ]; get notConfigured() { return !this.isConfigured; } + get customSortOptionsEnabled() { + return this.config.customSortOptionsEnabled; + } + + get customSortOptions() { + return this.customSortOptionsArray; + } + handleTryItNow(evt) { this.config = evt.detail; this.isConfigured = true;