|
1 | 1 | import { Component, NO_ERRORS_SCHEMA } from '@angular/core'; |
2 | | -import { BrowserModule } from '@angular/platform-browser'; |
| 2 | +import { BrowserModule, By } from '@angular/platform-browser'; |
3 | 3 | import { CommonModule } from '@angular/common'; |
4 | 4 | import { FormsModule, ReactiveFormsModule } from '@angular/forms'; |
5 | 5 | import { ComponentFixture, inject, TestBed, waitForAsync } from '@angular/core/testing'; |
@@ -61,7 +61,9 @@ describe('SectionExternalUploadComponent test suite', () => { |
61 | 61 | }); |
62 | 62 |
|
63 | 63 | const sectionsService: any = jasmine.createSpyObj('sectionsService', { |
64 | | - isSectionTypeAvailable: of(true) |
| 64 | + isSectionTypeAvailable: of(true), |
| 65 | + isSectionActive: of(true), |
| 66 | + setSectionStatus: () => null |
65 | 67 | }); |
66 | 68 |
|
67 | 69 | const submissionId = mockSubmissionId; |
@@ -162,6 +164,33 @@ describe('SectionExternalUploadComponent test suite', () => { |
162 | 164 |
|
163 | 165 | expect(comp.source).toBeFalsy(); |
164 | 166 | }); |
| 167 | + |
| 168 | + it('Button should be disabled if no source', () => { |
| 169 | + comp.loading$ = of(false); |
| 170 | + |
| 171 | + comp.onSectionInit(); |
| 172 | + fixture.detectChanges(); |
| 173 | + |
| 174 | + expect(comp.source).toBeFalsy(); |
| 175 | + expect(fixture.debugElement.query(By.css('button')).nativeElement.disabled).toBeTruthy(); |
| 176 | + }); |
| 177 | + |
| 178 | + it('Should execute upload is source is present', () => { |
| 179 | + spyOn(compAsAny, 'submitUpload'); |
| 180 | + comp.loading$ = of(false); |
| 181 | + |
| 182 | + comp.onSectionInit(); |
| 183 | + comp.source = '/path/to/file'; |
| 184 | + comp.submissionId = 'subId'; |
| 185 | + |
| 186 | + fixture.detectChanges(); |
| 187 | + |
| 188 | + const button = fixture.debugElement.query(By.css('button')).nativeElement; |
| 189 | + button.click(); |
| 190 | + |
| 191 | + expect(fixture.debugElement.query(By.css('button')).nativeElement.disabled).toBeFalsy(); |
| 192 | + expect(compAsAny.submitUpload).toHaveBeenCalled(); |
| 193 | + }); |
165 | 194 | }); |
166 | 195 |
|
167 | 196 | }); |
|
0 commit comments