-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(cdk-experimental/listbox): selection logic and testing for listbox. #19690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jelbourn
merged 35 commits into
angular:master
from
nielsr98:cdk-listbox-selected-state
Jun 26, 2020
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
8ff6997
build: Added required files to listbox directory.
nielsr98 364aa53
build: added listbox option directive and renamed listbox directive f…
nielsr98 ee5746b
build: Added required files to listbox directory.
nielsr98 893ba4f
build: added listbox option directive and renamed listbox directive f…
nielsr98 5d0617c
fix(cdk-experimental/listbox): deleted unused files.
nielsr98 a3a6940
feat(cdk-experimental/listbox): added tests for listbox and options, …
nielsr98 24acc81
chore(cdk-experimental/listbox): formated BUILD.bazel.
nielsr98 a0d66ad
fix(cdk-experimental/listbox): fixed style bugs caught by lint test.
nielsr98 9369e30
chore(cdk-experimental/listbox): fixed style bugs and made CdkListbox…
nielsr98 b5ba387
fix(cdk-experimental/listbox): made click handler function public.
nielsr98 2b4b436
refactor(cdk-experimental/listbox): refactored functions to condense …
nielsr98 362c169
fix(cdk-experimental/listbox): removed unused import.
nielsr98 4edff93
refactor(cdk-experimental/listbox): cleaned up variable and method na…
nielsr98 e13c411
:
nielsr98 02a0d59
fix(cdk-experimental/listbox): moved compileComponents and createComp…
nielsr98 41bda71
refactor(cdk-experimental/listbox): used DebugElement for testing ins…
nielsr98 553df4c
refactor(cdk-experimental/listbox): removed unused variable.
nielsr98 a66964e
fix(cdk-experimental/listbox): removed unused import.
nielsr98 8aac577
feat(cdk-experimental/listbox): created selectionChange event emitter…
nielsr98 4f9666f
refactor(cdk-experimental/listbox): removed click handler on listbox …
nielsr98 c375efa
refactor(cdk-experimental/listbox): created selectionChange emitter f…
nielsr98 0060b40
fix(cdk-experimental:listbox): added toggle function to change select…
nielsr98 5332e83
refactor(cdk-experimental/listbox): added tests for unique ids and th…
nielsr98 93a9d44
refactor(cdk-experimental/listbox): removed unused function to get el…
nielsr98 5df2643
fix(cdk-experimental/listbox): fixed double quote lint error.
nielsr98 76e4232
refactor(cdk-experimental/listbox): coerce boolean property when sett…
nielsr98 b900539
fix(cdk-experimental/listbox): add static ngAcceptInputType for _sele…
nielsr98 fa2e1da
fix(cdk-experimental/listbox): fixed BUILD file format issue.
nielsr98 618d9c6
refactor(cdk-experimental/listbox): use the id attribute instead of c…
nielsr98 48e792f
fix(cdk-experimental/listbox): removed unused variable.
nielsr98 d39d9ae
fix(cdk-experimental/listbox): removed unused listbox variable.
nielsr98 75de55c
fix(cdk-experimental/listbox): removed unused CdkListbox import.
nielsr98 1e5f5ee
feat(cdk-experimental/listbox): added interface for selection change …
nielsr98 5be6915
fix(cdk-experimental/listbox): fix line length.
nielsr98 a0eaea2
refactor(cdk-experimental/listbox): removed spy from test.
nielsr98 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,99 @@ | ||
import { | ||
ComponentFixture, | ||
async, | ||
TestBed, | ||
} from '@angular/core/testing'; | ||
import {Component, DebugElement} from '@angular/core'; | ||
import {By} from '@angular/platform-browser'; | ||
import { | ||
CdkOption, | ||
CdkListboxModule, ListboxSelectionChangeEvent | ||
} from './index'; | ||
import {dispatchMouseEvent} from '@angular/cdk/testing/private'; | ||
|
||
describe('CdkOption', () => { | ||
|
||
describe('selection state change', () => { | ||
let fixture: ComponentFixture<ListboxWithOptions>; | ||
let options: DebugElement[]; | ||
let optionInstances: CdkOption[]; | ||
let optionElements: HTMLElement[]; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [CdkListboxModule], | ||
declarations: [ListboxWithOptions], | ||
}).compileComponents(); | ||
})); | ||
|
||
beforeEach(async(() => { | ||
fixture = TestBed.createComponent(ListboxWithOptions); | ||
fixture.detectChanges(); | ||
|
||
options = fixture.debugElement.queryAll(By.directive(CdkOption)); | ||
optionInstances = options.map(o => o.injector.get<CdkOption>(CdkOption)); | ||
optionElements = options.map(o => o.nativeElement); | ||
})); | ||
|
||
it('should generate a unique optionId for each option', () => { | ||
let optionIds: string[] = []; | ||
for (const instance of optionInstances) { | ||
expect(optionIds.indexOf(instance.id)).toBe(-1); | ||
optionIds.push(instance.id); | ||
|
||
expect(instance.id).toMatch(/cdk-option-\d+/); | ||
} | ||
}); | ||
|
||
it('should have set the selected input of the options to null by default', () => { | ||
for (const instance of optionInstances) { | ||
expect(instance.selected).toBeFalse(); | ||
} | ||
}); | ||
|
||
it('should update aria-selected when selected is changed programmatically', () => { | ||
expect(optionElements[0].getAttribute('aria-selected')).toBeNull(); | ||
optionInstances[1].selected = true; | ||
fixture.detectChanges(); | ||
|
||
expect(optionElements[1].getAttribute('aria-selected')).toBe('true'); | ||
}); | ||
|
||
it('should update selected option on click event', () => { | ||
jelbourn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let selectedOptions = optionInstances.filter(option => option.selected); | ||
|
||
expect(selectedOptions.length).toBe(0); | ||
expect(optionElements[0].getAttribute('aria-selected')).toBeNull(); | ||
expect(optionInstances[0].selected).toBeFalse(); | ||
expect(fixture.componentInstance.changedOption).toBeUndefined(); | ||
|
||
dispatchMouseEvent(optionElements[0], 'click'); | ||
fixture.detectChanges(); | ||
|
||
selectedOptions = optionInstances.filter(option => option.selected); | ||
expect(selectedOptions.length).toBe(1); | ||
expect(optionElements[0].getAttribute('aria-selected')).toBe('true'); | ||
expect(optionInstances[0].selected).toBeTrue(); | ||
expect(fixture.componentInstance.changedOption).toBeDefined(); | ||
expect(fixture.componentInstance.changedOption.id).toBe(optionInstances[0].id); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
@Component({ | ||
template: ` | ||
<div cdkListbox (selectionChange)="onSelectionChange($event)"> | ||
<div cdkOption>Void</div> | ||
<div cdkOption>Solar</div> | ||
<div cdkOption>Arc</div> | ||
<div cdkOption>Stasis</div> | ||
</div>` | ||
}) | ||
class ListboxWithOptions { | ||
changedOption: CdkOption; | ||
|
||
onSelectionChange(event: ListboxSelectionChangeEvent) { | ||
this.changedOption = event.option; | ||
} | ||
} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.