/* MMigreringsbeslut: denna test behöver Chrome headless eller PhantomJs + es6-shim för att kunna köras */ describe('KonstantIntressentCtrl', function () { var KonstantIntressentCtrl; var $scope: fb.IKonstantIntressentCtrlScope; var $routeParams: any; var sideDrawerService: fb.IMockSideDrawerService; var domainService: fb.IMockDomainService; var intressentService: fb.IMockIntressentService; var parterService: fb.IMockParterService; var exportService: fb.IMockExportService; var visningService: fb.IMockVisningService; beforeEach(function () { angular.mock.module('fasit', 'fbMocks'); inject(function ($controller: ng.IControllerService, $rootScope: fb.IRootScope, $injector) { $scope = $rootScope.$new(); $routeParams = { id: 123456, maeklarObjektId: 7357 }; sideDrawerService = $injector.get('sideDrawerService'); domainService = $injector.get('domainService'); intressentService = $injector.get('intressentService'); parterService = $injector.get('parterService'); exportService = $injector.get('exportService'); visningService = $injector.get('visningServiceMock'); KonstantIntressentCtrl = $controller('KonstantIntressentCtrl', { $scope: $scope, $routeParams: $routeParams, $q: $injector.get('$q'), $timeout: $injector.get('$timeout'), sideDrawerService: sideDrawerService, intressentService: intressentService, parterService: parterService, visningService: visningService, exportService: exportService, domainService: domainService }); }); }); describe('funktionen openSideDrawer', function () { it('borde anropa sideDrawerService.setSideDrawer', inject(function () { spyOn(sideDrawerService, 'setSideDrawer'); $scope.openSideDrawer(); expect(sideDrawerService.setSideDrawer).toHaveBeenCalled(); })); //it('borde sätt nyIntressent till true och skicka med ifall ingen intressent är vald', inject(function () { // spyOn(sideDrawerService, 'setSideDrawer'); // $scope.openSideDrawer(); // var sds: any = sideDrawerService; // expect(sds.setSideDrawer).toHaveBeenCalled(); // expect(sds.setSideDrawer.calls.mostRecent().args[0]).toBe('Intressent'); // expect(sds.setSideDrawer.calls.mostRecent().args[1].nyIntressent).toBe(true); //})); }); describe('Vid initiering av intressenter', function () { it('borde skapa en array med wrapper-objekt för alla intressenter', inject(function (getIntressent, getParter, getVisningar) { intressentService.resolve(fb.RequestType.GET, '123456', getIntressent); parterService.resolve(fb.RequestType.GET, '123456', getParter); visningService.resolve(fb.RequestType.QUERY, '123456', []); $scope.$digest(); expect($scope.primarKontakter.length).toBe(7); expect($scope.primarKontakter[0].Intressent.PersonId.value).toBe($scope.intressenter[0].PersonId.value); //if ($scope.primarKontakter[3].Intressent instanceof fb.Objektintressent && $scope.intressenter[3] instanceof fb.Objektintressent) { // expect($scope.primarKontakter[3].Intressent.Bud[3].Bud.value).toBe($scope.intressenter[3].Bud[3].Bud.value); //} expect($scope.primarKontakter[1].Intressent.Visningar[1].AktivitetStart.value).toBe($scope.intressenter[1].Visningar[1].AktivitetStart.value); expect($scope.primarKontakter[0].Intressent.TelefonnummerMobil.Telefonnummer.value).toBe($scope.intressenter[0].TelefonnummerMobil.Telefonnummer.value); })); it('borde skapa en lista med alla unika visningar ', inject(function (getIntressent, getParter, getVisningar) { intressentService.resolve(fb.RequestType.GET, '123456', getIntressent); parterService.resolve(fb.RequestType.GET, '123456', getParter); visningService.resolve(fb.RequestType.QUERY, '123456', getVisningar); $scope.$digest(); expect($scope.allaVisningar['2014-10-29T14:00:00']).not.toBeUndefined(); expect($scope.allaVisningar['2014-10-30T09:00:00']).not.toBeUndefined(); expect($scope.allaVisningar['2014-10-31T09:00:00']).not.toBeUndefined(); expect($scope.allaVisningar['2014-11-03T09:00:00']).not.toBeUndefined(); expect($scope.allaVisningar['2014-11-08T13:00:00']).not.toBeUndefined(); expect(Object.keys($scope.allaVisningar).length).toBe(5); })); }); describe('funktionen intressentFilter', function () { it('borde filtrera bort intressenter som inte har given status', inject(function (getIntressent, getParter, getVisningar) { intressentService.resolve(fb.RequestType.GET, '123456', getIntressent); parterService.resolve(fb.RequestType.GET, '123456', getParter); visningService.resolve(fb.RequestType.QUERY, '123456', getVisningar); $scope.$digest(); var testIntressent = $scope.primarKontakter[1]; expect($scope.intressentFilter(testIntressent)).toBeTruthy(); $scope.filter.status = ({ Intressegrad: $scope.primarKontakter[1].Intressent.Intressegrad.value, IntressegradNamn: 'Testgrad' }); expect($scope.intressentFilter(testIntressent)).toBeTruthy(); $scope.filter.status = ({ Intressegrad: 987654321, IntressegradNamn: 'Testgrad' }); expect($scope.intressentFilter(testIntressent)).toBeFalsy(); })); it('borde filtrera bort intressenter som inte varit på vald visning', inject(function (getIntressent, getParter, getVisningar) { intressentService.resolve(fb.RequestType.GET, '123456', getIntressent); parterService.resolve(fb.RequestType.GET, '123456', getParter); visningService.resolve(fb.RequestType.QUERY, '123456', getVisningar); $scope.$digest(); var testIntressent = $scope.primarKontakter[1]; expect($scope.intressentFilter(testIntressent)).toBeTruthy(); $scope.filter.visning = $scope.allaVisningar['2014-10-29T14:00:00']; expect($scope.intressentFilter(testIntressent)).toBeTruthy(); $scope.filter.visning = $scope.allaVisningar['2014-10-30T09:00:00']; expect($scope.intressentFilter(testIntressent)).toBeTruthy(); $scope.filter.visning = $scope.allaVisningar['2014-10-31T09:00:00']; expect($scope.intressentFilter(testIntressent)).toBeFalsy(); })); }); });