salix/modules/order/front/line/index.spec.js

67 lines
2.0 KiB
JavaScript
Raw Normal View History

2018-08-07 14:04:42 +00:00
import './index.js';
2019-04-05 05:52:08 +00:00
describe('Order', () => {
2018-08-07 14:04:42 +00:00
describe('Component vnOrderLine', () => {
let $state;
let controller;
let $httpBackend;
2019-11-12 13:18:46 +00:00
let rows = [
{
quantity: 4,
price: 10.5
}, {
quantity: 3,
price: 2.4
}
];
beforeEach(ngModule('order'));
2018-08-07 14:04:42 +00:00
beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_) => {
2018-08-07 14:04:42 +00:00
$state = _$state_;
$httpBackend = _$httpBackend_;
2019-11-12 13:18:46 +00:00
$state.params.id = 1;
$httpBackend.whenRoute('GET', `OrderRows`).respond(rows);
$httpBackend.whenRoute('GET', `Orders/:id/getVAT`).respond(200, 10.5);
let $element = angular.element('<div></div>');
controller = $componentController('vnOrderLine', {$element});
2018-08-07 14:04:42 +00:00
}));
describe('getRows()', () => {
it('should make a query to get the rows of a given order', () => {
controller.getRows();
$httpBackend.flush();
2019-11-12 13:18:46 +00:00
expect(controller.rows).toBeDefined();
2018-08-07 14:04:42 +00:00
});
});
describe('getVAT()', () => {
it('should make a query to get the VAT of a given order', () => {
2018-08-07 14:04:42 +00:00
controller.getVAT();
$httpBackend.flush();
2019-11-12 13:18:46 +00:00
expect(controller.VAT).toBeDefined();
2018-08-07 14:04:42 +00:00
});
});
2019-01-14 13:59:14 +00:00
describe('deleteRow()', () => {
2019-10-30 15:57:14 +00:00
it('should remove a row from rows and add save the data if the response is accept', () => {
2019-11-12 13:18:46 +00:00
controller.getRows();
$httpBackend.flush();
2019-01-14 13:59:14 +00:00
2019-11-12 13:18:46 +00:00
controller.card = {reload: jasmine.createSpy('reload')};
$httpBackend.expectPOST(`OrderRows/removes`).respond();
2019-11-12 13:18:46 +00:00
controller.deleteRow(0);
2019-01-14 13:59:14 +00:00
$httpBackend.flush();
2018-08-07 14:04:42 +00:00
2019-11-12 13:18:46 +00:00
expect(controller.rows.length).toBe(1);
2019-04-05 05:52:08 +00:00
expect(controller.card.reload).toHaveBeenCalledWith();
2018-08-07 14:04:42 +00:00
});
});
});
});