]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/blob
73bc10c46852b17fb178b06804517f050d59b374
[ceph.git] /
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';
11
12 describe('SmbClusterFormComponent', () => {
13   let component: SmbClusterFormComponent;
14   let fixture: ComponentFixture<SmbClusterFormComponent>;
15
16   beforeEach(async () => {
17     await TestBed.configureTestingModule({
18       imports: [
19         BrowserAnimationsModule,
20         SharedModule,
21         HttpClientTestingModule,
22         RouterTestingModule,
23         ReactiveFormsModule,
24         ToastrModule.forRoot(),
25         GridModule,
26         InputModule,
27         SelectModule,
28         ComboBoxModule
29       ],
30       declarations: [SmbClusterFormComponent]
31     }).compileComponents();
32
33     fixture = TestBed.createComponent(SmbClusterFormComponent);
34     component = fixture.componentInstance;
35     fixture.detectChanges();
36   });
37
38   it('should create', () => {
39     expect(component).toBeTruthy();
40   });
41
42   it('should have cluster_id and domain_settings as required fields', () => {
43     fixture.detectChanges();
44
45     const clusterIdControl = component.smbForm.get('cluster_id');
46     const domainSettingsControl = component.smbForm.get('domain_settings');
47
48     const isClusterId = [clusterIdControl.validator].includes(Validators.required);
49     const isDomainSettings = [domainSettingsControl.validator].includes(Validators.required);
50
51     expect(isClusterId).toBe(false);
52     expect(isDomainSettings).toBe(true);
53   });
54
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);
61   });
62
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);
69   });
70
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);
78   });
79
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();
85   });
86
87   it('should delete domain', () => {
88     component.deleteDomainSettingsModal();
89     expect(component).toBeTruthy();
90   });
91 });