/* MMigreringsbeslut: denna test behöver Chrome headless eller PhantomJs + es6-shim för att kunna köras */ describe("fbFormMultiSelect", function () { var $scope: any; var innerScope: fb.IFbFormMultiSelectScope var compile; var naanSiffra; var commonService beforeEach(angular.mock.module('fasit', 'fbMocks')); beforeEach(inject(function ($compile, $rootScope) { $scope = $rootScope; compile = $compile; naanSiffra = 0; })); afterEach(function () { $scope.$destroy(); }); describe('funktionerna', function () { var DOM; var element: JQuery; var link; beforeEach(inject(function ($injector) { $scope.aoptions = []; $scope.amodel = []; $scope.aonAdd = function () { naanSiffra=1; }; commonService = $injector.get('commonService'); spyOn(commonService.changeTrack, 'isChangeTrackObject').and.returnValue(false); DOM = '' element = angular.element(DOM); link = compile(element)($scope); $scope.$digest(); innerScope = $scope.$$childHead; $scope.aoptions = [{ a: 1, b: 'a' }, { a: 2, b: 'a' }, { a: 3, b: 'a' }]; $scope.amodel = [$scope.aoptions[0]]; $scope.$digest(); innerScope.$digest(); $scope.$digest(); innerScope.$digest(); $scope.$digest(); innerScope.$digest(); $scope.$digest(); innerScope.$digest(); })); it('getDisplayText borde ge rätt visningstext', function () { expect(innerScope.getDisplayTextForModel(innerScope.model[0]) as any).toBe(1); }); it('remove borde ta bort ett element ur model och läggas till i pure', function () { //innerScope.$digest(); //spyOn(commonService var modellength = innerScope.model.length; var purelength = innerScope.pureOptions.length; innerScope.remove(0); innerScope.$digest(); setTimeout(function () { expect(innerScope.model.length).toBe(modellength - 1); expect(innerScope.pureOptions.length).toBe(purelength + 1); }, 1); }); describe('focusInput', function(){ it('sätter fokus vid multiselect', function () { expect(innerScope.showDroppis).toBeUndefined(); innerScope.focusInput(); expect(innerScope.showDroppis).toBe(true); }); }) // TODO: Detta test blir fel efter fix av lint-bygge //it('väljer element ur listan', function () { // var modellength = innerScope.model.length; // var purelength = innerScope.pureOptions.length; // innerScope.selected(innerScope.pureOptions[0]); // innerScope.$digest(); // setTimeout(function () { // expect(innerScope.model.length).toBe(modellength + 1); // expect(innerScope.pureOptions.length).toBe(purelength - 1); // expect(innerScope.showDroppis).toBe(true); // }, 1); // innerScope.selected(innerScope.pureOptions[0]); // innerScope.$digest(); // setTimeout(function () { // expect(innerScope.model.length).toBe(modellength + 2); // expect(innerScope.pureOptions.length).toBe(purelength - 2); // expect(innerScope.showDroppis).toBe(false); // }, 1); //}); //it('lägger till nytt element', function () { // var text = 'hej'; // var modellength = innerScope.model.length; // var purelength = innerScope.pureOptions.length; // var optionslength = innerScope.options.length; // innerScope.newItem = text; // spyOn(innerScope, 'onAdd'); // innerScope.addNewItem(); // innerScope.$digest(); // expect(innerScope.onAdd).toHaveBeenCalledWith({ input: { value: text } }); // expect(innerScope.model.length).toBe(modellength + 1); // expect(innerScope.pureOptions.length).toBe(purelength); // expect(innerScope.options.length).toBe(optionslength+1); //}); //it('glömmer droppis', function () { // innerScope.showDroppis = true; // innerScope.$digest(); // expect(innerScope.showDroppis).toBe(true); // innerScope.hideDroppis(); // innerScope.$digest(); // expect(innerScope.showDroppis).toBe(false); //}); it('suddar i tom input tar bort en i model', function () { var modellength = innerScope.model.length; var purelength = innerScope.pureOptions.length; var event = jQuery.Event('keydown'); event.keyCode = 7; element.find('.input').trigger(event); expect(innerScope.model.length).toBe(modellength); expect(innerScope.pureOptions.length).toBe(purelength); event.keyCode = 8; innerScope.newItem = 'Hej'; innerScope.$digest(); element.find('.input').trigger(event); expect(innerScope.model.length).toBe(modellength); expect(innerScope.pureOptions.length).toBe(purelength); event.keyCode = 8; innerScope.newItem = ''; innerScope.$digest(); element.find('.input').trigger(event); expect(innerScope.model.length).toBe(modellength - 1); expect(innerScope.pureOptions.length).toBe(purelength + 1); }); }); });