|
1 | 1 | import {Platform, PlatformModule} from '@angular/cdk/platform';
|
2 |
| -import {createFakeEvent, dispatchFakeEvent, wrappedErrorMessage} from '@angular/cdk/testing'; |
3 |
| -import {ChangeDetectionStrategy, Component, ViewChild, Type, Provider} from '@angular/core'; |
| 2 | +import { |
| 3 | + createFakeEvent, |
| 4 | + dispatchFakeEvent, |
| 5 | + wrappedErrorMessage, |
| 6 | + MockNgZone, |
| 7 | +} from '@angular/cdk/testing'; |
| 8 | +import {ChangeDetectionStrategy, Component, ViewChild, Type, Provider, NgZone} from '@angular/core'; |
4 | 9 | import {ComponentFixture, fakeAsync, flush, TestBed} from '@angular/core/testing';
|
5 | 10 | import {
|
6 | 11 | FormControl,
|
@@ -28,10 +33,10 @@ import {
|
28 | 33 | } from '@angular/material/form-field';
|
29 | 34 | import {By} from '@angular/platform-browser';
|
30 | 35 | import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
|
31 |
| -import {MatInputModule} from './index'; |
32 |
| -import {MatInput} from './input'; |
33 | 36 | import {MatStepperModule} from '@angular/material/stepper';
|
34 | 37 | import {MatTabsModule} from '@angular/material/tabs';
|
| 38 | +import {MatInputModule} from './index'; |
| 39 | +import {MatInput} from './input'; |
35 | 40 | import {MatTextareaAutosize} from './autosize';
|
36 | 41 |
|
37 | 42 | describe('MatInput without forms', () => {
|
@@ -1170,6 +1175,35 @@ describe('MatInput with appearance', () => {
|
1170 | 1175 | expect(parseInt(outlineGap.style.width)).toBeFalsy();
|
1171 | 1176 | }));
|
1172 | 1177 |
|
| 1178 | + it('should calculate the gaps if the default appearance is provided through DI', fakeAsync(() => { |
| 1179 | + fixture.destroy(); |
| 1180 | + TestBed.resetTestingModule(); |
| 1181 | + |
| 1182 | + let zone: MockNgZone; |
| 1183 | + const labelFixture = createComponent(MatInputWithLabel, [ |
| 1184 | + { |
| 1185 | + provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, |
| 1186 | + useValue: {appearance: 'outline'} |
| 1187 | + }, |
| 1188 | + { |
| 1189 | + provide: NgZone, |
| 1190 | + useFactory: () => zone = new MockNgZone() |
| 1191 | + } |
| 1192 | + ]); |
| 1193 | + |
| 1194 | + labelFixture.detectChanges(); |
| 1195 | + zone!.simulateZoneExit(); |
| 1196 | + flush(); |
| 1197 | + labelFixture.detectChanges(); |
| 1198 | + |
| 1199 | + const wrapperElement = labelFixture.nativeElement; |
| 1200 | + const outlineStart = wrapperElement.querySelector('.mat-form-field-outline-start'); |
| 1201 | + const outlineGap = wrapperElement.querySelector('.mat-form-field-outline-gap'); |
| 1202 | + |
| 1203 | + expect(parseInt(outlineStart.style.width)).toBeGreaterThan(0); |
| 1204 | + expect(parseInt(outlineGap.style.width)).toBeGreaterThan(0); |
| 1205 | + })); |
| 1206 | + |
1173 | 1207 | });
|
1174 | 1208 |
|
1175 | 1209 | describe('MatFormField default options', () => {
|
@@ -1586,6 +1620,16 @@ class MatInputOnPush {
|
1586 | 1620 | })
|
1587 | 1621 | class MatInputWithReadonlyInput {}
|
1588 | 1622 |
|
| 1623 | +@Component({ |
| 1624 | + template: ` |
| 1625 | + <mat-form-field> |
| 1626 | + <mat-label>Label</mat-label> |
| 1627 | + <input matInput> |
| 1628 | + </mat-form-field> |
| 1629 | + ` |
| 1630 | +}) |
| 1631 | +class MatInputWithLabel {} |
| 1632 | + |
1589 | 1633 | @Component({
|
1590 | 1634 | template: `
|
1591 | 1635 | <mat-form-field [floatLabel]="floatLabel">
|
|
0 commit comments