Last active
August 29, 2015 14:05
-
-
Save PitBeast/c3df13c26f5cfd04bafd to your computer and use it in GitHub Desktop.
Revisions
-
PitBeast revised this gist
Aug 18, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,7 +26,7 @@ describe('statsHeight', function() { expect(element.css('font-size')).toEqual(fontSize+'px'); }); it('string length greater than 3', function() { var element, fontSize = 93, content = '999569'; -
PitBeast revised this gist
Aug 18, 2014 . 1 changed file with 107 additions and 28 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,28 +1,107 @@ //тесты для текущего(твоего) варианта директивы describe('statsHeight', function() { var $compile, $rootScope, $timeout; beforeEach(function () { angular.mock.module('gby.common'); }); beforeEach(inject(function (_$compile_, _$rootScope_, _$timeout_){ $compile = _$compile_; $rootScope = _$rootScope_; $timeout = _$timeout_; })); it('string length less than 4', function() { var element, fontSize = 93, content = '999'; element = $compile('<dt stats-height="'+fontSize+'" class="\'list_item_description__number\'" ng-bind="\''+content+'\'"></dt>')($rootScope); $rootScope.$digest(); $timeout.flush(); expect(element.html().length).toBeLessThan(4); expect(element.css('font-size')).toEqual(fontSize+'px'); }); it('string length greater than 4', function() { var element, fontSize = 93, content = '999569'; element = $compile('<dt stats-height="'+fontSize+'" class="\'list_item_description__number\'" ng-bind="\''+content+'\'"></dt>')($rootScope); $rootScope.$digest(); $timeout.flush(); expect(element.html().length).toBeGreaterThan(3); expect(element.css('font-size')).toEqual((fontSize-10*(content.length-1))+'px'); }); }); //мой вариант директивы(без отслеживания baseMetrics), тесты commonModule.directive('statsHeight', function ($timeout) { return { restrict: 'A', link: function (scope, element, attrs) { var collection={}; scope.$watchCollection( function() { collection.length = element.text().length; collection.fontSize = parseFloat(attrs.statsHeight); return collection; }, function (newCollection) { var newFontSize = newCollection.length < 4 ? newCollection.fontSize : newCollection.fontSize - 10 * (newCollection.length - 1); element.css({ "font-size" : newFontSize }); }); } } }); //тесты describe('statsHeight', function() { var $compile, $rootScope, $timeout; beforeEach(function () { angular.mock.module('gby.common'); }); beforeEach(inject(function (_$compile_, _$rootScope_, _$timeout_){ $compile = _$compile_; $rootScope = _$rootScope_; $timeout = _$timeout_; })); it('string length less than 4', function() { var element, fontSize = 93, content = '999'; element = $compile('<dt stats-height="'+fontSize+'" class="\'list_item_description__number\'" ng-bind="\''+content+'\'"></dt>')($rootScope); $rootScope.$digest(); expect(element.text().length).toBeLessThan(4); expect(element.css('font-size')).toEqual(fontSize+'px'); }); it('string length greater than 3', function() { var element, fontSize = 93, content = '999569'; element = $compile('<dt stats-height="'+fontSize+'" class="\'list_item_description__number\'" ng-bind="\''+content+'\'"></dt>')($rootScope); $rootScope.$digest(); expect(element.text().length).toBeGreaterThan(4); console.log((fontSize-10*(content.length-1))); expect(element.css('font-size')).toEqual((fontSize-10*(content.length-1))+'px'); }); }); -
PitBeast revised this gist
Aug 18, 2014 . 1 changed file with 2 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,19 +12,17 @@ it('string length less than 4', function() { var element = $compile('<dt stats-height="\'93\'" class="\'list_item_description__number\'" ng-bind="\'999\'"></dt>')($rootScope); $rootScope.$digest(); $timeout.flush() expect(element.html().length).toBeLessThan(4); expect(element.css("font-size")).toEqual("93px"); }); it('string length greater than 4', function() { var element = $compile('<dt stats-height="\'93\'" class="\'list_item_description__number\'" ng-bind="\'999569\'"></dt>')($rootScope); $rootScope.$digest(); $timeout.flush() expect(element.html().length).toBeGreaterThan(4); expect(element.css("font-size")).toEqual("63px"); }); }); -
ws-malysheva created this gist
Aug 18, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ describe('statsHeight', function() { var $compile, $rootScope, $timeout; beforeEach(inject(function (_$compile_, _$rootScope_, _$timeout_){ $compile = _$compile_; $rootScope = _$rootScope_; $timeout = _$timeout_; })); it('string length less than 4', function() { var element = $compile('<dt stats-height="\'93\'" class="\'list_item_description__number\'" ng-bind="\'999\'"></dt>')($rootScope); $rootScope.$digest(); expect(element.html().length).toBeLessThan(4); element.css({"font-size" : 93}) expect(element.css("font-size")).toEqual("93px"); $timeout.flush() }); it('string length greater than 4', function() { var element = $compile('<dt stats-height="\'93\'" class="\'list_item_description__number\'" ng-bind="\'999569\'"></dt>')($rootScope); $rootScope.$digest(); expect(element.html().length).toBeGreaterThan(4); element.css({"font-size" : 93 - 30}) expect(element.css("font-size")).toEqual("63px"); $timeout.flush() }); });