2020-02-05 12:37:36 +00:00
|
|
|
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(`<div></div>`);
|
|
|
|
$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;
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller, 'getCard');
|
2020-02-05 12:37:36 +00:00
|
|
|
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;
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller, 'getCard');
|
2020-02-05 12:37:36 +00:00
|
|
|
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()`, () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.$.popover, 'relocate');
|
2020-02-05 12:37:36 +00:00
|
|
|
let route = `i'm the route!`;
|
|
|
|
controller.route = route;
|
|
|
|
$timeout.flush();
|
|
|
|
|
|
|
|
expect(controller.route).toEqual(route);
|
|
|
|
expect(controller.$.popover.relocate).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('show()', () => {
|
2020-02-06 06:39:00 +00:00
|
|
|
it(`should call the popover show() method`, () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.$.popover, 'show');
|
2020-02-05 12:37:36 +00:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|