TSK-1349: expanded tests for import-export and removed unnecessary console.log calls
This commit is contained in:
parent
8cbbab4050
commit
06e10d8557
|
|
@ -9,13 +9,13 @@ import { WorkbasketDefinitionService } from '../../services/workbasket-definitio
|
||||||
import { NotificationService } from '../../../shared/services/notifications/notification.service';
|
import { NotificationService } from '../../../shared/services/notifications/notification.service';
|
||||||
import { UploadService } from '../../../shared/services/upload/upload.service';
|
import { UploadService } from '../../../shared/services/upload/upload.service';
|
||||||
import { ImportExportService } from '../../services/import-export.service';
|
import { ImportExportService } from '../../services/import-export.service';
|
||||||
import { HttpClient, HttpHandler } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { Router } from '@angular/router';
|
|
||||||
import { of } from 'rxjs';
|
import { of } from 'rxjs';
|
||||||
import { ClassificationDefinitionService } from '../../services/classification-definition.service';
|
import { ClassificationDefinitionService } from '../../services/classification-definition.service';
|
||||||
import { take, timeout } from 'rxjs/operators';
|
import { take } from 'rxjs/operators';
|
||||||
import { TaskanaType } from '../../../shared/models/taskana-type';
|
import { TaskanaType } from '../../../shared/models/taskana-type';
|
||||||
import { BlobGenerator } from '../../../shared/util/blob-generator';
|
import { BlobGenerator } from '../../../shared/util/blob-generator';
|
||||||
|
|
||||||
jest.mock('../../../shared/util/blob-generator');
|
jest.mock('../../../shared/util/blob-generator');
|
||||||
|
|
||||||
describe('ImportExportComponent', () => {
|
describe('ImportExportComponent', () => {
|
||||||
|
|
@ -74,6 +74,10 @@ describe('ImportExportComponent', () => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
it('should create component', () => {
|
||||||
|
expect(app).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
it('should successfully upload a valid file', () => {
|
it('should successfully upload a valid file', () => {
|
||||||
app.selectedFileInput = {
|
app.selectedFileInput = {
|
||||||
nativeElement: {
|
nativeElement: {
|
||||||
|
|
@ -92,12 +96,41 @@ describe('ImportExportComponent', () => {
|
||||||
expect(app.uploadService.isInUse).toBeTruthy();
|
expect(app.uploadService.isInUse).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should successfully export the classifications', async (done) => {
|
it('should trigger an error when uploading an invalid file format', () => {
|
||||||
|
app.selectedFileInput = {
|
||||||
|
nativeElement: {
|
||||||
|
files: [
|
||||||
|
{
|
||||||
|
lastModified: 1599117374674,
|
||||||
|
name: 'Workbaskets_2020-09-03T09_16_14.1414Z.pdf',
|
||||||
|
size: 59368,
|
||||||
|
type: 'application/pdf',
|
||||||
|
webkitRelativePath: ''
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
app.uploadFile();
|
||||||
|
expect(notificationServiceSpy).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should successfully export the workbaskets', async (done) => {
|
||||||
app
|
app
|
||||||
.export()
|
.export()
|
||||||
.pipe(take(1))
|
.pipe(take(1))
|
||||||
.subscribe(() => {
|
.subscribe(() => {
|
||||||
expect(BlobGenerator.saveFile).toHaveBeenCalled();
|
expect(BlobGenerator.saveFile).toHaveBeenCalledWith([], expect.stringMatching(/Workbaskets_.*\.json/));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should successfully export the classifications', async (done) => {
|
||||||
|
app.currentSelection = TaskanaType.CLASSIFICATIONS;
|
||||||
|
app
|
||||||
|
.export()
|
||||||
|
.pipe(take(1))
|
||||||
|
.subscribe(() => {
|
||||||
|
expect(BlobGenerator.saveFile).toHaveBeenCalledWith([], expect.stringMatching(/Classifications_.*\.json/));
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,6 @@ export class ImportExportComponent implements OnInit {
|
||||||
|
|
||||||
uploadFile() {
|
uploadFile() {
|
||||||
const file = this.selectedFileInput.nativeElement.files[0];
|
const file = this.selectedFileInput.nativeElement.files[0];
|
||||||
console.log(this.selectedFileInput);
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
if (this.checkFormatFile(file)) {
|
if (this.checkFormatFile(file)) {
|
||||||
|
|
@ -122,7 +121,6 @@ export class ImportExportComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
private errorHandler(key: NOTIFICATION_TYPES, passedError?: HttpErrorResponse) {
|
private errorHandler(key: NOTIFICATION_TYPES, passedError?: HttpErrorResponse) {
|
||||||
console.log(key, passedError);
|
|
||||||
this.errorsService.triggerError(key, passedError);
|
this.errorsService.triggerError(key, passedError);
|
||||||
delete this.selectedFileInput.files;
|
delete this.selectedFileInput.files;
|
||||||
this.resetProgress();
|
this.resetProgress();
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ export class WorkbasketDefinitionService {
|
||||||
const domainRequest = domain === '' ? domain : `?domain=${domain}`;
|
const domainRequest = domain === '' ? domain : `?domain=${domain}`;
|
||||||
const workbasketDefObservable = this.httpClient.get<WorkbasketDefinition[]>(this.url + domainRequest).pipe(take(1));
|
const workbasketDefObservable = this.httpClient.get<WorkbasketDefinition[]>(this.url + domainRequest).pipe(take(1));
|
||||||
workbasketDefObservable.subscribe((workbasketDefinitions) =>
|
workbasketDefObservable.subscribe((workbasketDefinitions) =>
|
||||||
BlobGenerator.saveFile(workbasketDefinitions, `Classifications_${TaskanaDate.getDate()}.json`)
|
BlobGenerator.saveFile(workbasketDefinitions, `Workbaskets_${TaskanaDate.getDate()}.json`)
|
||||||
);
|
);
|
||||||
return workbasketDefObservable;
|
return workbasketDefObservable;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue