Skip to content

Instantly share code, notes, and snippets.

@PitBeast
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save PitBeast/c3df13c26f5cfd04bafd to your computer and use it in GitHub Desktop.

Select an option

Save PitBeast/c3df13c26f5cfd04bafd to your computer and use it in GitHub Desktop.

Revisions

  1. PitBeast revised this gist Aug 18, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.txt
    Original 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 4', function() {
    it('string length greater than 3', function() {
    var element,
    fontSize = 93,
    content = '999569';
  2. PitBeast revised this gist Aug 18, 2014. 1 changed file with 107 additions and 28 deletions.
    135 changes: 107 additions & 28 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,28 +1,107 @@
    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();
    $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");
    });

    });
    //тесты для текущего(твоего) варианта директивы

    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');

    });

    });

  3. PitBeast revised this gist Aug 18, 2014. 1 changed file with 2 additions and 4 deletions.
    6 changes: 2 additions & 4 deletions gistfile1.txt
    Original 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);
    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();
    $timeout.flush()
    expect(element.html().length).toBeGreaterThan(4);
    element.css({"font-size" : 93 - 30})
    expect(element.css("font-size")).toEqual("63px");
    $timeout.flush()
    });

    });
  4. @ws-malysheva ws-malysheva created this gist Aug 18, 2014.
    30 changes: 30 additions & 0 deletions gistfile1.txt
    Original 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()
    });

    });