From 17497c3f2d75dc5f61bbf0ce629a41fdf2d5ecdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Tue, 25 Aug 2020 10:22:57 +0200 Subject: [PATCH] Added unit test --- modules/route/front/index/index.spec.js | 60 +++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 modules/route/front/index/index.spec.js diff --git a/modules/route/front/index/index.spec.js b/modules/route/front/index/index.spec.js new file mode 100644 index 000000000..8d71c91d6 --- /dev/null +++ b/modules/route/front/index/index.spec.js @@ -0,0 +1,60 @@ +import './index.js'; +import crudModel from 'core/mocks/crud-model'; + +describe('Component vnRouteIndex', () => { + let controller; + + beforeEach(ngModule('route')); + + beforeEach(inject($componentController => { + const $element = angular.element(''); + controller = $componentController('vnRouteIndex', {$element}); + controller.$.model = crudModel; + controller.$.model.data = [{id: 1}, {id: 2}, {id: 3}]; + })); + + describe('checked() getter', () => { + it('should should return the checked lines', () => { + const data = controller.$.model.data; + data[0].checked = true; + data[2].checked = true; + + const checkedRows = controller.checked; + + const firstCheckedRow = checkedRows[0]; + const secondCheckedRow = checkedRows[1]; + + expect(firstCheckedRow.id).toEqual(1); + expect(secondCheckedRow.id).toEqual(3); + }); + }); + + describe('totalCheked() getter', () => { + it('should should return the total checked lines', () => { + const data = controller.$.model.data; + data[0].checked = true; + + const checkedRows = controller.totalChecked; + + expect(checkedRows).toEqual(1); + }); + }); + + describe('showRouteReport()', () => { + it('should call to the vnReport show method', () => { + controller.vnReport.show = jest.fn(); + + const data = controller.$.model.data; + data[0].checked = true; + data[2].checked = true; + const expectedParams = { + authorization: null, + routeId: '1,3' + }; + + controller.showRouteReport(); + + expect(controller.vnReport.show).toHaveBeenCalledWith('driver-route', expectedParams); + }); + }); +});