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;
|
|
|
|
|
2020-04-28 12:26:02 +00:00
|
|
|
const vat = 10.5;
|
|
|
|
const rows = [
|
2019-11-12 13:18:46 +00:00
|
|
|
{
|
|
|
|
quantity: 4,
|
|
|
|
price: 10.5
|
|
|
|
}, {
|
|
|
|
quantity: 3,
|
|
|
|
price: 2.4
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('order'));
|
2018-08-07 14:04:42 +00:00
|
|
|
|
2018-12-22 10:59:26 +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;
|
2020-04-28 12:26:02 +00:00
|
|
|
$httpBackend.whenGET(`OrderRows`).respond(rows);
|
|
|
|
$httpBackend.whenRoute('GET', `Orders/:id/getVAT`).respond(200, vat);
|
2019-11-12 13:18:46 +00:00
|
|
|
|
2020-04-28 12:26:02 +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
|
|
|
|
2020-04-28 12:26:02 +00:00
|
|
|
expect(controller.rows).toEqual(rows);
|
2018-08-07 14:04:42 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-08 13:21:06 +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
|
|
|
|
2020-04-28 12:26:02 +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')};
|
2019-10-24 22:53:53 +00:00
|
|
|
$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);
|
2020-04-28 12:26:02 +00:00
|
|
|
expect(controller.card.reload).toHaveBeenCalled();
|
2018-08-07 14:04:42 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|