front unit tests for item card, item create and started over production index
This commit is contained in:
parent
d77faf8e47
commit
d24058bab1
|
@ -0,0 +1,33 @@
|
|||
import './item-card.js';
|
||||
|
||||
describe('Item', () => {
|
||||
describe('Component vnItemCard', () => {
|
||||
let $componentController;
|
||||
let $httpBackend;
|
||||
let $state;
|
||||
let controller;
|
||||
|
||||
beforeEach(() => {
|
||||
angular.mock.module('item');
|
||||
});
|
||||
|
||||
beforeEach(angular.mock.inject((_$componentController_, _$state_, _$httpBackend_) => {
|
||||
$componentController = _$componentController_;
|
||||
$httpBackend = _$httpBackend_;
|
||||
$state = _$state_;
|
||||
controller = $componentController('vnItemCard', {$state: $state});
|
||||
}));
|
||||
|
||||
describe('$onInit()', () => {
|
||||
it('should request to patch the propagation of tax status', () => {
|
||||
controller.client = {id: 123, isEqualizated: false};
|
||||
$httpBackend.whenGET('/item/api/Items/undefined?filter={"include":[{"relation":"itemType"},{"relation":"origin"},{"relation":"ink"},{"relation":"producer"},{"relation":"intrastat"},{"relation":"expence"},{"relation":"taxClass"},{"relation":"itemTag","scope":{"order":"priority ASC","include":{"relation":"tag"}}}]}').respond({data: 'item'});
|
||||
$httpBackend.expectGET('/item/api/Items/undefined?filter={"include":[{"relation":"itemType"},{"relation":"origin"},{"relation":"ink"},{"relation":"producer"},{"relation":"intrastat"},{"relation":"expence"},{"relation":"taxClass"},{"relation":"itemTag","scope":{"order":"priority ASC","include":{"relation":"tag"}}}]}');
|
||||
controller.$onInit();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.item).toEqual({data: 'item'});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,46 @@
|
|||
import './item-create.js';
|
||||
|
||||
describe('Item', () => {
|
||||
describe('Component vnItemCreate', () => {
|
||||
let $componentController;
|
||||
let $scope;
|
||||
let $state;
|
||||
let controller;
|
||||
|
||||
beforeEach(() => {
|
||||
angular.mock.module('item');
|
||||
});
|
||||
|
||||
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$state_) => {
|
||||
$componentController = _$componentController_;
|
||||
$scope = $rootScope.$new();
|
||||
$state = _$state_;
|
||||
$scope.watcher = {
|
||||
submit: () => {
|
||||
return {
|
||||
then: callback => {
|
||||
callback({data: {id: 1}});
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
controller = $componentController('vnItemCreate', {$scope: $scope});
|
||||
}));
|
||||
|
||||
it('should define and set scope, state and item properties', () => {
|
||||
expect(controller.$).toEqual($scope);
|
||||
expect(controller.$state).toEqual($state);
|
||||
expect(controller.item).toEqual({relevancy: 0});
|
||||
});
|
||||
|
||||
describe('onSubmit()', () => {
|
||||
it(`should call submit() on the watcher then expect a callback`, () => {
|
||||
spyOn($state, 'go');
|
||||
controller.onSubmit();
|
||||
|
||||
expect(controller.$state.go).toHaveBeenCalledWith('item.card.data', {id: 1});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -8,7 +8,7 @@ export default class ProductionIndex {
|
|||
this.$http = $http;
|
||||
this.filter = {};
|
||||
this.tickets = [];
|
||||
|
||||
|
||||
this.checkAll = 0;
|
||||
this.footer = {
|
||||
total: null,
|
||||
|
@ -35,58 +35,53 @@ export default class ProductionIndex {
|
|||
}
|
||||
|
||||
// Actions Callbacks
|
||||
_changeState(ids, sateteId, stateName, index) {
|
||||
this.$http.put(`/production/api/TicketStates/${sateteId}/changeState`, {tickets: ids}).then(
|
||||
() => {
|
||||
index.forEach(
|
||||
val => {
|
||||
this.tickets[val].state = stateName;
|
||||
this.tickets[val].stateFk = sateteId;
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
_changeState(ids, stateId, stateName, index) {
|
||||
this.$http.put(`/production/api/TicketStates/${stateId}/changeState`, {tickets: ids}).then(() => {
|
||||
index.forEach(val => {
|
||||
this.tickets[val].state = stateName;
|
||||
this.tickets[val].stateFk = stateId;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
_sendMessage(tickets) {
|
||||
this.$http.post(`/production/api/FakeProductions/messageSend`, {tickets: tickets}).then(
|
||||
() => {
|
||||
this.vnApp.showMessage(this.$translate.instant('Success: message send!'));
|
||||
}
|
||||
);
|
||||
this.$http.post(`/production/api/FakeProductions/messageSend`, {tickets: tickets}).then(() => {
|
||||
this.vnApp.showMessage(this.$translate.instant('Success: message send!'));
|
||||
});
|
||||
}
|
||||
|
||||
_changeTime(ids, time, index) {
|
||||
this.$http.put(`/production/api/Tickets/${time}/changeTime`, {tickets: ids}).then(
|
||||
() => {
|
||||
index.forEach(
|
||||
val => {
|
||||
this.tickets[val].hour = time;
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
this.$http.put(`/production/api/Tickets/${time}/changeTime`, {tickets: ids}).then(() => {
|
||||
index.forEach(val => {
|
||||
this.tickets[val].hour = time;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
searchTickets(filter) {
|
||||
this.$.index.filter.filter = Object.assign({}, this.filter, filter || {});
|
||||
this.checkAll = 0;
|
||||
this.$.index.accept().then(
|
||||
json => {
|
||||
this.tickets = json.tickets;
|
||||
this.footer.lines = json.lines;
|
||||
this.footer.meters = json.m3;
|
||||
this.footer.total = json.total;
|
||||
}
|
||||
);
|
||||
this.$.index.accept().then(json => {
|
||||
this.tickets = json.tickets;
|
||||
this.footer.lines = json.lines;
|
||||
this.footer.meters = json.m3;
|
||||
this.footer.total = json.total;
|
||||
});
|
||||
}
|
||||
|
||||
refreshTickets() {
|
||||
this.filter = {};
|
||||
this.filter.warehouseFk = this.$.displayValue = this.userProfile.warehouseId;
|
||||
}
|
||||
|
||||
onChangeWareHouse(warehouse) {
|
||||
if (warehouse && warehouse != this.filter.warehouseFk) {
|
||||
this.filter.warehouseFk = warehouse;
|
||||
this.searchTickets(this.filter);
|
||||
}
|
||||
}
|
||||
|
||||
$onInit() {
|
||||
for (let i = 1; i <= 24; i++) {
|
||||
let hour = [i].join('');
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
import './index.js';
|
||||
|
||||
describe('Production', () => {
|
||||
describe('Component vnProductionIndex', () => {
|
||||
let $componentController;
|
||||
let $httpBackend;
|
||||
let $scope;
|
||||
let controller;
|
||||
let $element;
|
||||
let aclConstant;
|
||||
|
||||
beforeEach(() => {
|
||||
angular.mock.module('production');
|
||||
});
|
||||
|
||||
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_) => {
|
||||
$element = angular.element('<div></div>');
|
||||
$componentController = _$componentController_;
|
||||
$httpBackend = _$httpBackend_;
|
||||
$scope = $rootScope.$new();
|
||||
aclConstant = {userProfile: {warehouseId: 1}};
|
||||
controller = $componentController('vnProductionIndex', {$scope: $scope, $element: $element, aclConstant: aclConstant});
|
||||
}));
|
||||
|
||||
describe('_changeState()', () => {
|
||||
it('should request to update the ticket state', () => {
|
||||
let ids = [1, 2, 3, 4];
|
||||
let stateId = 1;
|
||||
let stateName = 'the state!';
|
||||
let index = [];
|
||||
controller.tickets = ['ticketVal'];
|
||||
$httpBackend.whenPUT('/production/api/TicketStates/1/changeState', {tickets: ids}).respond({data: 'ticketVal'});
|
||||
$httpBackend.expectPUT('/production/api/TicketStates/1/changeState', {tickets: ids});
|
||||
controller._changeState(ids, stateId, stateName, index);
|
||||
$httpBackend.flush();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue