Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalerba committed Jul 14, 2017
1 parent 043818d commit 5bbf235
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/datepicker/datepicker-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const MD_DATEPICKER_VALIDATORS: any = {
providers: [MD_DATEPICKER_VALUE_ACCESSOR, MD_DATEPICKER_VALIDATORS],
host: {
'[attr.aria-haspopup]': 'true',
'[attr.aria-owns]': '_datepicker?.opened && _datepicker.id',
'[attr.aria-owns]': '(_datepicker?.opened && _datepicker.id) || null',
'[attr.min]': 'min ? _dateAdapter.getISODateString(min) : null',
'[attr.max]': 'max ? _dateAdapter.getISODateString(max) : null',
'[disabled]': 'disabled',
Expand Down
33 changes: 33 additions & 0 deletions src/lib/datepicker/datepicker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,39 @@ describe('MdDatepicker', () => {
expect(attachToRef.nativeElement.tagName.toLowerCase())
.toBe('input', 'popup should be attached to native input');
});

it('input should aria-owns calendar after opened in non-touch mode', () => {
let inputEl = fixture.debugElement.query(By.css('input')).nativeElement;
expect(inputEl.getAttribute('aria-owns')).toBeNull();

testComponent.datepicker.open();
fixture.detectChanges();

let ownedElementId = inputEl.getAttribute('aria-owns');
expect(ownedElementId).not.toBeNull();

let ownedElement = document.getElementById(ownedElementId);
expect(ownedElement).not.toBeNull();
expect((ownedElement as Element).tagName.toLowerCase()).toBe('md-calendar');
});

it('input should aria-owns calendar after opened in touch mode', () => {
testComponent.touch = true;
fixture.detectChanges();

let inputEl = fixture.debugElement.query(By.css('input')).nativeElement;
expect(inputEl.getAttribute('aria-owns')).toBeNull();

testComponent.datepicker.open();
fixture.detectChanges();

let ownedElementId = inputEl.getAttribute('aria-owns');
expect(ownedElementId).not.toBeNull();

let ownedElement = document.getElementById(ownedElementId);
expect(ownedElement).not.toBeNull();
expect((ownedElement as Element).tagName.toLowerCase()).toBe('md-calendar');
});
});

describe('datepicker with too many inputs', () => {
Expand Down

0 comments on commit 5bbf235

Please sign in to comment.