mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 02:24:11 +00:00
Added tests
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { ChangeDetectorRef, CUSTOM_ELEMENTS_SCHEMA, DebugElement, SimpleChange } from '@angular/core';
|
||||
import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
|
||||
import { ChangeDetectorRef, Component, CUSTOM_ELEMENTS_SCHEMA, DebugElement, SimpleChange } from '@angular/core';
|
||||
import { async, ComponentFixture, fakeAsync, inject, TestBed, tick } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
|
||||
@@ -23,6 +23,7 @@ import { RemoteData } from '../../../core/data/remote-data';
|
||||
import { PaginatedList } from '../../../core/data/paginated-list';
|
||||
import { PageInfo } from '../../../core/shared/page-info.model';
|
||||
import { Collection } from '../../../core/shared/collection.model';
|
||||
import { createTestComponent } from '../../../shared/testing/utils';
|
||||
|
||||
const subcommunities = [Object.assign(new Community(), {
|
||||
name: 'SubCommunity 1',
|
||||
@@ -186,6 +187,7 @@ describe('SubmissionFormCollectionComponent Component', () => {
|
||||
const collectionId = '1234567890-1';
|
||||
const definition = 'traditional';
|
||||
const submissionRestResponse = mockSubmissionRestResponse;
|
||||
const searchedCollection = 'Community 2-Collection 2';
|
||||
|
||||
const communityDataService: any = jasmine.createSpyObj('communityDataService', {
|
||||
findAll: jasmine.createSpy('findAll')
|
||||
@@ -206,19 +208,52 @@ describe('SubmissionFormCollectionComponent Component', () => {
|
||||
NgbModule.forRoot(),
|
||||
TranslateModule.forRoot()
|
||||
],
|
||||
declarations: [SubmissionFormCollectionComponent],
|
||||
declarations: [
|
||||
SubmissionFormCollectionComponent,
|
||||
TestComponent
|
||||
],
|
||||
providers: [
|
||||
{ provide: SubmissionJsonPatchOperationsService, useClass: SubmissionJsonPatchOperationsServiceStub },
|
||||
{ provide: SubmissionService, useClass: SubmissionServiceStub },
|
||||
{ provide: CommunityDataService, useValue: communityDataService },
|
||||
{ provide: JsonPatchOperationsBuilder, useValue: jsonPatchOpBuilder },
|
||||
{ provide: Store, useValue: store },
|
||||
ChangeDetectorRef
|
||||
ChangeDetectorRef,
|
||||
SubmissionFormCollectionComponent
|
||||
],
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
describe('', () => {
|
||||
let testComp: TestComponent;
|
||||
let testFixture: ComponentFixture<TestComponent>;
|
||||
|
||||
// synchronous beforeEach
|
||||
beforeEach(() => {
|
||||
const html = `
|
||||
<ds-submission-form-collection [currentCollectionId]="collectionId"
|
||||
[currentDefinition]="definitionId"
|
||||
[submissionId]="submissionId"
|
||||
(collectionChange)="onCollectionChange($event)">
|
||||
</ds-submission-form-collection>`;
|
||||
|
||||
testFixture = createTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;
|
||||
testComp = testFixture.componentInstance;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
testFixture.destroy();
|
||||
});
|
||||
|
||||
it('should create SubmissionFormCollectionComponent', inject([SubmissionFormCollectionComponent], (app: SubmissionFormCollectionComponent) => {
|
||||
|
||||
expect(app).toBeDefined();
|
||||
|
||||
}));
|
||||
});
|
||||
|
||||
describe('', () => {
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(SubmissionFormCollectionComponent);
|
||||
comp = fixture.componentInstance;
|
||||
@@ -264,7 +299,7 @@ describe('SubmissionFormCollectionComponent Component', () => {
|
||||
comp.searchListCollection$ = observableOf(mockCollectionList);
|
||||
fixture.detectChanges();
|
||||
|
||||
comp.searchField.patchValue('Community 2-Collection 2');
|
||||
comp.searchField.setValue(searchedCollection);
|
||||
fixture.detectChanges();
|
||||
|
||||
comp.searchListCollection$.pipe(
|
||||
@@ -346,8 +381,45 @@ describe('SubmissionFormCollectionComponent Component', () => {
|
||||
|
||||
expect(comp.onSelect).toHaveBeenCalled();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should update searchField on input type', fakeAsync(() => {
|
||||
|
||||
dropdowBtn.triggerEventHandler('click', null);
|
||||
tick();
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
const input = fixture.debugElement.query(By.css('input.form-control'));
|
||||
const el = input.nativeElement;
|
||||
|
||||
expect(el.value).toBe('');
|
||||
|
||||
el.value = searchedCollection;
|
||||
el.dispatchEvent(new Event('input'));
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(fixture.componentInstance.searchField.value).toEqual(searchedCollection);
|
||||
});
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
// declare a test component
|
||||
@Component({
|
||||
selector: 'ds-test-cmp',
|
||||
template: ``
|
||||
})
|
||||
class TestComponent {
|
||||
|
||||
collectionId = '1234567890-1';
|
||||
definitionId = 'traditional';
|
||||
submissionId = mockSubmissionId;
|
||||
|
||||
onCollectionChange = () => { return; }
|
||||
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { ChangeDetectorRef, NO_ERRORS_SCHEMA, SimpleChange } from '@angular/core';
|
||||
import { async, ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
|
||||
import { ChangeDetectorRef, Component, CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA, SimpleChange } from '@angular/core';
|
||||
import { async, ComponentFixture, fakeAsync, inject, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
|
||||
import { of as observableOf } from 'rxjs';
|
||||
@@ -14,6 +14,7 @@ import { SubmissionService } from '../../submission.service';
|
||||
import { SubmissionRestServiceStub } from '../../../shared/testing/submission-rest-service-stub';
|
||||
import { SubmissionFormFooterComponent } from './submission-form-footer.component';
|
||||
import { SubmissionRestService } from '../../submission-rest.service';
|
||||
import { createTestComponent } from '../../../shared/testing/utils';
|
||||
|
||||
describe('SubmissionFormFooterComponent Component', () => {
|
||||
|
||||
@@ -36,18 +37,48 @@ describe('SubmissionFormFooterComponent Component', () => {
|
||||
NgbModule.forRoot(),
|
||||
TranslateModule.forRoot()
|
||||
],
|
||||
declarations: [SubmissionFormFooterComponent],
|
||||
declarations: [
|
||||
SubmissionFormFooterComponent,
|
||||
TestComponent
|
||||
],
|
||||
providers: [
|
||||
{ provide: SubmissionService, useClass: SubmissionServiceStub },
|
||||
{ provide: SubmissionRestService, useClass: SubmissionRestServiceStub },
|
||||
{ provide: Store, useValue: store },
|
||||
ChangeDetectorRef,
|
||||
NgbModal
|
||||
NgbModal,
|
||||
SubmissionFormFooterComponent
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
describe('', () => {
|
||||
let testComp: TestComponent;
|
||||
let testFixture: ComponentFixture<TestComponent>;
|
||||
|
||||
// synchronous beforeEach
|
||||
beforeEach(() => {
|
||||
const html = `
|
||||
<ds-submission-form-footer [submissionId]="submissionId"></ds-submission-form-footer>`;
|
||||
|
||||
testFixture = createTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;
|
||||
testComp = testFixture.componentInstance;
|
||||
testFixture.detectChanges();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
testFixture.destroy();
|
||||
});
|
||||
|
||||
it('should create SubmissionFormFooterComponent', inject([SubmissionFormFooterComponent], (app: SubmissionFormFooterComponent) => {
|
||||
|
||||
expect(app).toBeDefined();
|
||||
|
||||
}));
|
||||
});
|
||||
|
||||
describe('', () => {
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(SubmissionFormFooterComponent);
|
||||
comp = fixture.componentInstance;
|
||||
@@ -192,4 +223,17 @@ describe('SubmissionFormFooterComponent Component', () => {
|
||||
|
||||
expect(depositBtn.nativeElement.disabled).toBeFalsy();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
// declare a test component
|
||||
@Component({
|
||||
selector: 'ds-test-cmp',
|
||||
template: ``
|
||||
})
|
||||
class TestComponent {
|
||||
|
||||
submissionId = mockSubmissionId;
|
||||
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { ChangeDetectorRef, DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
|
||||
import { ChangeDetectorRef, Component, CUSTOM_ELEMENTS_SCHEMA, DebugElement } from '@angular/core';
|
||||
import { async, ComponentFixture, fakeAsync, inject, TestBed, tick } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
|
||||
import { of as observableOf } from 'rxjs';
|
||||
@@ -15,6 +15,7 @@ import { SectionsServiceStub } from '../../../shared/testing/sections-service-st
|
||||
import { SectionsService } from '../../sections/sections.service';
|
||||
import { HostWindowServiceStub } from '../../../shared/testing/host-window-service-stub';
|
||||
import { HostWindowService } from '../../../shared/host-window.service';
|
||||
import { createTestComponent } from '../../../shared/testing/utils';
|
||||
|
||||
const mockAvailableSections: any = [
|
||||
{
|
||||
@@ -37,7 +38,7 @@ const mockAvailableSections: any = [
|
||||
}
|
||||
];
|
||||
|
||||
describe('SubmissionFormFooterComponent Component', () => {
|
||||
describe('SubmissionFormSectionAddComponent Component', () => {
|
||||
|
||||
let comp: SubmissionFormSectionAddComponent;
|
||||
let compAsAny: any;
|
||||
@@ -61,18 +62,50 @@ describe('SubmissionFormFooterComponent Component', () => {
|
||||
NgbModule.forRoot(),
|
||||
TranslateModule.forRoot()
|
||||
],
|
||||
declarations: [SubmissionFormSectionAddComponent],
|
||||
declarations: [
|
||||
SubmissionFormSectionAddComponent,
|
||||
TestComponent
|
||||
],
|
||||
providers: [
|
||||
{ provide: HostWindowService, useValue: window },
|
||||
{ provide: SubmissionService, useClass: SubmissionServiceStub },
|
||||
{ provide: SectionsService, useClass: SectionsServiceStub },
|
||||
{ provide: Store, useValue: store },
|
||||
ChangeDetectorRef
|
||||
ChangeDetectorRef,
|
||||
SubmissionFormSectionAddComponent
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
describe('', () => {
|
||||
let testComp: TestComponent;
|
||||
let testFixture: ComponentFixture<TestComponent>;
|
||||
|
||||
// synchronous beforeEach
|
||||
beforeEach(() => {
|
||||
const html = `
|
||||
<ds-submission-form-section-add [collectionId]="collectionId"
|
||||
[submissionId]="submissionId">
|
||||
</ds-submission-form-section-add>`;
|
||||
|
||||
testFixture = createTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;
|
||||
testComp = testFixture.componentInstance;
|
||||
testFixture.detectChanges();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
testFixture.destroy();
|
||||
});
|
||||
|
||||
it('should create SubmissionFormSectionAddComponent', inject([SubmissionFormSectionAddComponent], (app: SubmissionFormSectionAddComponent) => {
|
||||
|
||||
expect(app).toBeDefined();
|
||||
|
||||
}));
|
||||
});
|
||||
|
||||
describe('', () => {
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(SubmissionFormSectionAddComponent);
|
||||
comp = fixture.componentInstance;
|
||||
@@ -163,6 +196,19 @@ describe('SubmissionFormFooterComponent Component', () => {
|
||||
});
|
||||
|
||||
}));
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
// declare a test component
|
||||
@Component({
|
||||
selector: 'ds-test-cmp',
|
||||
template: ``
|
||||
})
|
||||
class TestComponent {
|
||||
|
||||
collectionId = mockSubmissionCollectionId;
|
||||
submissionId = mockSubmissionId;
|
||||
|
||||
}
|
||||
|
@@ -30,7 +30,6 @@
|
||||
</ng-container>
|
||||
</div>
|
||||
<div *ngIf="!(isLoading() | async)" class="submission-form-footer mt-3 mb-3 position-sticky">
|
||||
<ds-submission-form-footer
|
||||
[submissionId]="submissionId"></ds-submission-form-footer>
|
||||
<ds-submission-form-footer [submissionId]="submissionId"></ds-submission-form-footer>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { ChangeDetectorRef, NO_ERRORS_SCHEMA, SimpleChange } from '@angular/core';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ChangeDetectorRef, Component, NO_ERRORS_SCHEMA, SimpleChange } from '@angular/core';
|
||||
import { async, ComponentFixture, inject, TestBed } from '@angular/core/testing';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
|
||||
import { SubmissionServiceStub } from '../../shared/testing/submission-service-stub';
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
mockSubmissionCollectionId,
|
||||
mockSubmissionDefinition,
|
||||
mockSubmissionId,
|
||||
mockSubmissionObject,
|
||||
mockSubmissionObjectNew,
|
||||
mockSubmissionSelfUrl,
|
||||
mockSubmissionState
|
||||
@@ -20,6 +19,7 @@ import { HALEndpointService } from '../../core/shared/hal-endpoint.service';
|
||||
import { AuthServiceStub } from '../../shared/testing/auth-service-stub';
|
||||
import { AuthService } from '../../core/auth/auth.service';
|
||||
import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service-stub';
|
||||
import { createTestComponent } from '../../shared/testing/utils';
|
||||
|
||||
describe('SubmissionFormComponent Component', () => {
|
||||
|
||||
@@ -41,17 +41,49 @@ describe('SubmissionFormComponent Component', () => {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [],
|
||||
declarations: [SubmissionFormComponent],
|
||||
declarations: [
|
||||
SubmissionFormComponent,
|
||||
TestComponent
|
||||
],
|
||||
providers: [
|
||||
{ provide: AuthService, useClass: AuthServiceStub },
|
||||
{ provide: HALEndpointService, useValue: new HALEndpointServiceStub('workspaceitems') },
|
||||
{ provide: SubmissionService, useClass: SubmissionServiceStub },
|
||||
ChangeDetectorRef
|
||||
ChangeDetectorRef,
|
||||
SubmissionFormComponent
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
describe('', () => {
|
||||
let testComp: TestComponent;
|
||||
let testFixture: ComponentFixture<TestComponent>;
|
||||
|
||||
// synchronous beforeEach
|
||||
beforeEach(() => {
|
||||
const html = `
|
||||
<ds-submission-submit-form [collectionId]="collectionId"
|
||||
[selfUrl]="selfUrl"
|
||||
[submissionDefinition]="submissionDefinition"
|
||||
[submissionId]="submissionId"></ds-submission-submit-form>`;
|
||||
|
||||
testFixture = createTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;
|
||||
testComp = testFixture.componentInstance;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
testFixture.destroy();
|
||||
});
|
||||
|
||||
it('should create SubmissionFormComponent', inject([SubmissionFormComponent], (app: SubmissionFormComponent) => {
|
||||
|
||||
expect(app).toBeDefined();
|
||||
|
||||
}));
|
||||
});
|
||||
|
||||
describe('', () => {
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(SubmissionFormComponent);
|
||||
comp = fixture.componentInstance;
|
||||
@@ -161,4 +193,20 @@ describe('SubmissionFormComponent Component', () => {
|
||||
expect(comp.collectionId).toEqual('45f2f3f1-ba1f-4f36-908a-3f1ea9a557eb');
|
||||
expect(submissionServiceStub.resetSubmissionObject).not.toHaveBeenCalled()
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
// declare a test component
|
||||
@Component({
|
||||
selector: 'ds-test-cmp',
|
||||
template: ``
|
||||
})
|
||||
class TestComponent {
|
||||
|
||||
collectionId = mockSubmissionCollectionId;
|
||||
selfUrl = mockSubmissionSelfUrl;
|
||||
submissionDefinition = mockSubmissionDefinition;
|
||||
submissionId = mockSubmissionId;
|
||||
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { ChangeDetectorRef, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ChangeDetectorRef, Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
||||
import { async, ComponentFixture, inject, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { TranslateModule, TranslateService } from '@ngx-translate/core';
|
||||
@@ -27,6 +27,7 @@ import { cold, hot } from 'jasmine-marbles';
|
||||
import { SubmissionJsonPatchOperationsServiceStub } from '../../../shared/testing/submission-json-patch-operations-service-stub';
|
||||
import { SubmissionJsonPatchOperationsService } from '../../../core/submission/submission-json-patch-operations.service';
|
||||
import { SharedModule } from '../../../shared/shared.module';
|
||||
import { createTestComponent } from '../../../shared/testing/utils';
|
||||
|
||||
describe('SubmissionUploadFilesComponent Component', () => {
|
||||
|
||||
@@ -54,7 +55,10 @@ describe('SubmissionUploadFilesComponent Component', () => {
|
||||
SharedModule,
|
||||
TranslateModule.forRoot()
|
||||
],
|
||||
declarations: [SubmissionUploadFilesComponent],
|
||||
declarations: [
|
||||
SubmissionUploadFilesComponent,
|
||||
TestComponent
|
||||
],
|
||||
providers: [
|
||||
{ provide: NotificationsService, useClass: NotificationsServiceStub },
|
||||
{ provide: SubmissionService, useClass: SubmissionServiceStub },
|
||||
@@ -62,12 +66,41 @@ describe('SubmissionUploadFilesComponent Component', () => {
|
||||
{ provide: TranslateService, useValue: getMockTranslateService() },
|
||||
{ provide: SubmissionJsonPatchOperationsService, useValue: submissionJsonPatchOperationsServiceStub },
|
||||
{ provide: Store, useValue: store },
|
||||
ChangeDetectorRef
|
||||
ChangeDetectorRef,
|
||||
SubmissionUploadFilesComponent
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
describe('', () => {
|
||||
let testComp: TestComponent;
|
||||
let testFixture: ComponentFixture<TestComponent>;
|
||||
|
||||
// synchronous beforeEach
|
||||
beforeEach(() => {
|
||||
const html = `
|
||||
<ds-submission-upload-files [submissionId]="submissionId"
|
||||
[collectionId]="collectionId"
|
||||
[sectionId]="'upload'"
|
||||
[uploadFilesOptions]="uploadFilesOptions"></ds-submission-upload-files>`;
|
||||
|
||||
testFixture = createTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;
|
||||
testComp = testFixture.componentInstance;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
testFixture.destroy();
|
||||
});
|
||||
|
||||
it('should create SubmissionUploadFilesComponent', inject([SubmissionUploadFilesComponent], (app: SubmissionUploadFilesComponent) => {
|
||||
|
||||
expect(app).toBeDefined();
|
||||
|
||||
}));
|
||||
});
|
||||
|
||||
describe('', () => {
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(SubmissionUploadFilesComponent);
|
||||
comp = fixture.componentInstance;
|
||||
@@ -161,4 +194,25 @@ describe('SubmissionUploadFilesComponent Component', () => {
|
||||
expect(notificationsServiceStub.success).not.toHaveBeenCalled();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
// declare a test component
|
||||
@Component({
|
||||
selector: 'ds-test-cmp',
|
||||
template: ``
|
||||
})
|
||||
class TestComponent {
|
||||
|
||||
submissionId = mockSubmissionId;
|
||||
collectionId = mockSubmissionCollectionId;
|
||||
sectionId = 'upload';
|
||||
uploadFilesOptions = {
|
||||
url: '',
|
||||
authToken: null,
|
||||
disableMultipart: false,
|
||||
itemAlias: null
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user