@@ -12,6 +12,11 @@ import { IgxDateRangeModule } from './igx-date-range.module';
12
12
import { By } from '@angular/platform-browser' ;
13
13
import { UIInteractions } from '../test-utils/ui-interactions.spec' ;
14
14
15
+ const CSS_CLASS_INPUT = 'igx-input-group__input' ;
16
+ const CSS_CLASS_TOGGLE_BUTTON = 'igx-icon' ;
17
+ const CSS_CLASS_CALENDAR = 'igx-calendar' ;
18
+ const CSS_CLASS_CALENDAR_WRAPPER = 'igx-toggle' ; // TODO Implementation -> maybe add class for the div container
19
+
15
20
function getDatesInView ( dates : DebugElement [ ] ) : DebugElement [ ] {
16
21
return dates . filter ( d => {
17
22
const date = d . childNodes [ 0 ] . nativeNode . innerText ;
@@ -20,8 +25,11 @@ function getDatesInView(dates: DebugElement[]): DebugElement[] {
20
25
}
21
26
22
27
// tslint:disable: no-use-before-declare
23
- xdescribe ( 'IgxDateRange' , ( ) => {
24
- let singleInputRange : DateRangeTwoInputsTestComponent ;
28
+ describe ( 'IgxDateRange' , ( ) => {
29
+ let calendarElement : DebugElement ;
30
+ let calendarWrapper : DebugElement ;
31
+
32
+ let singleInputRange : DateRangeSingleInputTestComponent ;
25
33
let twoInputsRange : DateRangeTwoInputsTestComponent ;
26
34
let fixture : ComponentFixture < DateRangeTestComponent > ;
27
35
@@ -227,6 +235,12 @@ xdescribe('IgxDateRange', () => {
227
235
} ) ;
228
236
229
237
describe ( 'Single Input' , ( ) => {
238
+ beforeEach ( fakeAsync ( ( ) => {
239
+ fixture = TestBed . createComponent ( DateRangeSingleInputTestComponent ) ;
240
+ fixture . detectChanges ( ) ;
241
+ tick ( ) ;
242
+ } ) ) ;
243
+
230
244
/* The single input's text looks like this -> START_DATE - END_DATE */
231
245
232
246
it ( 'Should set the first part of the input properly on first date selection' , ( ) => {
@@ -246,6 +260,37 @@ xdescribe('IgxDateRange', () => {
246
260
it ( 'Should do a range selection if a date is selected and "Today" is pressed' , ( ) => {
247
261
// TODO
248
262
} ) ;
263
+
264
+ it ( 'should render aria attributes properly' , fakeAsync ( ( ) => {
265
+ fixture = TestBed . createComponent ( DateRangeSingleInputTestARIAComponent ) ;
266
+ fixture . detectChanges ( ) ;
267
+ const dateRangeSingle = fixture . componentInstance . dateRange ;
268
+ fixture . detectChanges ( ) ;
269
+
270
+ const singleInputElement = fixture . debugElement . query ( By . css ( '.' + CSS_CLASS_INPUT ) ) ;
271
+ calendarElement = fixture . debugElement . query ( By . css ( '.' + CSS_CLASS_CALENDAR ) ) ;
272
+ calendarWrapper = fixture . debugElement . query ( By . css ( '.' + CSS_CLASS_CALENDAR_WRAPPER ) ) ;
273
+ const expectedLabelID = dateRangeSingle . label . id ;
274
+ const toggleBtn = fixture . debugElement . query ( By . css ( '.' + CSS_CLASS_TOGGLE_BUTTON ) ) ;
275
+
276
+ expect ( singleInputElement . nativeElement . getAttribute ( 'role' ) ) . toEqual ( 'combobox' ) ;
277
+ expect ( singleInputElement . nativeElement . getAttribute ( 'aria-haspopup' ) ) . toEqual ( 'grid' ) ;
278
+ expect ( singleInputElement . nativeElement . getAttribute ( 'aria-expanded' ) ) . toEqual ( 'false' ) ;
279
+ expect ( toggleBtn . nativeElement . getAttribute ( 'aria-hidden' ) ) . toEqual ( 'true' ) ;
280
+ expect ( calendarElement . nativeElement . getAttribute ( 'role' ) ) . toEqual ( 'grid' ) ;
281
+ expect ( singleInputElement . nativeElement . getAttribute ( 'aria-labelledby' ) ) . toEqual ( expectedLabelID ) ;
282
+ dateRangeSingle . toggle ( ) ;
283
+ tick ( ) ;
284
+ fixture . detectChanges ( ) ;
285
+
286
+ expect ( singleInputElement . nativeElement . getAttribute ( 'aria-expanded' ) ) . toEqual ( 'true' ) ;
287
+ expect ( calendarWrapper . nativeElement . getAttribute ( 'aria-hidden' ) ) . toEqual ( 'false' ) ;
288
+
289
+ dateRangeSingle . toggle ( ) ;
290
+ tick ( ) ;
291
+ fixture . detectChanges ( ) ;
292
+ expect ( singleInputElement . nativeElement . getAttribute ( 'aria-expanded' ) ) . toEqual ( 'false' ) ;
293
+ } ) ) ;
249
294
} ) ;
250
295
} ) ;
251
296
@@ -268,7 +313,7 @@ export class DateRangeTestComponent implements OnInit {
268
313
}
269
314
270
315
@Component ( {
271
- selector : 'igx-date-range-single-input -test' ,
316
+ selector : 'igx-date-range-two-inputs -test' ,
272
317
template : `
273
318
<igx-input-group>
274
319
<input #fullName igxInput type="text">
@@ -298,7 +343,7 @@ export class DateRangeTestComponent implements OnInit {
298
343
export class DateRangeTwoInputsTestComponent extends DateRangeTestComponent { }
299
344
300
345
@Component ( {
301
- selector : 'igx-date-range-two-inputs -test' ,
346
+ selector : 'igx-date-range-single-input -test' ,
302
347
template : `
303
348
<igx-input-group>
304
349
<input #fullName igxInput type="text">
@@ -318,18 +363,36 @@ export class DateRangeTwoInputsTestComponent extends DateRangeTestComponent { }
318
363
</igx-date-range>
319
364
`
320
365
} )
321
- export class DateRangeSingleInputTestComponent extends DateRangeTestComponent { }
366
+ export class DateRangeSingleInputTestComponent extends DateRangeTestComponent {
367
+ }
368
+
369
+ @Component ( {
370
+ selector : 'igx-date-range-single-input-aria-test' ,
371
+ template : `
372
+ <igx-date-range [mode]="mode" [todayButtonText]="todayButtonText" [doneButtonText]="doneButtonText">
373
+ <igx-input-group>
374
+ <input #singleInput igxInput igxDateRange type="text">
375
+ <label igxLabel for="singleInput">Input Date</label>
376
+ <igx-prefix>
377
+ <igx-icon>today</igx-icon>
378
+ </igx-prefix>
379
+ </igx-input-group>
380
+ </igx-date-range>
381
+ `
382
+ } )
383
+ export class DateRangeSingleInputTestARIAComponent extends DateRangeTestComponent {
384
+ }
322
385
323
386
@NgModule ( {
324
387
declarations : [
325
388
DateRangeSingleInputTestComponent ,
389
+ DateRangeSingleInputTestARIAComponent ,
326
390
DateRangeTwoInputsTestComponent ,
327
391
DateRangeTestComponent
328
392
] ,
329
393
imports : [
330
394
IgxDateRangeModule ,
331
395
NoopAnimationsModule ,
332
- IgxInputGroupModule ,
333
396
ReactiveFormsModule ,
334
397
IgxIconModule ,
335
398
IgxCalendarModule ,
@@ -339,6 +402,7 @@ export class DateRangeSingleInputTestComponent extends DateRangeTestComponent {
339
402
] ,
340
403
exports : [
341
404
DateRangeSingleInputTestComponent ,
405
+ DateRangeSingleInputTestARIAComponent ,
342
406
DateRangeTwoInputsTestComponent ,
343
407
DateRangeTestComponent
344
408
]
0 commit comments