1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { ReactiveFormsModule } from '@angular/forms';
4 import { Router } from '@angular/router';
5 import { RouterTestingModule } from '@angular/router/testing';
6 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
7 import _ from 'lodash';
8 import { ToastrModule } from 'ngx-toastr';
9 import { of as observableOf } from 'rxjs';
10 import { RgwZonegroupService } from '~/app/shared/api/rgw-zonegroup.service';
11 import { NotificationType } from '~/app/shared/enum/notification-type.enum';
12 import { NotificationService } from '~/app/shared/services/notification.service';
13 import { SharedModule } from '~/app/shared/shared.module';
15 import { RgwMultisiteZonegroupFormComponent } from './rgw-multisite-zonegroup-form.component';
17 describe('RgwMultisiteZonegroupFormComponent', () => {
18 let component: RgwMultisiteZonegroupFormComponent;
19 let fixture: ComponentFixture<RgwMultisiteZonegroupFormComponent>;
20 let rgwZonegroupService: RgwZonegroupService;
22 beforeEach(async () => {
23 await TestBed.configureTestingModule({
28 HttpClientTestingModule,
29 ToastrModule.forRoot()
31 providers: [NgbActiveModal],
32 declarations: [RgwMultisiteZonegroupFormComponent]
33 }).compileComponents();
37 fixture = TestBed.createComponent(RgwMultisiteZonegroupFormComponent);
38 component = fixture.componentInstance;
39 fixture.detectChanges();
42 it('should create', () => {
43 expect(component).toBeTruthy();
46 describe('submit form', () => {
47 let notificationService: NotificationService;
50 spyOn(TestBed.inject(Router), 'navigate').and.stub();
51 notificationService = TestBed.inject(NotificationService);
52 spyOn(notificationService, 'show');
53 rgwZonegroupService = TestBed.inject(RgwZonegroupService);
56 it('should validate name', () => {
57 component.action = 'create';
58 component.createForm();
59 const control = component.multisiteZonegroupForm.get('zonegroupName');
60 expect(_.isFunction(control.validator)).toBeTruthy();
63 it('should not validate name', () => {
64 component.action = 'edit';
65 component.createForm();
66 const control = component.multisiteZonegroupForm.get('zonegroupName');
67 expect(control.asyncValidator).toBeNull();
70 it('tests create success notification', () => {
71 spyOn(rgwZonegroupService, 'create').and.returnValue(observableOf([]));
72 component.action = 'create';
73 component.multisiteZonegroupForm.markAsDirty();
74 component.multisiteZonegroupForm._get('zonegroupName').setValue('zg-1');
75 component.multisiteZonegroupForm
76 ._get('zonegroup_endpoints')
77 .setValue('http://192.1.1.1:8004');
79 expect(notificationService.show).toHaveBeenCalledWith(
80 NotificationType.success,
81 "Zonegroup: 'zg-1' created successfully"
85 it('tests update success notification', () => {
86 spyOn(rgwZonegroupService, 'update').and.returnValue(observableOf([]));
87 component.action = 'edit';
89 data: { name: 'zg-1', zones: ['z1'] }
91 component.multisiteZonegroupForm._get('zonegroupName').setValue('zg-1');
92 component.multisiteZonegroupForm
93 ._get('zonegroup_endpoints')
94 .setValue('http://192.1.1.1:8004,http://192.12.12.12:8004');
95 component.multisiteZonegroupForm.markAsDirty();
97 expect(notificationService.show).toHaveBeenCalledWith(
98 NotificationType.success,
99 "Zonegroup: 'zg-1' updated successfully"