71 lines
2.7 KiB
JavaScript
71 lines
2.7 KiB
JavaScript
|
import './index.js';
|
||
|
|
||
|
describe('Item', () => {
|
||
|
describe('Component vnItemTax', () => {
|
||
|
let $componentController;
|
||
|
let $stateParams;
|
||
|
let controller;
|
||
|
let $httpBackend;
|
||
|
let vnApp;
|
||
|
|
||
|
beforeEach(() => {
|
||
|
angular.mock.module('item');
|
||
|
});
|
||
|
|
||
|
beforeEach(angular.mock.inject((_$componentController_, _$httpBackend_, _$stateParams_, _vnApp_) => {
|
||
|
$componentController = _$componentController_;
|
||
|
$stateParams = _$stateParams_;
|
||
|
$stateParams.id = 1;
|
||
|
$httpBackend = _$httpBackend_;
|
||
|
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
|
||
|
vnApp = _vnApp_;
|
||
|
spyOn(vnApp, 'showSuccess');
|
||
|
controller = $componentController('vnItemTax', {$state: $stateParams});
|
||
|
}));
|
||
|
|
||
|
describe('getTaxes()', () => {
|
||
|
it("should perform a query to set the array of taxes into the controller", () => {
|
||
|
let filter = {
|
||
|
fields: ['id', 'countryFk', 'taxClassFk'],
|
||
|
include: [{
|
||
|
relation: 'country',
|
||
|
scope: {fields: ['country']}
|
||
|
}]
|
||
|
};
|
||
|
let response = [{id: 1, taxClassFk: 1}];
|
||
|
filter = encodeURIComponent(JSON.stringify(filter));
|
||
|
$httpBackend.when('GET', `/item/api/Items/1/taxes?filter=${filter}`).respond(response);
|
||
|
$httpBackend.expect('GET', `/item/api/Items/1/taxes?filter=${filter}`);
|
||
|
controller.$onInit();
|
||
|
$httpBackend.flush();
|
||
|
|
||
|
expect(controller.taxes).toEqual(response);
|
||
|
});
|
||
|
});
|
||
|
|
||
|
describe('submit()', () => {
|
||
|
it("should perform a post to update taxes", () => {
|
||
|
let filter = {
|
||
|
fields: ['id', 'countryFk', 'taxClassFk'],
|
||
|
include: [{
|
||
|
relation: 'country',
|
||
|
scope: {fields: ['country']}
|
||
|
}]
|
||
|
};
|
||
|
let response = [{id: 1, taxClassFk: 1}];
|
||
|
filter = encodeURIComponent(JSON.stringify(filter));
|
||
|
$httpBackend.when('GET', `/item/api/Items/1/taxes?filter=${filter}`).respond(response);
|
||
|
controller.$onInit();
|
||
|
$httpBackend.flush();
|
||
|
|
||
|
$httpBackend.when('POST', `/item/api/Items/1/updateTaxes`).respond('ok');
|
||
|
$httpBackend.expect('POST', `/item/api/Items/1/updateTaxes`);
|
||
|
controller.submit();
|
||
|
$httpBackend.flush();
|
||
|
|
||
|
expect(vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
});
|