1 import { ComponentFixture, TestBed } from '@angular/core/testing';
2 import { HttpClientTestingModule } from '@angular/common/http/testing';
3 import { SmbClusterFormComponent } from './smb-cluster-form.component';
4 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
5 import { SharedModule } from '~/app/shared/shared.module';
6 import { RouterTestingModule } from '@angular/router/testing';
7 import { FormArray, ReactiveFormsModule, Validators } from '@angular/forms';
8 import { ToastrModule } from 'ngx-toastr';
9 import { ComboBoxModule, GridModule, InputModule, SelectModule } from 'carbon-components-angular';
10 import { AUTHMODE } from '../smb.model';
12 describe('SmbClusterFormComponent', () => {
13 let component: SmbClusterFormComponent;
14 let fixture: ComponentFixture<SmbClusterFormComponent>;
16 beforeEach(async () => {
17 await TestBed.configureTestingModule({
19 BrowserAnimationsModule,
21 HttpClientTestingModule,
24 ToastrModule.forRoot(),
30 declarations: [SmbClusterFormComponent]
31 }).compileComponents();
33 fixture = TestBed.createComponent(SmbClusterFormComponent);
34 component = fixture.componentInstance;
35 fixture.detectChanges();
38 it('should create', () => {
39 expect(component).toBeTruthy();
42 it('should have cluster_id and domain_settings as required fields', () => {
43 fixture.detectChanges();
45 const clusterIdControl = component.smbForm.get('cluster_id');
46 const domainSettingsControl = component.smbForm.get('domain_settings');
48 const isClusterId = [clusterIdControl.validator].includes(Validators.required);
49 const isDomainSettings = [domainSettingsControl.validator].includes(Validators.required);
51 expect(isClusterId).toBe(false);
52 expect(isDomainSettings).toBe(true);
55 it('should add and remove user group settings', () => {
56 const defaultLength = component.joinSources.length;
57 component.addUserGroupSetting();
58 expect(component.joinSources.length).toBe(defaultLength + 1);
59 component.removeUserGroupSetting(0);
60 expect(component.joinSources.length).toBe(defaultLength);
63 it('should add and remove custom dns settings (custom_dns)', () => {
64 const defaultLength = component.custom_dns.length;
65 component.addCustomDns();
66 expect(component.custom_dns.length).toBe(defaultLength + 1);
67 component.removeCustomDNS(0);
68 expect(component.custom_dns.length).toBe(defaultLength);
71 it('should change the form when authmode is changed', () => {
72 const authModeControl = component.smbForm.get('auth_mode');
73 authModeControl?.setValue('user');
74 component.onAuthModeChange();
75 fixture.detectChanges();
76 const joinSourcesControl = component.smbForm.get('joinSources') as FormArray;
77 expect(joinSourcesControl.length).toBe(1);
80 it('should check submit request', () => {
81 component.smbForm.get('auth_mode').setValue(AUTHMODE.activeDirectory);
82 component.smbForm.get('domain_settings').setValue('test-realm');
83 component.smbForm.get('cluster_id').setValue('cluster-id');
84 component.submitAction();
87 it('should delete domain', () => {
88 component.deleteDomainSettingsModal();
89 expect(component).toBeTruthy();