|
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', () => {
|
@@ -1151,6 +1156,36 @@ describe('MatInput with appearance', () => {
|
1151 | 1156 | expect(parseInt(outlineStart.style.width)).toBeGreaterThan(0);
|
1152 | 1157 | expect(parseInt(outlineGap.style.width)).toBeGreaterThan(0);
|
1153 | 1158 | }));
|
| 1159 | + |
| 1160 | + it('should calculate the gaps if the default appearance is provided through DI', fakeAsync(() => { |
| 1161 | + fixture.destroy(); |
| 1162 | + TestBed.resetTestingModule(); |
| 1163 | + |
| 1164 | + let zone: MockNgZone; |
| 1165 | + const labelFixture = createComponent(MatInputWithLabel, [ |
| 1166 | + { |
| 1167 | + provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, |
| 1168 | + useValue: {appearance: 'outline'} |
| 1169 | + }, |
| 1170 | + { |
| 1171 | + provide: NgZone, |
| 1172 | + useFactory: () => zone = new MockNgZone() |
| 1173 | + } |
| 1174 | + ]); |
| 1175 | + |
| 1176 | + labelFixture.detectChanges(); |
| 1177 | + zone!.simulateZoneExit(); |
| 1178 | + flush(); |
| 1179 | + labelFixture.detectChanges(); |
| 1180 | + |
| 1181 | + const wrapperElement = labelFixture.nativeElement; |
| 1182 | + const outlineStart = wrapperElement.querySelector('.mat-form-field-outline-start'); |
| 1183 | + const outlineGap = wrapperElement.querySelector('.mat-form-field-outline-gap'); |
| 1184 | + |
| 1185 | + expect(parseInt(outlineStart.style.width)).toBeGreaterThan(0); |
| 1186 | + expect(parseInt(outlineGap.style.width)).toBeGreaterThan(0); |
| 1187 | + })); |
| 1188 | + |
1154 | 1189 | });
|
1155 | 1190 |
|
1156 | 1191 | describe('MatFormField default options', () => {
|
@@ -1567,6 +1602,16 @@ class MatInputOnPush {
|
1567 | 1602 | })
|
1568 | 1603 | class MatInputWithReadonlyInput {}
|
1569 | 1604 |
|
| 1605 | +@Component({ |
| 1606 | + template: ` |
| 1607 | + <mat-form-field> |
| 1608 | + <mat-label>Label</mat-label> |
| 1609 | + <input matInput> |
| 1610 | + </mat-form-field> |
| 1611 | + ` |
| 1612 | +}) |
| 1613 | +class MatInputWithLabel {} |
| 1614 | + |
1570 | 1615 | @Component({
|
1571 | 1616 | template: `
|
1572 | 1617 | <mat-form-field [floatLabel]="floatLabel">
|
|
0 commit comments