]>
Commit | Line | Data |
---|---|---|
a4b75251 TL |
1 | import { HttpClientTestingModule } from '@angular/common/http/testing'; |
2 | import { ComponentFixture, TestBed } from '@angular/core/testing'; | |
3 | import { By } from '@angular/platform-browser'; | |
4 | import { RouterTestingModule } from '@angular/router/testing'; | |
5 | ||
6 | import { ToastrModule } from 'ngx-toastr'; | |
7 | ||
8 | import { CephModule } from '~/app/ceph/ceph.module'; | |
9 | import { CoreModule } from '~/app/core/core.module'; | |
10 | import { HostService } from '~/app/shared/api/host.service'; | |
11 | import { OsdService } from '~/app/shared/api/osd.service'; | |
12 | import { ConfirmationModalComponent } from '~/app/shared/components/confirmation-modal/confirmation-modal.component'; | |
13 | import { LoadingPanelComponent } from '~/app/shared/components/loading-panel/loading-panel.component'; | |
14 | import { AppConstants } from '~/app/shared/constants/app.constants'; | |
15 | import { ModalService } from '~/app/shared/services/modal.service'; | |
16 | import { WizardStepsService } from '~/app/shared/services/wizard-steps.service'; | |
17 | import { SharedModule } from '~/app/shared/shared.module'; | |
18 | import { configureTestBed } from '~/testing/unit-test-helper'; | |
19 | import { CreateClusterComponent } from './create-cluster.component'; | |
20 | ||
21 | describe('CreateClusterComponent', () => { | |
22 | let component: CreateClusterComponent; | |
23 | let fixture: ComponentFixture<CreateClusterComponent>; | |
24 | let wizardStepService: WizardStepsService; | |
25 | let hostService: HostService; | |
26 | let osdService: OsdService; | |
27 | let modalServiceShowSpy: jasmine.Spy; | |
28 | const projectConstants: typeof AppConstants = AppConstants; | |
29 | ||
30 | configureTestBed( | |
31 | { | |
32 | imports: [ | |
33 | HttpClientTestingModule, | |
34 | RouterTestingModule, | |
35 | ToastrModule.forRoot(), | |
36 | SharedModule, | |
37 | CoreModule, | |
38 | CephModule | |
39 | ] | |
40 | }, | |
41 | [LoadingPanelComponent] | |
42 | ); | |
43 | ||
44 | beforeEach(() => { | |
45 | fixture = TestBed.createComponent(CreateClusterComponent); | |
46 | component = fixture.componentInstance; | |
47 | wizardStepService = TestBed.inject(WizardStepsService); | |
48 | hostService = TestBed.inject(HostService); | |
49 | osdService = TestBed.inject(OsdService); | |
50 | modalServiceShowSpy = spyOn(TestBed.inject(ModalService), 'show').and.returnValue({ | |
51 | // mock the close function, it might be called if there are async tests. | |
52 | close: jest.fn() | |
53 | }); | |
54 | fixture.detectChanges(); | |
55 | }); | |
56 | ||
57 | it('should create', () => { | |
58 | expect(component).toBeTruthy(); | |
59 | }); | |
60 | ||
61 | it('should have project name as heading in welcome screen', () => { | |
62 | const heading = fixture.debugElement.query(By.css('h3')).nativeElement; | |
63 | expect(heading.innerHTML).toBe(`Welcome to ${projectConstants.projectName}`); | |
64 | }); | |
65 | ||
66 | it('should show confirmation modal when cluster creation is skipped', () => { | |
67 | component.skipClusterCreation(); | |
68 | expect(modalServiceShowSpy.calls.any()).toBeTruthy(); | |
69 | expect(modalServiceShowSpy.calls.first().args[0]).toBe(ConfirmationModalComponent); | |
70 | }); | |
71 | ||
72 | it('should show the wizard when cluster creation is started', () => { | |
73 | component.createCluster(); | |
74 | fixture.detectChanges(); | |
75 | const nativeEl = fixture.debugElement.nativeElement; | |
76 | expect(nativeEl.querySelector('cd-wizard')).not.toBe(null); | |
77 | }); | |
78 | ||
79 | it('should have title Add Hosts', () => { | |
80 | component.createCluster(); | |
81 | fixture.detectChanges(); | |
82 | const heading = fixture.debugElement.query(By.css('.title')).nativeElement; | |
83 | expect(heading.innerHTML).toBe('Add Hosts'); | |
84 | }); | |
85 | ||
86 | it('should show the host list when cluster creation as first step', () => { | |
87 | component.createCluster(); | |
88 | fixture.detectChanges(); | |
89 | const nativeEl = fixture.debugElement.nativeElement; | |
90 | expect(nativeEl.querySelector('cd-hosts')).not.toBe(null); | |
91 | }); | |
92 | ||
93 | it('should move to next step and show the second page', () => { | |
94 | const wizardStepServiceSpy = spyOn(wizardStepService, 'moveToNextStep').and.callThrough(); | |
95 | component.createCluster(); | |
96 | fixture.detectChanges(); | |
97 | component.onNextStep(); | |
98 | fixture.detectChanges(); | |
99 | expect(wizardStepServiceSpy).toHaveBeenCalledTimes(1); | |
100 | }); | |
101 | ||
102 | it('should show the button labels correctly', () => { | |
103 | component.createCluster(); | |
104 | fixture.detectChanges(); | |
105 | let submitBtnLabel = component.showSubmitButtonLabel(); | |
106 | expect(submitBtnLabel).toEqual('Next'); | |
107 | let cancelBtnLabel = component.showCancelButtonLabel(); | |
108 | expect(cancelBtnLabel).toEqual('Cancel'); | |
109 | ||
110 | component.onNextStep(); | |
111 | fixture.detectChanges(); | |
112 | submitBtnLabel = component.showSubmitButtonLabel(); | |
113 | expect(submitBtnLabel).toEqual('Next'); | |
114 | cancelBtnLabel = component.showCancelButtonLabel(); | |
115 | expect(cancelBtnLabel).toEqual('Back'); | |
116 | ||
117 | component.onNextStep(); | |
118 | fixture.detectChanges(); | |
119 | submitBtnLabel = component.showSubmitButtonLabel(); | |
120 | expect(submitBtnLabel).toEqual('Next'); | |
121 | cancelBtnLabel = component.showCancelButtonLabel(); | |
122 | expect(cancelBtnLabel).toEqual('Back'); | |
123 | ||
124 | // Last page of the wizard | |
125 | component.onNextStep(); | |
126 | fixture.detectChanges(); | |
127 | submitBtnLabel = component.showSubmitButtonLabel(); | |
128 | expect(submitBtnLabel).toEqual('Expand Cluster'); | |
129 | cancelBtnLabel = component.showCancelButtonLabel(); | |
130 | expect(cancelBtnLabel).toEqual('Back'); | |
131 | }); | |
132 | ||
133 | it('should ensure osd creation did not happen when no devices are selected', () => { | |
2a845540 | 134 | component.simpleDeployment = false; |
a4b75251 TL |
135 | const osdServiceSpy = spyOn(osdService, 'create').and.callThrough(); |
136 | component.onSubmit(); | |
137 | fixture.detectChanges(); | |
138 | expect(osdServiceSpy).toBeCalledTimes(0); | |
139 | }); | |
140 | ||
141 | it('should ensure osd creation did happen when devices are selected', () => { | |
142 | const osdServiceSpy = spyOn(osdService, 'create').and.callThrough(); | |
143 | osdService.osdDevices['totalDevices'] = 1; | |
144 | component.onSubmit(); | |
145 | fixture.detectChanges(); | |
146 | expect(osdServiceSpy).toBeCalledTimes(1); | |
147 | }); | |
148 | ||
149 | it('should ensure host list call happened', () => { | |
150 | const hostServiceSpy = spyOn(hostService, 'list').and.callThrough(); | |
151 | component.onSubmit(); | |
152 | expect(hostServiceSpy).toHaveBeenCalledTimes(1); | |
153 | }); | |
154 | }); |