Skip to content

Commit

Permalink
fix: bug where disabled options could be selected (#2243)
Browse files Browse the repository at this point in the history
* fix bug where disabled options could be selected

* test changes

* pasted to wrong line
  • Loading branch information
mikerodonnell89 committed Apr 2, 2020
1 parent b25382c commit 9f6b4d3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions libs/core/src/lib/select/option/option.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,30 @@ describe('OptionComponent', () => {
});

it('should be selectable by click', () => {
spyOn(component.selectedChange, 'emit');
spyOn(component, 'selectionHandler').and.callThrough();
component.getHtmlElement().click();
expect(component.selectionHandler).toHaveBeenCalled();
expect(component.selectedChange.emit).toHaveBeenCalled();
expect(component.selected).toBe(true);
});

it('should be selectable by keyboard', () => {
spyOn(component, 'selectionHandler').and.callThrough();
spyOn(component.selectedChange, 'emit');
component.getHtmlElement().dispatchEvent(new KeyboardEvent('keydown', {key: 'Enter'}));
expect(component.selectionHandler).toHaveBeenCalled();
expect(component.selectedChange.emit).toHaveBeenCalled();
expect(component.selected).toBe(true);
});

it('should not fire select event when disabled', () => {
spyOn(component.selectedChange, 'emit');
component.disabled = true;
component.selectionHandler();
expect(component.selectedChange.emit).not.toHaveBeenCalled();
})

it('should support custom view value', () => {
component.value = 'value';
expect(component.viewValueText).toBeFalsy();
Expand Down
2 changes: 1 addition & 1 deletion libs/core/src/lib/select/option/option.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ export class OptionComponent implements OnInit {
if (!this.selected && !this.disabled) {
this.selected = true;
this._changeDetRef.markForCheck();
this.selectedChange.emit(this);
}
this.selectedChange.emit(this);
}

}

0 comments on commit 9f6b4d3

Please sign in to comment.