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

67 lines
2.0 KiB
JavaScript
Raw Permalink 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;
const vat = 10.5;
const rows = [
2019-11-12 13:18:46 +00:00
{
quantity: 4,
price: 10.5
}, {
quantity: 3,
price: 2.4
}
];
beforeEach(ngModule('order'));
2018-08-07 14:04:42 +00:00
2020-07-23 14:46:16 +00:00
beforeEach(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.whenGET(`OrderRows`).respond(rows);
$httpBackend.whenRoute('GET', `Orders/:id/getVAT`).respond(200, vat);
2019-11-12 13:18:46 +00:00
controller = $componentController('vnOrderLine', {$element: null});
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).toEqual(rows);
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).toBe(vat);
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);
expect(controller.card.reload).toHaveBeenCalled();
2018-08-07 14:04:42 +00:00
});
});
});
});