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 { of as observableOf } from 'rxjs';
9 import { ToastrModule } from 'ngx-toastr';
10 import { RgwRealmService } from '~/app/shared/api/rgw-realm.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 { RgwMultisiteRealmFormComponent } from './rgw-multisite-realm-form.component';
17 describe('RgwMultisiteRealmFormComponent', () => {
18 let component: RgwMultisiteRealmFormComponent;
19 let fixture: ComponentFixture<RgwMultisiteRealmFormComponent>;
20 let rgwRealmService: RgwRealmService;
22 beforeEach(async () => {
23 await TestBed.configureTestingModule({
28 HttpClientTestingModule,
29 ToastrModule.forRoot()
31 providers: [NgbActiveModal],
32 declarations: [RgwMultisiteRealmFormComponent]
33 }).compileComponents();
37 fixture = TestBed.createComponent(RgwMultisiteRealmFormComponent);
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 rgwRealmService = TestBed.inject(RgwRealmService);
56 it('should validate name', () => {
57 component.action = 'create';
58 component.createForm();
59 const control = component.multisiteRealmForm.get('realmName');
60 expect(_.isFunction(control.validator)).toBeTruthy();
63 it('should not validate name', () => {
64 component.action = 'edit';
65 component.createForm();
66 const control = component.multisiteRealmForm.get('realmName');
67 expect(control.asyncValidator).toBeNull();
70 it('tests create success notification', () => {
71 spyOn(rgwRealmService, 'create').and.returnValue(observableOf([]));
72 component.action = 'create';
73 component.multisiteRealmForm.markAsDirty();
75 expect(notificationService.show).toHaveBeenCalledWith(
76 NotificationType.success,
77 "Realm: 'null' created successfully"
81 it('tests update success notification', () => {
82 spyOn(rgwRealmService, 'update').and.returnValue(observableOf([]));
83 component.action = 'edit';
85 data: { name: 'null' }
87 component.multisiteRealmForm.markAsDirty();
89 expect(notificationService.show).toHaveBeenCalledWith(
90 NotificationType.success,
91 "Realm: 'null' updated successfully"