-
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(headless): exposes category facet values hierarchically (#3105)
* feat: exposes values hierarchicaly https://coveord.atlassian.net/browse/KIT-2668 * typo in ut https://coveord.atlassian.net/browse/KIT-2668 * fixed tests https://coveord.atlassian.net/browse/KIT-2668 * Revert "fixed tests" This reverts commit 30026fb. * adjust behavior around more/less value https://coveord.atlassian.net/browse/KIT-2668 * remove internal uses of `values` https://coveord.atlassian.net/browse/KIT-2668 * probably fix e2e https://coveord.atlassian.net/browse/KIT-2668 * refactor getActiveValueFromValueTree https://coveord.atlassian.net/browse/KIT-2668 * getActiveValueFromValueTree: prioritize first value in the array https://coveord.atlassian.net/browse/KIT-2668 * unit tests https://coveord.atlassian.net/browse/KIT-2668 * improve comments https://coveord.atlassian.net/browse/KIT-2668
- Loading branch information
1 parent
b7b78b3
commit 4b6b0af
Showing
4 changed files
with
231 additions
and
17 deletions.
There are no files selected for viewing
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
57 changes: 57 additions & 0 deletions
57
packages/headless/src/features/facets/category-facet-set/category-facet-utils.test.ts
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,57 @@ | ||
import {buildMockCategoryFacetValue} from '../../../test/mock-category-facet-value'; | ||
import {getActiveValueFromValueTree} from './category-facet-utils'; | ||
import {CategoryFacetValue} from './interfaces/response'; | ||
|
||
describe('#getActiveValueFromValueTree', () => { | ||
it("should return undefined if there's no selected values", () => { | ||
expect(getActiveValueFromValueTree([])).toBeUndefined(); | ||
}); | ||
|
||
it.each([ | ||
{ | ||
caseName: 'doubleRootValues', | ||
getValues: (expectedValue: CategoryFacetValue) => [ | ||
expectedValue, | ||
buildMockCategoryFacetValue({state: 'selected'}), | ||
], | ||
}, | ||
{ | ||
caseName: 'rootAndNestedValues', | ||
getValues: (expectedValue: CategoryFacetValue) => [ | ||
buildMockCategoryFacetValue({children: [expectedValue]}), | ||
buildMockCategoryFacetValue({state: 'selected'}), | ||
], | ||
}, | ||
{ | ||
caseName: 'doubleNestedValues', | ||
getValues: (expectedValue: CategoryFacetValue) => [ | ||
buildMockCategoryFacetValue({children: [expectedValue]}), | ||
buildMockCategoryFacetValue({ | ||
children: [buildMockCategoryFacetValue({state: 'selected'})], | ||
}), | ||
], | ||
}, | ||
{ | ||
caseName: 'singleNestedValue', | ||
getValues: (expectedValue: CategoryFacetValue) => [ | ||
buildMockCategoryFacetValue({children: [expectedValue]}), | ||
], | ||
}, | ||
{ | ||
caseName: 'singleRootValue', | ||
getValues: (expectedValue: CategoryFacetValue) => [expectedValue], | ||
}, | ||
])( | ||
'should return the first selected values found while doing a depth first search - $caseName', | ||
({getValues}) => { | ||
const expectedValues = buildMockCategoryFacetValue({ | ||
state: 'selected', | ||
value: 'A', | ||
}); | ||
|
||
const values: CategoryFacetValue[] = getValues(expectedValues); | ||
|
||
expect(getActiveValueFromValueTree(values)).toBe(expectedValues); | ||
} | ||
); | ||
}); |
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