mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-11 03:53:02 +00:00
96252: Extract upload-specific code from SharedModule
This commit is contained in:
88
src/app/shared/upload/uploader/uploader.component.spec.ts
Normal file
88
src/app/shared/upload/uploader/uploader.component.spec.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
// Load the implementations that should be tested
|
||||
import { ChangeDetectorRef, Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
||||
import { ComponentFixture, inject, TestBed, waitForAsync, } from '@angular/core/testing';
|
||||
|
||||
import { ScrollToService } from '@nicky-lenaers/ngx-scroll-to';
|
||||
|
||||
import { DragService } from '../../../core/drag.service';
|
||||
import { UploaderOptions } from './uploader-options.model';
|
||||
import { UploaderComponent } from './uploader.component';
|
||||
import { FileUploadModule } from 'ng2-file-upload';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { createTestComponent } from '../../testing/utils.test';
|
||||
import { HttpXsrfTokenExtractor } from '@angular/common/http';
|
||||
import { CookieService } from '../../../core/services/cookie.service';
|
||||
import { CookieServiceMock } from '../../mocks/cookie.service.mock';
|
||||
import { HttpXsrfTokenExtractorMock } from '../../mocks/http-xsrf-token-extractor.mock';
|
||||
|
||||
describe('Chips component', () => {
|
||||
|
||||
let testComp: TestComponent;
|
||||
let testFixture: ComponentFixture<TestComponent>;
|
||||
let html;
|
||||
|
||||
// waitForAsync beforeEach
|
||||
beforeEach(waitForAsync(() => {
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
FileUploadModule,
|
||||
TranslateModule.forRoot()
|
||||
],
|
||||
declarations: [
|
||||
UploaderComponent,
|
||||
TestComponent,
|
||||
], // declare the test component
|
||||
providers: [
|
||||
ChangeDetectorRef,
|
||||
ScrollToService,
|
||||
UploaderComponent,
|
||||
DragService,
|
||||
{ provide: HttpXsrfTokenExtractor, useValue: new HttpXsrfTokenExtractorMock('mock-token') },
|
||||
{ provide: CookieService, useValue: new CookieServiceMock() },
|
||||
],
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||
});
|
||||
|
||||
}));
|
||||
|
||||
// synchronous beforeEach
|
||||
beforeEach(() => {
|
||||
html = `
|
||||
<ds-uploader [onBeforeUpload]="onBeforeUpload"
|
||||
[uploadFilesOptions]="uploadFilesOptions"
|
||||
(onCompleteItem)="onCompleteItem($event)"></ds-uploader>`;
|
||||
|
||||
testFixture = createTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;
|
||||
testComp = testFixture.componentInstance;
|
||||
});
|
||||
|
||||
it('should create Uploader Component', inject([UploaderComponent], (app: UploaderComponent) => {
|
||||
|
||||
expect(app).toBeDefined();
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
// declare a test component
|
||||
@Component({
|
||||
selector: 'ds-test-cmp',
|
||||
template: ``
|
||||
})
|
||||
class TestComponent {
|
||||
public uploadFilesOptions: UploaderOptions = Object.assign(new UploaderOptions(), {
|
||||
url: 'http://test',
|
||||
authToken: null,
|
||||
disableMultipart: false,
|
||||
itemAlias: null
|
||||
});
|
||||
|
||||
/* eslint-disable no-empty,@typescript-eslint/no-empty-function */
|
||||
public onBeforeUpload = () => {
|
||||
};
|
||||
|
||||
onCompleteItem(event) {
|
||||
}
|
||||
|
||||
/* eslint-enable no-empty, @typescript-eslint/no-empty-function */
|
||||
}
|
Reference in New Issue
Block a user