import './index.js'; import crudModel from 'core/mocks/crud-model'; describe('AgencyTerm', () => { describe('Component vnAgencyTermIndex', () => { let controller; let $window; beforeEach(ngModule('route')); beforeEach(inject(($componentController, _$window_) => { $window = _$window_; const $element = angular.element(''); controller = $componentController('vnAgencyTermIndex', {$element}); controller.$.model = crudModel; controller.$.model.data = [ {supplierFk: 1, totalPrice: null}, {supplierFk: 1}, {supplierFk: 2} ]; })); 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()', () => { it('should show the dialog summary', () => { 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()', () => { it('should throw an error if are checked more than one autonomous', () => { 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(); }); it('should call the function go() on $state to go to the file managment', () => { jest.spyOn(controller.$state, 'go'); const data = controller.$.model.data; data[0].checked = true; controller.createInvoiceIn(); delete data[0].checked; const params = JSON.stringify({ supplierName: data[0].supplierName, rows: [data[0]] }); expect(controller.$state.go).toHaveBeenCalledWith('route.agencyTerm.createInvoiceIn', {q: params}); }); }); }); });