1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
3 import { FormControl, ReactiveFormsModule } from '@angular/forms';
4 import { RouterTestingModule } from '@angular/router/testing';
6 import { of as observableOf } from 'rxjs';
8 import { RgwBucketService } from '../../../shared/api/rgw-bucket.service';
9 import { RgwUserService } from '../../../shared/api/rgw-user.service';
10 import { SharedModule } from '../../../shared/shared.module';
11 import { RgwBucketFormComponent } from './rgw-bucket-form.component';
13 describe('RgwBucketFormComponent', () => {
14 let component: RgwBucketFormComponent;
15 let fixture: ComponentFixture<RgwBucketFormComponent>;
16 let queryResult: Array<string> = [];
18 class MockRgwBucketService extends RgwBucketService {
20 return observableOf(queryResult);
24 beforeEach(async(() => {
25 TestBed.configureTestingModule({
26 declarations: [RgwBucketFormComponent],
27 imports: [HttpClientTestingModule, ReactiveFormsModule, RouterTestingModule, SharedModule],
28 providers: [RgwUserService, { provide: RgwBucketService, useClass: MockRgwBucketService }]
29 }).compileComponents();
33 fixture = TestBed.createComponent(RgwBucketFormComponent);
34 component = fixture.componentInstance;
35 fixture.detectChanges();
38 it('should create', () => {
39 expect(component).toBeTruthy();
42 describe('bucketNameValidator', () => {
43 it('should validate name (1/4)', () => {
44 const validatorFn = component.bucketNameValidator();
45 const ctrl = new FormControl('');
46 const validatorPromise = validatorFn(ctrl);
47 expect(validatorPromise instanceof Promise).toBeTruthy();
48 if (validatorPromise instanceof Promise) {
49 validatorPromise.then((resp) => {
50 expect(resp).toBe(null);
55 it('should validate name (2/4)', () => {
56 const validatorFn = component.bucketNameValidator();
57 const ctrl = new FormControl('ab');
59 const validatorPromise = validatorFn(ctrl);
60 expect(validatorPromise instanceof Promise).toBeTruthy();
61 if (validatorPromise instanceof Promise) {
62 validatorPromise.then((resp) => {
63 expect(resp.bucketNameInvalid).toBeTruthy();
68 it('should validate name (3/4)', () => {
69 const validatorFn = component.bucketNameValidator();
70 const ctrl = new FormControl('abc');
72 const validatorPromise = validatorFn(ctrl);
73 expect(validatorPromise instanceof Promise).toBeTruthy();
74 if (validatorPromise instanceof Promise) {
75 validatorPromise.then((resp) => {
76 expect(resp).toBe(null);
81 it('should validate name (4/4)', () => {
82 queryResult = ['abcd'];
83 const validatorFn = component.bucketNameValidator();
84 const ctrl = new FormControl('abcd');
86 const validatorPromise = validatorFn(ctrl);
87 expect(validatorPromise instanceof Promise).toBeTruthy();
88 if (validatorPromise instanceof Promise) {
89 validatorPromise.then((resp) => {
90 expect(resp instanceof Object).toBeTruthy();
91 expect(resp.bucketNameExists).toBeTruthy();