2022-02-24 13:52:32 +00:00
|
|
|
import './index.js';
|
2022-03-03 13:42:12 +00:00
|
|
|
import crudModel from 'core/mocks/crud-model';
|
2022-02-24 13:52:32 +00:00
|
|
|
|
2022-03-03 13:42:12 +00:00
|
|
|
describe('AgencyTerm', () => {
|
|
|
|
describe('Component vnAgencyTermIndex', () => {
|
2022-02-24 13:52:32 +00:00
|
|
|
let controller;
|
2022-03-03 13:42:12 +00:00
|
|
|
let $window;
|
2022-02-24 13:52:32 +00:00
|
|
|
|
2022-03-03 13:42:12 +00:00
|
|
|
beforeEach(ngModule('route'));
|
2022-02-24 13:52:32 +00:00
|
|
|
|
2022-03-03 13:42:12 +00:00
|
|
|
beforeEach(inject(($componentController, _$window_) => {
|
|
|
|
$window = _$window_;
|
|
|
|
const $element = angular.element('<vn-agency-term-index></vn-agency-term-index>');
|
|
|
|
controller = $componentController('vnAgencyTermIndex', {$element});
|
|
|
|
controller.$.model = crudModel;
|
|
|
|
controller.$.model.data = [
|
|
|
|
{supplierFk: 1, totalPrice: null},
|
|
|
|
{supplierFk: 1},
|
|
|
|
{supplierFk: 2}
|
|
|
|
];
|
2022-02-24 13:52:32 +00:00
|
|
|
}));
|
|
|
|
|
2022-03-03 13:42:12 +00:00
|
|
|
describe('checked() getter', () => {
|
|
|
|
it('should return the checked lines', () => {
|
|
|
|
const data = controller.$.model.data;
|
|
|
|
data[0].checked = true;
|
|
|
|
|
|
|
|
const checkedRows = controller.checked;
|
|
|
|
|
|
|
|
const firstCheckedRow = checkedRows[0];
|
|
|
|
|
|
|
|
expect(firstCheckedRow.supplierFk).toEqual(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('totalCheked() getter', () => {
|
|
|
|
it('should return the total checked lines', () => {
|
|
|
|
const data = controller.$.model.data;
|
|
|
|
data[0].checked = true;
|
|
|
|
|
|
|
|
const checkedRows = controller.totalChecked;
|
|
|
|
|
|
|
|
expect(checkedRows).toEqual(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('preview()', () => {
|
2022-03-08 12:42:44 +00:00
|
|
|
it('should show the summary dialog', () => {
|
2022-03-03 13:42:12 +00:00
|
|
|
controller.$.summary = {show: () => {}};
|
|
|
|
jest.spyOn(controller.$.summary, 'show');
|
|
|
|
|
|
|
|
let event = new MouseEvent('click', {
|
|
|
|
view: $window,
|
|
|
|
bubbles: true,
|
|
|
|
cancelable: true
|
|
|
|
});
|
|
|
|
const route = {id: 1};
|
|
|
|
|
|
|
|
controller.preview(event, route);
|
|
|
|
|
|
|
|
expect(controller.$.summary.show).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('createInvoiceIn()', () => {
|
2022-03-08 12:42:44 +00:00
|
|
|
it('should throw an error if more than one autonomous are checked', () => {
|
2022-03-03 13:42:12 +00:00
|
|
|
jest.spyOn(controller.vnApp, 'showError');
|
|
|
|
const data = controller.$.model.data;
|
|
|
|
data[0].checked = true;
|
|
|
|
data[2].checked = true;
|
|
|
|
|
|
|
|
controller.createInvoiceIn();
|
|
|
|
|
|
|
|
expect(controller.vnApp.showError).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2022-03-08 12:42:44 +00:00
|
|
|
it('should call the function go() on $state to go to the file management', () => {
|
2022-02-24 13:52:32 +00:00
|
|
|
jest.spyOn(controller.$state, 'go');
|
2022-03-03 13:42:12 +00:00
|
|
|
const data = controller.$.model.data;
|
|
|
|
data[0].checked = true;
|
|
|
|
|
|
|
|
controller.createInvoiceIn();
|
2022-02-24 13:52:32 +00:00
|
|
|
|
2022-03-03 13:42:12 +00:00
|
|
|
delete data[0].checked;
|
|
|
|
const params = JSON.stringify({
|
|
|
|
supplierName: data[0].supplierName,
|
|
|
|
rows: [data[0]]
|
|
|
|
});
|
2022-02-24 13:52:32 +00:00
|
|
|
|
2022-03-03 13:42:12 +00:00
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('route.agencyTerm.createInvoiceIn', {q: params});
|
2022-02-24 13:52:32 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|