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;
let rows = [
{
quantity: 4,
price: 10.5
}, {
quantity: 3,
price: 2.4
}
];
beforeEach(ngModule('order'));
beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_) => {
$state = _$state_;
$httpBackend = _$httpBackend_;
$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});
}));
describe('getRows()', () => {
it('should make a query to get the rows of a given order', () => {
controller.getRows();
$httpBackend.flush();
expect(controller.rows).toBeDefined();
});
});
describe('getVAT()', () => {
it('should make a query to get the VAT of a given order', () => {
controller.getVAT();
$httpBackend.flush();
expect(controller.VAT).toBeDefined();
});
});
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).toHaveBeenCalledWith();
});
});
});
});