Skip to content

Commit da18ca9

Browse files
committed
test(input-group): covering the newly added readonly directive
1 parent c95f4ba commit da18ca9

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { Component, ViewChild } from '@angular/core';
2+
import { TestBed, waitForAsync } from '@angular/core/testing';
3+
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
4+
import { IgxReadOnlyInputDirective } from './read-only-input.directive';
5+
import { IgxDatePickerComponent, IgxInputGroupComponent } from 'igniteui-angular';
6+
import { By } from '@angular/platform-browser';
7+
8+
describe('IgxReadOnlyInputDirective', () => {
9+
beforeEach(waitForAsync(() => {
10+
TestBed.configureTestingModule({
11+
imports: [
12+
NoopAnimationsModule,
13+
TestComponent
14+
]
15+
})
16+
.compileComponents();
17+
}));
18+
19+
it('should update readOnly property and `igx-input-group--readonly` class correctly', () => {
20+
const fixture = TestBed.createComponent(TestComponent);
21+
fixture.detectChanges();
22+
23+
const inputGroupDebug = fixture.debugElement.query(By.directive(IgxInputGroupComponent));
24+
const inputGroupEl = inputGroupDebug.nativeElement as HTMLElement;
25+
expect(inputGroupEl.classList.contains('igx-input-group--readonly')).toBeFalse();
26+
27+
const inputDebug = fixture.debugElement.query(By.css('input'));
28+
const inputEl = inputDebug.nativeElement as HTMLInputElement;
29+
expect(inputEl.readOnly).toBeFalse();
30+
31+
fixture.componentInstance.datePicker.readOnly = true;
32+
fixture.detectChanges();
33+
expect(inputGroupEl.classList.contains('igx-input-group--readonly')).toBeTrue();
34+
expect(inputEl.readOnly).toBeTrue();
35+
36+
fixture.componentInstance.datePicker.readOnly = false;
37+
fixture.detectChanges();
38+
expect(inputGroupEl.classList.contains('igx-input-group--readonly')).toBeFalse();
39+
expect(inputEl.readOnly).toBeFalse();
40+
41+
// When the date-picker component is in dialog mode, the native input is always readonly
42+
fixture.componentInstance.datePicker.mode = 'dialog';
43+
fixture.detectChanges();
44+
expect(inputGroupEl.classList.contains('igx-input-group--readonly')).toBeFalse();
45+
expect(inputEl.readOnly).toBeTrue();
46+
47+
fixture.componentInstance.datePicker.readOnly = true;
48+
fixture.detectChanges();
49+
expect(inputGroupEl.classList.contains('igx-input-group--readonly')).toBeTrue();
50+
expect(inputEl.readOnly).toBeTrue();
51+
});
52+
});
53+
54+
@Component({
55+
template: `<igx-date-picker></igx-date-picker>`,
56+
imports: [IgxDatePickerComponent, IgxReadOnlyInputDirective]
57+
})
58+
class TestComponent {
59+
@ViewChild(IgxDatePickerComponent, { static: true })
60+
public datePicker!: IgxDatePickerComponent;
61+
}

0 commit comments

Comments
 (0)