Updated unit test
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
a87ebba4ab
commit
e3a192bcea
|
@ -143,14 +143,13 @@ export default class UploadPhoto extends Component {
|
|||
height: output.height
|
||||
}
|
||||
};
|
||||
this.editor.result(options)
|
||||
return this.editor.result(options)
|
||||
.then(blob => this.newPhoto.blob = blob)
|
||||
.then(() => this.makeRequest());
|
||||
} catch (e) {
|
||||
this.vnApp.showError(this.$t(e.message));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -171,7 +170,9 @@ export default class UploadPhoto extends Component {
|
|||
const formData = new FormData();
|
||||
const now = new Date();
|
||||
const timestamp = now.getTime();
|
||||
formData.append('blob', this.newPhoto.blob, file.name + '_' + timestamp);
|
||||
const fileName = `${file.name}_${timestamp}`;
|
||||
|
||||
formData.append('blob', this.newPhoto.blob, fileName);
|
||||
|
||||
return formData;
|
||||
},
|
||||
|
|
|
@ -6,7 +6,9 @@ describe('Salix', () => {
|
|||
let $scope;
|
||||
let $httpBackend;
|
||||
|
||||
beforeEach(ngModule('salix'));
|
||||
beforeEach(ngModule('salix', $translateProvider => {
|
||||
$translateProvider.translations('en', {});
|
||||
}));
|
||||
|
||||
beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => {
|
||||
$scope = $rootScope.$new();
|
||||
|
@ -14,12 +16,58 @@ describe('Salix', () => {
|
|||
const $element = angular.element('<vn-upload-photo></vn-upload-photo>');
|
||||
controller = $componentController('vnUploadPhoto', {$element, $scope});
|
||||
controller.newPhoto = {};
|
||||
controller.$t = m => m;
|
||||
}));
|
||||
|
||||
afterEach(() => {
|
||||
$scope.$destroy();
|
||||
});
|
||||
|
||||
describe('viewportSelection()', () => {
|
||||
it('should call to displayEditor() and updatePhotoPreview() methods', () => {
|
||||
controller.displayEditor = jest.fn();
|
||||
controller.updatePhotoPreview = jest.fn();
|
||||
|
||||
const files = [{name: 'test.jpg'}];
|
||||
controller.newPhoto.files = files;
|
||||
|
||||
controller.viewportSelection = {code: 'normal'};
|
||||
|
||||
expect(controller.displayEditor).toHaveBeenCalledWith();
|
||||
expect(controller.updatePhotoPreview).toHaveBeenCalledWith(files);
|
||||
});
|
||||
});
|
||||
|
||||
describe('displayEditor()', () => {
|
||||
it('should define the editor property', () => {
|
||||
controller.viewportSelection = {
|
||||
code: 'normal',
|
||||
description: 'Normal',
|
||||
viewport: {
|
||||
width: 400,
|
||||
height: 400
|
||||
},
|
||||
output: {
|
||||
width: 1200,
|
||||
height: 1200
|
||||
}
|
||||
};
|
||||
const element = document.createElement('div');
|
||||
|
||||
jest.spyOn(document, 'getElementById').mockReturnValue(element);
|
||||
|
||||
controller.displayEditor();
|
||||
|
||||
const editor = controller.editor;
|
||||
|
||||
expect(editor).toBeDefined();
|
||||
expect(editor.options.viewport.width).toEqual(400);
|
||||
expect(editor.options.viewport.width).toEqual(400);
|
||||
expect(editor.options.boundary.width).toEqual(600);
|
||||
expect(editor.options.boundary.height).toEqual(600);
|
||||
});
|
||||
});
|
||||
|
||||
describe('onUploadAccept()', () => {
|
||||
it('should throw an error message containing "Select an image"', () => {
|
||||
jest.spyOn(controller.vnApp, 'showError');
|
||||
|
@ -29,13 +77,33 @@ describe('Salix', () => {
|
|||
expect(controller.vnApp.showError).toHaveBeenCalledWith('Select an image');
|
||||
});
|
||||
|
||||
it('should call to the makeRequest() method', () => {
|
||||
it('should call to the makeRequest() method', done => {
|
||||
controller.editor = {
|
||||
result: () => {}
|
||||
};
|
||||
|
||||
jest.spyOn(controller, 'makeRequest');
|
||||
jest.spyOn(controller.editor, 'result').mockReturnValue(new Promise(resolve => resolve('blobFile')));
|
||||
|
||||
controller.viewportSelection = {
|
||||
code: 'normal',
|
||||
description: 'Normal',
|
||||
viewport: {
|
||||
width: 400,
|
||||
height: 400
|
||||
},
|
||||
output: {
|
||||
width: 1200,
|
||||
height: 1200
|
||||
}
|
||||
};
|
||||
|
||||
controller.newPhoto.files = [0];
|
||||
controller.onUploadAccept();
|
||||
|
||||
expect(controller.makeRequest).toHaveBeenCalledWith();
|
||||
controller.onUploadAccept().then(() => {
|
||||
expect(controller.newPhoto.blob).toEqual('blobFile');
|
||||
expect(controller.makeRequest).toHaveBeenCalledWith();
|
||||
done();
|
||||
}).catch(done.fail);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -44,7 +112,11 @@ describe('Salix', () => {
|
|||
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||
jest.spyOn(controller, 'emit');
|
||||
|
||||
$httpBackend.expectGET('ImageContainers/allowedContentTypes').respond(200, ['image/jpg']);
|
||||
|
||||
controller.newPhoto.files = [{name: 'hola'}];
|
||||
controller.newPhoto.blob = new Blob([]);
|
||||
|
||||
$httpBackend.expectRoute('POST', 'Images/upload').respond(200);
|
||||
controller.makeRequest();
|
||||
$httpBackend.flush();
|
||||
|
|
Loading…
Reference in New Issue