TSK-1349: expanded tests for import-export and removed unnecessary console.log calls

This commit is contained in:
Tristan Eisermann 2020-10-05 18:36:40 +02:00 committed by Tristan2357
parent 8cbbab4050
commit 06e10d8557
3 changed files with 39 additions and 8 deletions

View File

@ -9,13 +9,13 @@ import { WorkbasketDefinitionService } from '../../services/workbasket-definitio
import { NotificationService } from '../../../shared/services/notifications/notification.service';
import { UploadService } from '../../../shared/services/upload/upload.service';
import { ImportExportService } from '../../services/import-export.service';
import { HttpClient, HttpHandler } from '@angular/common/http';
import { Router } from '@angular/router';
import { HttpClient } from '@angular/common/http';
import { of } from 'rxjs';
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 { BlobGenerator } from '../../../shared/util/blob-generator';
jest.mock('../../../shared/util/blob-generator');
describe('ImportExportComponent', () => {
@ -74,6 +74,10 @@ describe('ImportExportComponent', () => {
fixture.detectChanges();
}));
it('should create component', () => {
expect(app).toBeTruthy();
});
it('should successfully upload a valid file', () => {
app.selectedFileInput = {
nativeElement: {
@ -92,12 +96,41 @@ describe('ImportExportComponent', () => {
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
.export()
.pipe(take(1))
.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();
});
});

View File

@ -53,7 +53,6 @@ export class ImportExportComponent implements OnInit {
uploadFile() {
const file = this.selectedFileInput.nativeElement.files[0];
console.log(this.selectedFileInput);
const formData = new FormData();
const xhr = new XMLHttpRequest();
if (this.checkFormatFile(file)) {
@ -122,7 +121,6 @@ export class ImportExportComponent implements OnInit {
}
private errorHandler(key: NOTIFICATION_TYPES, passedError?: HttpErrorResponse) {
console.log(key, passedError);
this.errorsService.triggerError(key, passedError);
delete this.selectedFileInput.files;
this.resetProgress();

View File

@ -18,7 +18,7 @@ export class WorkbasketDefinitionService {
const domainRequest = domain === '' ? domain : `?domain=${domain}`;
const workbasketDefObservable = this.httpClient.get<WorkbasketDefinition[]>(this.url + domainRequest).pipe(take(1));
workbasketDefObservable.subscribe((workbasketDefinitions) =>
BlobGenerator.saveFile(workbasketDefinitions, `Classifications_${TaskanaDate.getDate()}.json`)
BlobGenerator.saveFile(workbasketDefinitions, `Workbaskets_${TaskanaDate.getDate()}.json`)
);
return workbasketDefObservable;
}