Skip to content

Commit 4e8d66b

Browse files
[UXP-147] add tests
1 parent 37f37b6 commit 4e8d66b

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

src/app/submission/sections/external-upload/section-external-upload.component.spec.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component, NO_ERRORS_SCHEMA } from '@angular/core';
2-
import { BrowserModule } from '@angular/platform-browser';
2+
import { BrowserModule, By } from '@angular/platform-browser';
33
import { CommonModule } from '@angular/common';
44
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
55
import { ComponentFixture, inject, TestBed, waitForAsync } from '@angular/core/testing';
@@ -61,7 +61,9 @@ describe('SectionExternalUploadComponent test suite', () => {
6161
});
6262

6363
const sectionsService: any = jasmine.createSpyObj('sectionsService', {
64-
isSectionTypeAvailable: of(true)
64+
isSectionTypeAvailable: of(true),
65+
isSectionActive: of(true),
66+
setSectionStatus: () => null
6567
});
6668

6769
const submissionId = mockSubmissionId;
@@ -162,6 +164,33 @@ describe('SectionExternalUploadComponent test suite', () => {
162164

163165
expect(comp.source).toBeFalsy();
164166
});
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+
});
165194
});
166195

167196
});

0 commit comments

Comments
 (0)