diff --git a/modules/route/front/descriptor-popover/index.js b/modules/route/front/descriptor-popover/index.js index 2458a94ac..7d5cd3d91 100644 --- a/modules/route/front/descriptor-popover/index.js +++ b/modules/route/front/descriptor-popover/index.js @@ -54,7 +54,7 @@ class Controller extends Component { this.canceler = this.$q.defer(); - let query = `Routes/findOne`; + let query = 'Routes/findOne'; let filter = { fields: [ diff --git a/modules/route/front/descriptor-popover/index.spec.js b/modules/route/front/descriptor-popover/index.spec.js new file mode 100644 index 000000000..d8e21c730 --- /dev/null +++ b/modules/route/front/descriptor-popover/index.spec.js @@ -0,0 +1,77 @@ +import './index'; + +describe('vnRouteDescriptorPopover', () => { + let $httpBackend; + let $scope; + let controller; + let $element; + let $timeout; + + beforeEach(ngModule('route')); + + beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$timeout_) => { + $httpBackend = _$httpBackend_; + $timeout = _$timeout_; + $element = angular.element(`
`); + $scope = $rootScope.$new(); + $scope.popover = {relocate: () => {}, show: () => {}}; + controller = $componentController('vnRouteDescriptorPopover', {$scope, $element}); + })); + + describe('routeFk()', () => { + it(`should do nothing if the received id isn't a new one`, () => { + controller.route = 'I exist!'; + controller._routeFk = 1; + spyOn(controller, 'getCard'); + controller.routeFk = 1; + + expect(controller.route).toEqual('I exist!'); + expect(controller._routeFk).toEqual(1); + expect(controller.getCard).not.toHaveBeenCalled(); + }); + + it(`should set the received id, set the route null and then call getCard()`, () => { + controller.route = `Please don't`; + controller._routeFk = 1; + spyOn(controller, 'getCard'); + controller.routeFk = 999; + + expect(controller.route).toBeNull(); + expect(controller._routeFk).toEqual(999); + expect(controller.getCard).toHaveBeenCalledWith(); + }); + }); + + describe('route()', () => { + it(`should save the client on the controller and then call relocate()`, () => { + spyOn(controller.$.popover, 'relocate'); + let route = `i'm the route!`; + controller.route = route; + $timeout.flush(); + + expect(controller.route).toEqual(route); + expect(controller.$.popover.relocate).toHaveBeenCalledWith(); + }); + }); + + describe('show()', () => { + it(`should call the popover show() mothod`, () => { + spyOn(controller.$.popover, 'show'); + controller.show(); + + expect(controller.$.popover.show).toHaveBeenCalledWith(); + }); + }); + + describe('getCard()', () => { + it(`should perform a get query to store the client data into the controller`, () => { + let response = {the: 'route'}; + + $httpBackend.whenRoute('GET', 'Routes/findOne').respond(response); + controller.routeFk = 1; + $httpBackend.flush(); + + expect(controller.route).toEqual(response); + }); + }); +});