added front unit tests
gitea/salix/1982-travel_add_thermograph This commit looks good Details

This commit is contained in:
Joan Sanchez 2020-01-22 09:04:26 +01:00
parent 2339d347f7
commit c36e62a97b
6 changed files with 54 additions and 56 deletions

View File

@ -206,9 +206,9 @@ describe('claim', () => {
return resolve({id: freightPickUpPrice});
}));
controller.onUpdateGreugeResponse('accept').then(res => {
console.log('asdas');
}).catch(error => {
console.log('errorrrr!!');
});
$httpBackend.flush();

View File

@ -0,0 +1,23 @@
module.exports = Self => {
Self.remoteMethodCtx('allowedContentTypes', {
description: 'Returns a list of allowed contentTypes',
accessType: 'READ',
returns: {
type: ['Object'],
root: true
},
http: {
path: `/allowedContentTypes`,
verb: 'GET'
}
});
Self.allowedContentTypes = async() => {
const storageConnector = Self.app.dataSources.storage.connector;
const allowedContentTypes = storageConnector.allowedContentTypes;
const modelAllowedContentTypes = Self.definition.settings.allowedContentTypes;
return modelAllowedContentTypes || allowedContentTypes;
};
};

View File

@ -0,0 +1,4 @@
module.exports = Self => {
require('../methods/travel-thermograph/allowedContentTypes')(Self);
};

View File

@ -59,7 +59,6 @@
vn-one
label="File"
ng-model="$ctrl.dms.files"
on-change="$ctrl.onFileChange($files)"
accept="{{$ctrl.allowedContentTypes}}"
multiple="true">
<append>

View File

@ -8,10 +8,7 @@ class Controller {
this.$translate = $translate;
this.vnApp = vnApp;
this.vnConfig = vnConfig;
this.dms = {
hasFileAttached: false,
files: []
};
this.dms = {files: []};
}
get travel() {
@ -28,8 +25,7 @@ class Controller {
}
getAllowedContentTypes() {
// Replace with TravelThermographs
this.$http.get('ticketDms/allowedContentTypes').then(res => {
this.$http.get('TravelThermographs/allowedContentTypes').then(res => {
const contentTypes = res.data.join(', ');
this.allowedContentTypes = contentTypes;
});
@ -83,21 +79,9 @@ class Controller {
data: this.dms.files
};
this.$http(options).then(res => {
if (res) {
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
this.$.watcher.updateOriginalData();
this.$state.go('travel.card.thermograph.index');
}
});
}
onFileChange(files) {
let hasFileAttached = false;
if (files.length > 0)
hasFileAttached = true;
this.$.$applyAsync(() => {
this.dms.hasFileAttached = hasFileAttached;
});
}
}

View File

@ -1,37 +1,35 @@
import './index';
describe('Ticket', () => {
describe('Component vnTicketDmsCreate', () => {
describe('Component vnTravelThermographCreate', () => {
let controller;
let $scope;
let $httpBackend;
let $httpParamSerializer;
const travelId = 3;
const dmsTypeId = 5;
beforeEach(ngModule('ticket'));
beforeEach(ngModule('travel'));
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
$scope = $rootScope.$new();
$httpBackend = _$httpBackend_;
$httpParamSerializer = _$httpParamSerializer_;
controller = $componentController('vnTicketDmsCreate', {$scope});
controller._ticket = {
id: 15,
client: {id: 101, name: 'Bruce wayne'},
warehouseFk: 1,
companyFk: 1
controller = $componentController('vnTravelThermographCreate', {$scope});
controller._travel = {
id: travelId
};
}));
describe('client() setter', () => {
it('should set the ticket data and then call setDefaultParams() and getAllowedContentTypes()', () => {
describe('travel() setter', () => {
it('should set the travel data and then call setDefaultParams() and getAllowedContentTypes()', () => {
spyOn(controller, 'setDefaultParams');
spyOn(controller, 'getAllowedContentTypes');
controller.ticket = {
id: 15,
name: 'Bruce wayne'
controller.travel = {
id: travelId
};
expect(controller.ticket).toBeDefined();
expect(controller.travel).toBeDefined();
expect(controller.setDefaultParams).toHaveBeenCalledWith();
expect(controller.getAllowedContentTypes).toHaveBeenCalledWith();
});
@ -40,40 +38,30 @@ describe('Ticket', () => {
describe('setDefaultParams()', () => {
it('should perform a GET query and define the dms property on controller', () => {
const params = {filter: {
where: {code: 'ticket'}
where: {code: 'miscellaneous'}
}};
let serializedParams = $httpParamSerializer(params);
$httpBackend.when('GET', `DmsTypes/findOne?${serializedParams}`).respond({id: 14, code: 'ticket'});
$httpBackend.when('GET', `DmsTypes/findOne?${serializedParams}`).respond({id: dmsTypeId, code: 'miscellaneous'});
$httpBackend.expect('GET', `DmsTypes/findOne?${serializedParams}`);
controller.setDefaultParams();
$httpBackend.flush();
expect(controller.dms).toBeDefined();
expect(controller.dms.reference).toEqual(15);
expect(controller.dms.dmsTypeId).toEqual(14);
});
});
describe('onFileChange()', () => {
it('should set dms hasFileAttached property to true if has any files', () => {
const files = [{id: 1, name: 'MyFile'}];
controller.onFileChange(files);
$scope.$apply();
expect(controller.dms.hasFileAttached).toBeTruthy();
expect(controller.dms.reference).toEqual(travelId);
expect(controller.dms.dmsTypeId).toEqual(dmsTypeId);
});
});
describe('getAllowedContentTypes()', () => {
it('should make an HTTP GET request to get the allowed content types', () => {
const expectedResponse = ['image/png', 'image/jpg'];
$httpBackend.when('GET', `ticketDms/allowedContentTypes`).respond(expectedResponse);
$httpBackend.expect('GET', `ticketDms/allowedContentTypes`);
const expectedResponse = ['application/pdf', 'image/png', 'image/jpg'];
$httpBackend.when('GET', `TravelThermographs/allowedContentTypes`).respond(expectedResponse);
$httpBackend.expect('GET', `TravelThermographs/allowedContentTypes`);
controller.getAllowedContentTypes();
$httpBackend.flush();
expect(controller.allowedContentTypes).toBeDefined();
expect(controller.allowedContentTypes).toEqual('image/png, image/jpg');
expect(controller.allowedContentTypes).toEqual('application/pdf, image/png, image/jpg');
});
});
});