1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { ReactiveFormsModule } from '@angular/forms';
4 import { RouterTestingModule } from '@angular/router/testing';
6 import { ToastrModule } from 'ngx-toastr';
8 import { configureTestBed, i18nProviders } from '../../../../../testing/unit-test-helper';
9 import { SharedModule } from '../../../../shared/shared.module';
10 import { MgrModuleFormComponent } from './mgr-module-form.component';
12 describe('MgrModuleFormComponent', () => {
13 let component: MgrModuleFormComponent;
14 let fixture: ComponentFixture<MgrModuleFormComponent>;
17 declarations: [MgrModuleFormComponent],
19 HttpClientTestingModule,
23 ToastrModule.forRoot()
25 providers: i18nProviders
29 fixture = TestBed.createComponent(MgrModuleFormComponent);
30 component = fixture.componentInstance;
31 fixture.detectChanges();
34 it('should create', () => {
35 expect(component).toBeTruthy();
38 describe('getValidators', () => {
39 it('should return ip validator for type addr', () => {
40 const result = component.getValidators({ type: 'addr' });
41 expect(result.length).toBe(1);
44 it('should return number, required validators for types uint, int, size, secs', () => {
45 const types = ['uint', 'int', 'size', 'secs'];
46 types.forEach((type) => {
47 const result = component.getValidators({ type: type });
48 expect(result.length).toBe(2);
52 it('should return number, required, min validators for types uint, int, size, secs', () => {
53 const types = ['uint', 'int', 'size', 'secs'];
54 types.forEach((type) => {
55 const result = component.getValidators({ type: type, min: 2 });
56 expect(result.length).toBe(3);
60 it('should return number, required, min, max validators for types uint, int, size, secs', () => {
61 const types = ['uint', 'int', 'size', 'secs'];
62 types.forEach((type) => {
63 const result = component.getValidators({ type: type, min: 2, max: 5 });
64 expect(result.length).toBe(4);
68 it('should return required, decimalNumber validators for type float', () => {
69 const result = component.getValidators({ type: 'float' });
70 expect(result.length).toBe(2);
73 it('should return uuid validator for type uuid', () => {
74 const result = component.getValidators({ type: 'uuid' });
75 expect(result.length).toBe(1);
78 it('should return no validator for type str', () => {
79 const result = component.getValidators({ type: 'str' });
80 expect(result.length).toBe(0);
83 it('should return min validator for type str', () => {
84 const result = component.getValidators({ type: 'str', min: 1 });
85 expect(result.length).toBe(1);
88 it('should return min, max validators for type str', () => {
89 const result = component.getValidators({ type: 'str', min: 1, max: 127 });
90 expect(result.length).toBe(2);