51 lines
1.7 KiB
JavaScript
51 lines
1.7 KiB
JavaScript
|
import './index.js';
|
||
|
import crudModel from 'core/mocks/crud-model';
|
||
|
|
||
|
describe('Component vnMonitorSalesOrders', () => {
|
||
|
let controller;
|
||
|
let $httpBackend;
|
||
|
|
||
|
beforeEach(ngModule('monitor'));
|
||
|
|
||
|
beforeEach(inject(($componentController, _$httpBackend_) => {
|
||
|
$httpBackend = _$httpBackend_;
|
||
|
const $element = angular.element('<vn-monitor-sales-orders></vn-monitor-sales-orders>');
|
||
|
controller = $componentController('vnMonitorSalesOrders', {$element});
|
||
|
controller.$.model = crudModel;
|
||
|
controller.$.model.data = [
|
||
|
{id: 1, name: 'My item 1'},
|
||
|
{id: 2, name: 'My item 2'},
|
||
|
{id: 3, name: 'My item 3'}
|
||
|
];
|
||
|
}));
|
||
|
|
||
|
describe('checked() getter', () => {
|
||
|
it('should return a the selected rows', () => {
|
||
|
const modelData = controller.$.model.data;
|
||
|
modelData[0].checked = true;
|
||
|
modelData[1].checked = true;
|
||
|
|
||
|
const result = controller.checked;
|
||
|
|
||
|
expect(result).toEqual(expect.arrayContaining([1, 2]));
|
||
|
});
|
||
|
});
|
||
|
|
||
|
describe('onDelete()', () => {
|
||
|
it('should make a query and then call to the model refresh() method', () => {
|
||
|
jest.spyOn(controller.$.model, 'refresh');
|
||
|
|
||
|
const modelData = controller.$.model.data;
|
||
|
modelData[0].checked = true;
|
||
|
modelData[1].checked = true;
|
||
|
|
||
|
const expectedParams = {deletes: [1, 2]};
|
||
|
$httpBackend.expect('POST', 'SalesMonitors/deleteOrders', expectedParams).respond(200);
|
||
|
controller.onDelete();
|
||
|
$httpBackend.flush();
|
||
|
|
||
|
expect(controller.$.model.refresh).toHaveBeenCalledWith();
|
||
|
});
|
||
|
});
|
||
|
});
|