added front unit tests
gitea/salix/1982-travel_add_thermograph This commit looks good
Details
gitea/salix/1982-travel_add_thermograph This commit looks good
Details
This commit is contained in:
parent
2339d347f7
commit
c36e62a97b
|
@ -206,9 +206,9 @@ describe('claim', () => {
|
||||||
return resolve({id: freightPickUpPrice});
|
return resolve({id: freightPickUpPrice});
|
||||||
}));
|
}));
|
||||||
controller.onUpdateGreugeResponse('accept').then(res => {
|
controller.onUpdateGreugeResponse('accept').then(res => {
|
||||||
console.log('asdas');
|
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.log('errorrrr!!');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
|
@ -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;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
require('../methods/travel-thermograph/allowedContentTypes')(Self);
|
||||||
|
};
|
||||||
|
|
|
@ -59,7 +59,6 @@
|
||||||
vn-one
|
vn-one
|
||||||
label="File"
|
label="File"
|
||||||
ng-model="$ctrl.dms.files"
|
ng-model="$ctrl.dms.files"
|
||||||
on-change="$ctrl.onFileChange($files)"
|
|
||||||
accept="{{$ctrl.allowedContentTypes}}"
|
accept="{{$ctrl.allowedContentTypes}}"
|
||||||
multiple="true">
|
multiple="true">
|
||||||
<append>
|
<append>
|
||||||
|
|
|
@ -8,10 +8,7 @@ class Controller {
|
||||||
this.$translate = $translate;
|
this.$translate = $translate;
|
||||||
this.vnApp = vnApp;
|
this.vnApp = vnApp;
|
||||||
this.vnConfig = vnConfig;
|
this.vnConfig = vnConfig;
|
||||||
this.dms = {
|
this.dms = {files: []};
|
||||||
hasFileAttached: false,
|
|
||||||
files: []
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get travel() {
|
get travel() {
|
||||||
|
@ -28,8 +25,7 @@ class Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
getAllowedContentTypes() {
|
getAllowedContentTypes() {
|
||||||
// Replace with TravelThermographs
|
this.$http.get('TravelThermographs/allowedContentTypes').then(res => {
|
||||||
this.$http.get('ticketDms/allowedContentTypes').then(res => {
|
|
||||||
const contentTypes = res.data.join(', ');
|
const contentTypes = res.data.join(', ');
|
||||||
this.allowedContentTypes = contentTypes;
|
this.allowedContentTypes = contentTypes;
|
||||||
});
|
});
|
||||||
|
@ -83,21 +79,9 @@ class Controller {
|
||||||
data: this.dms.files
|
data: this.dms.files
|
||||||
};
|
};
|
||||||
this.$http(options).then(res => {
|
this.$http(options).then(res => {
|
||||||
if (res) {
|
|
||||||
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
||||||
this.$.watcher.updateOriginalData();
|
this.$.watcher.updateOriginalData();
|
||||||
this.$state.go('travel.card.thermograph.index');
|
this.$state.go('travel.card.thermograph.index');
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
onFileChange(files) {
|
|
||||||
let hasFileAttached = false;
|
|
||||||
if (files.length > 0)
|
|
||||||
hasFileAttached = true;
|
|
||||||
|
|
||||||
this.$.$applyAsync(() => {
|
|
||||||
this.dms.hasFileAttached = hasFileAttached;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,37 +1,35 @@
|
||||||
import './index';
|
import './index';
|
||||||
|
|
||||||
describe('Ticket', () => {
|
describe('Ticket', () => {
|
||||||
describe('Component vnTicketDmsCreate', () => {
|
describe('Component vnTravelThermographCreate', () => {
|
||||||
let controller;
|
let controller;
|
||||||
let $scope;
|
let $scope;
|
||||||
let $httpBackend;
|
let $httpBackend;
|
||||||
let $httpParamSerializer;
|
let $httpParamSerializer;
|
||||||
|
const travelId = 3;
|
||||||
|
const dmsTypeId = 5;
|
||||||
|
|
||||||
beforeEach(ngModule('ticket'));
|
beforeEach(ngModule('travel'));
|
||||||
|
|
||||||
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
|
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
|
||||||
$scope = $rootScope.$new();
|
$scope = $rootScope.$new();
|
||||||
$httpBackend = _$httpBackend_;
|
$httpBackend = _$httpBackend_;
|
||||||
$httpParamSerializer = _$httpParamSerializer_;
|
$httpParamSerializer = _$httpParamSerializer_;
|
||||||
controller = $componentController('vnTicketDmsCreate', {$scope});
|
controller = $componentController('vnTravelThermographCreate', {$scope});
|
||||||
controller._ticket = {
|
controller._travel = {
|
||||||
id: 15,
|
id: travelId
|
||||||
client: {id: 101, name: 'Bruce wayne'},
|
|
||||||
warehouseFk: 1,
|
|
||||||
companyFk: 1
|
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('client() setter', () => {
|
describe('travel() setter', () => {
|
||||||
it('should set the ticket data and then call setDefaultParams() and getAllowedContentTypes()', () => {
|
it('should set the travel data and then call setDefaultParams() and getAllowedContentTypes()', () => {
|
||||||
spyOn(controller, 'setDefaultParams');
|
spyOn(controller, 'setDefaultParams');
|
||||||
spyOn(controller, 'getAllowedContentTypes');
|
spyOn(controller, 'getAllowedContentTypes');
|
||||||
controller.ticket = {
|
controller.travel = {
|
||||||
id: 15,
|
id: travelId
|
||||||
name: 'Bruce wayne'
|
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(controller.ticket).toBeDefined();
|
expect(controller.travel).toBeDefined();
|
||||||
expect(controller.setDefaultParams).toHaveBeenCalledWith();
|
expect(controller.setDefaultParams).toHaveBeenCalledWith();
|
||||||
expect(controller.getAllowedContentTypes).toHaveBeenCalledWith();
|
expect(controller.getAllowedContentTypes).toHaveBeenCalledWith();
|
||||||
});
|
});
|
||||||
|
@ -40,40 +38,30 @@ describe('Ticket', () => {
|
||||||
describe('setDefaultParams()', () => {
|
describe('setDefaultParams()', () => {
|
||||||
it('should perform a GET query and define the dms property on controller', () => {
|
it('should perform a GET query and define the dms property on controller', () => {
|
||||||
const params = {filter: {
|
const params = {filter: {
|
||||||
where: {code: 'ticket'}
|
where: {code: 'miscellaneous'}
|
||||||
}};
|
}};
|
||||||
let serializedParams = $httpParamSerializer(params);
|
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}`);
|
$httpBackend.expect('GET', `DmsTypes/findOne?${serializedParams}`);
|
||||||
controller.setDefaultParams();
|
controller.setDefaultParams();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
expect(controller.dms).toBeDefined();
|
expect(controller.dms).toBeDefined();
|
||||||
expect(controller.dms.reference).toEqual(15);
|
expect(controller.dms.reference).toEqual(travelId);
|
||||||
expect(controller.dms.dmsTypeId).toEqual(14);
|
expect(controller.dms.dmsTypeId).toEqual(dmsTypeId);
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
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();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getAllowedContentTypes()', () => {
|
describe('getAllowedContentTypes()', () => {
|
||||||
it('should make an HTTP GET request to get the allowed content types', () => {
|
it('should make an HTTP GET request to get the allowed content types', () => {
|
||||||
const expectedResponse = ['image/png', 'image/jpg'];
|
const expectedResponse = ['application/pdf', 'image/png', 'image/jpg'];
|
||||||
$httpBackend.when('GET', `ticketDms/allowedContentTypes`).respond(expectedResponse);
|
$httpBackend.when('GET', `TravelThermographs/allowedContentTypes`).respond(expectedResponse);
|
||||||
$httpBackend.expect('GET', `ticketDms/allowedContentTypes`);
|
$httpBackend.expect('GET', `TravelThermographs/allowedContentTypes`);
|
||||||
controller.getAllowedContentTypes();
|
controller.getAllowedContentTypes();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
expect(controller.allowedContentTypes).toBeDefined();
|
expect(controller.allowedContentTypes).toBeDefined();
|
||||||
expect(controller.allowedContentTypes).toEqual('image/png, image/jpg');
|
expect(controller.allowedContentTypes).toEqual('application/pdf, image/png, image/jpg');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue