Fix 'select' method to allow deselecting selection#129
Fix 'select' method to allow deselecting selection#129adiletelf wants to merge 4 commits intomicrosoft:mainfrom
Conversation
AleksSavelev
left a comment
There was a problem hiding this comment.
I see that you copied select method from selectionManager and this is correct, but I'm not sure if we should copy spaghetti code, what do you think?
| resolve(this.selectionIds); | ||
| }) as any; | ||
| } | ||
|
|
There was a problem hiding this comment.
I see a lot of If else blocks and all of them have the same this.selectionIds = selectionIds
There was a problem hiding this comment.
If this is right, you can make it much easier:
if(multiSelect){
...all your ifs here
} else {
this.selectionIds = selectionIds
}There was a problem hiding this comment.
I refactored the code to make it more readable.
src/mocks/mockISelectionManager.ts
Outdated
| // if no multiselect reset current selection and save new passed selections; | ||
| if (!multiSelect) { | ||
| this.selectionIds = selectionIds; | ||
| if (selectionIds.length < 1) { |
There was a problem hiding this comment.
selectionIds.length === 0
src/mocks/mockISelectionManager.ts
Outdated
|
|
||
| public simutateSelection(selections: ISelectionId[]): void { | ||
| this.callback(selections); | ||
| if (this.callback && typeof this.callback === "function") { |
There was a problem hiding this comment.
type guard is enough here, it also checks for undefined
|
|
||
| const selectedIds: ISelectionId[] = selectionManager.getSelectionIds(); | ||
| expect(selectedIds).toHaveSize(3); | ||
| expect(selectedIds[0].equals(selectionId0)).toBeTruthy(); |
There was a problem hiding this comment.
expect(selectedIds[0]).toEqual(selectionId0)
| const selectionId0: ISelectionId = createSelectionId("0"); | ||
| const selectionId1: ISelectionId = createSelectionId("1"); | ||
| const selectionId2: ISelectionId = createSelectionId("2"); |
There was a problem hiding this comment.
You can create a variable with these selectionIds and then compare it with the result using toEqual
CHANGELOG.md
Outdated
| @@ -1,3 +1,7 @@ | |||
| ## 6.1.2 | |||
| * Fix 'select' method to allow deselecting selection | |||
There was a problem hiding this comment.
Fix 'select' method in MockISelectionManager to allow deselecting selection
src/mocks/mockISelectionManager.ts
Outdated
| this.selectionIds = this.selectionIds.filter(x => !selectionIds[0].equals(x)); | ||
| } else { | ||
| // if multiSelect is off, the selected item is the new selectedId, else deselect the selection | ||
| this.selectionIds = selectionIds.length > 1 ? selectionIds : []; |
There was a problem hiding this comment.
Here would be always an empty array
There was a problem hiding this comment.
You're right, it's the expected behavior too. Fixed.
…handling and update tests for consistency
Please, view the source code for 'select' method.