1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ReactiveFormsModule } from '@angular/forms';
import { RouterTestingModule } from '@angular/router/testing';
import { ToastrModule } from 'ngx-toastr';
import { LoadingPanelComponent } from '~/app/shared/components/loading-panel/loading-panel.component';
import { SharedModule } from '~/app/shared/shared.module';
import { configureTestBed } from '~/testing/unit-test-helper';
import { MgrModuleFormComponent } from './mgr-module-form.component';
describe('MgrModuleFormComponent', () => {
let component: MgrModuleFormComponent;
let fixture: ComponentFixture<MgrModuleFormComponent>;
configureTestBed(
{
declarations: [MgrModuleFormComponent],
imports: [
HttpClientTestingModule,
ReactiveFormsModule,
RouterTestingModule,
SharedModule,
ToastrModule.forRoot()
]
},
[LoadingPanelComponent]
);
beforeEach(() => {
fixture = TestBed.createComponent(MgrModuleFormComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
describe('getValidators', () => {
it('should return ip validator for type addr', () => {
const result = component.getValidators({ type: 'addr' });
expect(result.length).toBe(1);
});
it('should return required validator for types uint, int, size, secs', () => {
const types = ['uint', 'int', 'size', 'secs'];
types.forEach((type) => {
const result = component.getValidators({ type: type });
expect(result.length).toBe(1);
});
});
it('should return required, decimalNumber validators for type float', () => {
const result = component.getValidators({ type: 'float' });
expect(result.length).toBe(2);
});
it('should return uuid validator for type uuid', () => {
const result = component.getValidators({ type: 'uuid' });
expect(result.length).toBe(1);
});
it('should return no validator for type str', () => {
const result = component.getValidators({ type: 'str' });
expect(result.length).toBe(0);
});
it('should return min validator for type str', () => {
const result = component.getValidators({ type: 'str', min: 1 });
expect(result.length).toBe(1);
});
it('should return min, max validators for type str', () => {
const result = component.getValidators({ type: 'str', min: 1, max: 127 });
expect(result.length).toBe(2);
});
});
});
|