]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/blob
1fa45cd8ae1b0d655cf6af447d1d6cd8e3c69fe4
[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 import { FOO_USERSGROUPS } from '../smb-usersgroups-form/smb-usersgroups-form.component.spec';
12 import { of } from 'rxjs';
13 import { By } from '@angular/platform-browser';
14
15 describe('SmbClusterFormComponent', () => {
16   let component: SmbClusterFormComponent;
17   let fixture: ComponentFixture<SmbClusterFormComponent>;
18
19   beforeEach(async () => {
20     await TestBed.configureTestingModule({
21       imports: [
22         BrowserAnimationsModule,
23         SharedModule,
24         HttpClientTestingModule,
25         RouterTestingModule,
26         ReactiveFormsModule,
27         ToastrModule.forRoot(),
28         GridModule,
29         InputModule,
30         SelectModule,
31         ComboBoxModule
32       ],
33       declarations: [SmbClusterFormComponent]
34     }).compileComponents();
35
36     fixture = TestBed.createComponent(SmbClusterFormComponent);
37     component = fixture.componentInstance;
38     fixture.detectChanges();
39   });
40
41   it('should create', () => {
42     expect(component).toBeTruthy();
43   });
44
45   it('should have cluster_id and domain_settings as required fields', () => {
46     fixture.detectChanges();
47
48     const clusterIdControl = component.smbForm.get('cluster_id');
49     const domainSettingsControl = component.smbForm.get('domain_settings');
50
51     const isClusterId = [clusterIdControl.validator].includes(Validators.required);
52     const isDomainSettings = [domainSettingsControl.validator].includes(Validators.required);
53
54     expect(isClusterId).toBe(false);
55     expect(isDomainSettings).toBe(true);
56   });
57
58   it('should add and remove user group settings', () => {
59     const defaultLength = component.joinSources.length;
60     component.addUserGroupSetting();
61     expect(component.joinSources.length).toBe(defaultLength + 1);
62     component.removeUserGroupSetting(0);
63     expect(component.joinSources.length).toBe(defaultLength);
64   });
65
66   it('should add and remove custom dns settings (custom_dns)', () => {
67     const defaultLength = component.custom_dns.length;
68     component.addCustomDns();
69     expect(component.custom_dns.length).toBe(defaultLength + 1);
70     component.removeCustomDNS(0);
71     expect(component.custom_dns.length).toBe(defaultLength);
72   });
73
74   it('should change the form when authmode is changed', () => {
75     const authModeControl = component.smbForm.get('auth_mode');
76     authModeControl?.setValue('user');
77     component.onAuthModeChange();
78     fixture.detectChanges();
79     const joinSourcesControl = component.smbForm.get('joinSources') as FormArray;
80     expect(joinSourcesControl.length).toBe(1);
81   });
82
83   it('should check submit request', () => {
84     component.smbForm.get('auth_mode').setValue(AUTHMODE.activeDirectory);
85     component.smbForm.get('domain_settings').setValue('test-realm');
86     component.smbForm.get('cluster_id').setValue('cluster-id');
87     component.submitAction();
88   });
89
90   it('should delete domain', () => {
91     component.deleteDomainSettingsModal();
92     expect(component).toBeTruthy();
93   });
94
95   it('should get usersgroups resources on user authmode', () => {
96     component.smbForm.get('auth_mode').setValue(AUTHMODE.User);
97     component.usersGroups$ = of([FOO_USERSGROUPS]);
98     fixture.whenStable().then(() => {
99       const options = fixture.debugElement.queryAll(By.css('select option'));
100
101       expect(options.length).toBe(1);
102       expect(options[0].nativeElement.value).toBe('foo');
103       expect(options[0].nativeElement.textContent).toBe('foo');
104     });
105   });
106 });