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

67 lines
2.0 KiB
JavaScript

import './index.js';
describe('Order', () => {
describe('Component vnOrderLine', () => {
let $state;
let controller;
let $httpBackend;
const vat = 10.5;
const rows = [
{
quantity: 4,
price: 10.5
}, {
quantity: 3,
price: 2.4
}
];
beforeEach(ngModule('order'));
beforeEach(inject(($componentController, _$state_, _$httpBackend_) => {
$state = _$state_;
$httpBackend = _$httpBackend_;
$state.params.id = 1;
$httpBackend.whenGET(`OrderRows`).respond(rows);
$httpBackend.whenRoute('GET', `Orders/:id/getVAT`).respond(200, vat);
controller = $componentController('vnOrderLine', {$element: null});
}));
describe('getRows()', () => {
it('should make a query to get the rows of a given order', () => {
controller.getRows();
$httpBackend.flush();
expect(controller.rows).toEqual(rows);
});
});
describe('getVAT()', () => {
it('should make a query to get the VAT of a given order', () => {
controller.getVAT();
$httpBackend.flush();
expect(controller.VAT).toBe(vat);
});
});
describe('deleteRow()', () => {
it('should remove a row from rows and add save the data if the response is accept', () => {
controller.getRows();
$httpBackend.flush();
controller.card = {reload: jasmine.createSpy('reload')};
$httpBackend.expectPOST(`OrderRows/removes`).respond();
controller.deleteRow(0);
$httpBackend.flush();
expect(controller.rows.length).toBe(1);
expect(controller.card.reload).toHaveBeenCalled();
});
});
});
});