From 5fc32a67fca0e02a2cacef01e63c269895245b59 Mon Sep 17 00:00:00 2001 From: Ilya Borisov Date: Thu, 25 Apr 2019 17:51:43 +0700 Subject: [PATCH] Initial form-field unit test. --- .../form-field/formField.component.spec.ts | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 modules/web-console/frontend/app-angular/components/form-field/formField.component.spec.ts diff --git a/modules/web-console/frontend/app-angular/components/form-field/formField.component.spec.ts b/modules/web-console/frontend/app-angular/components/form-field/formField.component.spec.ts new file mode 100644 index 0000000000000..1da3e38f13a74 --- /dev/null +++ b/modules/web-console/frontend/app-angular/components/form-field/formField.component.spec.ts @@ -0,0 +1,88 @@ +/* + * Copyright 2019 GridGain Systems, Inc. and Contributors. + * + * Licensed under the GridGain Community Edition License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gridgain.com/products/software/community-edition/gridgain-community-edition-license + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import 'zone.js/dist/zone'; + +// https://stackoverflow.com/q/52176565/333777 +import 'zone.js/dist/long-stack-trace-zone'; +import 'zone.js/dist/proxy'; +import 'zone.js/dist/sync-test'; +import 'zone.js/dist/mocha-patch'; +import 'zone.js/dist/async-test'; +import 'zone.js/dist/fake-async-test'; +import 'zone.js/dist/zone-patch-promise-test'; + +import 'core-js/es7/reflect'; + +import { + BrowserDynamicTestingModule, + platformBrowserDynamicTesting +} from '@angular/platform-browser-dynamic/testing'; +import {ReactiveFormsModule, FormControl, Validators, FormGroup} from '@angular/forms'; + +import {assert} from 'chai'; +import {TestBed, async, ComponentFixture, tick, fakeAsync} from '@angular/core/testing'; +import {Component, Directive, NO_ERRORS_SCHEMA} from '@angular/core'; +import { + FormField, FormFieldError, FormFieldHint, FormFieldTooltip, + FormFieldRequiredMarkerStyles +} from './index'; +import {FormFieldErrors} from './errors.component'; +import {IgniteIcon} from '../igniteIcon.component'; + +TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting()); + +suite.only('form-field', () => { + let fixture: ComponentFixture; + @Component({ + template: ` +
+ + + + +
+ ` + }) + class HostComponent { + form = new FormGroup({ + one: new FormControl(null, [Validators.required]) + }) + markerStyle = FormFieldRequiredMarkerStyles.REQUIRED + } + @Component({selector: 'popper-content', template: ''}) class PopperContentStub {} + @Directive({selector: '[popper]'}) class PopperStub {} + + setup(fakeAsync(async() => { + TestBed.configureTestingModule({ + declarations: [ + FormField, + HostComponent + ], + schemas: [NO_ERRORS_SCHEMA], + imports: [ReactiveFormsModule] + }).compileComponents().then(() => { + + fixture = TestBed.createComponent(HostComponent); + fixture.detectChanges(); + tick(); + fixture.detectChanges(); + }); + })); + test('Required host class', () => { + assert.ok(fixture.nativeElement.querySelector('form-field').matches('.form-field__required')); + }); +});