-
Notifications
You must be signed in to change notification settings - Fork 530
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(index): resolve parent SearchParameters (#3937)
* feat(resolveSearchParameters): implementation * feat(index): expose the parent * feat(index): resolve and shallow merge search parameters * chore(stories): remove index specific search parameters * test(index): use correct index name
- Loading branch information
Showing
6 changed files
with
221 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { createInitOptions } from '../../../../test/mock/createWidget'; | ||
import index from '../../../widgets/index/index'; | ||
import resolve from '../resolveSearchParameters'; | ||
|
||
describe('mergeSearchParameters', () => { | ||
describe('1 level', () => { | ||
it('resolves the `SearchParameters` from the level 0', () => { | ||
const level0 = index({ indexName: 'level_0_index_name' }); | ||
|
||
level0.init(createInitOptions()); | ||
|
||
const actual = resolve(level0); | ||
|
||
expect(actual).toEqual([level0.getHelper()!.state]); | ||
}); | ||
}); | ||
|
||
describe('2 levels', () => { | ||
const level0 = index({ indexName: 'level_0_index_name' }); | ||
const level1 = index({ indexName: 'level_1_index_name' }); | ||
|
||
level0.addWidgets([level1]); | ||
level0.init(createInitOptions()); | ||
|
||
it('resolves the `SearchParameters` from the level 0', () => { | ||
expect(resolve(level0)).toEqual([level0.getHelper()!.state]); | ||
}); | ||
|
||
it('resolves the `SearchParameters` from the level 1', () => { | ||
expect(resolve(level1)).toEqual([ | ||
level0.getHelper()!.state, | ||
level1.getHelper()!.state, | ||
]); | ||
}); | ||
}); | ||
|
||
describe('3 levels', () => { | ||
const level0 = index({ indexName: 'level_0_index_name' }); | ||
const level1 = index({ indexName: 'level_1_index_name' }); | ||
const level2 = index({ indexName: 'level_2_index_name' }); | ||
|
||
level0.addWidgets([level1.addWidgets([level2])]); | ||
level0.init(createInitOptions()); | ||
|
||
it('resolves the `SearchParameters` from the level 0', () => { | ||
expect(resolve(level0)).toEqual([level0.getHelper()!.state]); | ||
}); | ||
|
||
it('resolves the `SearchParameters` from the level 1', () => { | ||
expect(resolve(level1)).toEqual([ | ||
level0.getHelper()!.state, | ||
level1.getHelper()!.state, | ||
]); | ||
}); | ||
|
||
it('resolves the `SearchParameters` from the level 2', () => { | ||
expect(resolve(level2)).toEqual([ | ||
level0.getHelper()!.state, | ||
level1.getHelper()!.state, | ||
level2.getHelper()!.state, | ||
]); | ||
}); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Index } from '../../widgets/index/index'; | ||
import { SearchParameters } from '../../types'; | ||
|
||
const resolveSearchParameters = (current: Index): SearchParameters[] => { | ||
let parent = current.getParent(); | ||
let states = [current.getHelper()!.state]; | ||
|
||
while (parent !== null) { | ||
states = [parent.getHelper()!.state].concat(states); | ||
parent = parent.getParent(); | ||
} | ||
|
||
return states; | ||
}; | ||
|
||
export default resolveSearchParameters; |
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