<commit_before>/*global describe, beforeEach, module, inject, it, spyOn, expect, $, console */

describe('dfTagList', function() {
  'use strict';

  var scope, $compile;
  beforeEach(module('dataform.directives'));
  beforeEach(inject(function(_$rootScope_, _$compile_, _$window_) {
    scope = _$rootScope_.$new();
    $compile = _$compile_;
  }));

  describe('compiling this directive', function() {
    it('should throw an error if there is no items attribute', function() {
      function compile() {
        $compile('<ol df-tag-list></div>')(scope);
      }

      expect(compile).toThrow();
    });
  });
});

describe('dfTagAdd', function() {
  'use strict';

  var scope, $compile, $document;
  beforeEach(module('dataform.directives'));
  beforeEach(inject(function(_$rootScope_, _$compile_, _$window_) {
    scope = _$rootScope_.$new();
    $compile = _$compile_;
  }));

  describe('compiling this directive', function() {
    it('should construct proper DOM structure', function() {
      scope.items = ['foo'];
      scope.$digest();
      var element = $compile('<div df-tag-add></div>')(scope);
      expect(element.html()).toBe('<form><input placeholder="Tag"></form><button class="add"><i class="icon-plus"></i></button>');
    });
  });
  describe('when the tags array begins empty', function() {
    it('should show the input and hide the + button', function() {
      scope.items = [];
      var element = $compile('<div df-tag-add></div>')(scope);
      scope.$digest();
      expect(element.find('input').css('display')).toBe('');
      expect(element.find('button').css('display')).toBe('none');
    });
  });
  describe('when the tags array is emptied (but does not begin empty)', function() {
    it('should show the input and hide the + button', function() {
      scope.items = ['foo'];
      var element = $compile('<div df-tag-add></div>')(scope);
      scope.$digest();
      scope.items.pop();
      scope.$digest();
      expect(element.find('input').css('display')).toBe('');
      expect(element.find('button').css('display')).toBe('none');
    });
  });
  describe('after clicking +', function() {
    it('should hide the + button and show the input', function() {
      scope.items = ['foo'];
      var element = $compile('<div df-tag-add></div>')(scope);
      scope.$digest();
      element.find('button.add').click();
      expect(element.find('input').css('display')).toBe('');
      expect(element.find('button.add').css('display')).toBe('none');
    });
    it('de-focusing the input should clear and hide the input and show the + button (after a timeout)', function() {
      scope.items = ['foo'];
      var element = $compile('<div df-tag-add></div>')(scope);
      scope.$digest();
      element.find('button.add').click();
      element.find('input').val('bar');
      element.find('input').blur();
      expect(element.find('input').val()).toBe('');
      expect(element.find('input').is(':visible')).toBe(false);

      // TODO: This happens asynchronously now (in a $timeout), so this
      // synchronous test is failing.
      // expect(element.find('button.add').css('display')).toNotBe('none');
    });
  });
  describe('after submitting input value', function() {
    it('should append value', function() {
      scope.items = ['foo'];
      var element = $compile('<div df-tag-add></div>')(scope);
      scope.$digest();
      element.find('input').val('bar');
      element.find('form').trigger('submit');
      expect(scope.items).toEqual(['foo','bar']);
    });
  });
});

describe('dfTag', function() {
  'use strict';

  var scope, $compile;
  beforeEach(module('dataform.directives'));
  beforeEach(inject(function(_$rootScope_, _$compile_, _$window_) {
    scope = _$rootScope_.$new();
    $compile = _$compile_;
  }));

  describe('compiling this directive', function() {
    it('should throw an error if we have no $scope.items', function() {
      function compile() {
        $compile('<div df-tag>foo</div>')(scope);
      }<commit_msg>Test that input value is cleared after adding tag<commit_after>/*global describe, beforeEach, module, inject, it, spyOn, expect, $, console */

describe('dfTagList', function() {
  'use strict';

  var scope, $compile;
  beforeEach(module('dataform.directives'));
  beforeEach(inject(function(_$rootScope_, _$compile_, _$window_) {
    scope = _$rootScope_.$new();
    $compile = _$compile_;
  }));

  describe('compiling this directive', function() {
    it('should throw an error if there is no items attribute', function() {
      function compile() {
        $compile('<ol df-tag-list></div>')(scope);
      }

      expect(compile).toThrow();
    });
  });
});

describe('dfTagAdd', function() {
  'use strict';

  var scope, $compile, $document;
  beforeEach(module('dataform.directives'));
  beforeEach(inject(function(_$rootScope_, _$compile_, _$window_) {
    scope = _$rootScope_.$new();
    $compile = _$compile_;
  }));

  describe('compiling this directive', function() {
    it('should construct proper DOM structure', function() {
      scope.items = ['foo'];
      scope.$digest();
      var element = $compile('<div df-tag-add></div>')(scope);
      expect(element.html()).toBe('<form><input placeholder="Tag"></form><button class="add"><i class="icon-plus"></i></button>');
    });
  });
  describe('when the tags array begins empty', function() {
    it('should show the input and hide the + button', function() {
      scope.items = [];
      var element = $compile('<div df-tag-add></div>')(scope);
      scope.$digest();
      expect(element.find('input').css('display')).toBe('');
      expect(element.find('button').css('display')).toBe('none');
    });
  });
  describe('when the tags array is emptied (but does not begin empty)', function() {
    it('should show the input and hide the + button', function() {
      scope.items = ['foo'];
      var element = $compile('<div df-tag-add></div>')(scope);
      scope.$digest();
      scope.items.pop();
      scope.$digest();
      expect(element.find('input').css('display')).toBe('');
      expect(element.find('button').css('display')).toBe('none');
    });
  });
  describe('after clicking +', function() {
    it('should hide the + button and show the input', function() {
      scope.items = ['foo'];
      var element = $compile('<div df-tag-add></div>')(scope);
      scope.$digest();
      element.find('button.add').click();
      expect(element.find('input').css('display')).toBe('');
      expect(element.find('button.add').css('display')).toBe('none');
    });
    it('de-focusing the input should clear and hide the input and show the + button (after a timeout)', function() {
      scope.items = ['foo'];
      var element = $compile('<div df-tag-add></div>')(scope);
      scope.$digest();
      element.find('button.add').click();
      element.find('input').val('bar');
      element.find('input').blur();
      expect(element.find('input').val()).toBe('');
      expect(element.find('input').is(':visible')).toBe(false);

      // TODO: This happens asynchronously now (in a $timeout), so this
      // synchronous test is failing.
      // expect(element.find('button.add').css('display')).toNotBe('none');
    });
  });
  describe('after submitting input value', function() {
    it('should append value', function() {
      scope.items = ['foo'];
      var element = $compile('<div df-tag-add></div>')(scope);
      scope.$digest();
      element.find('input').val('bar');
      element.find('form').trigger('submit');
      expect(scope.items).toEqual(['foo','bar']);
    });
    it('should clear input value', function() {
      scope.items = [];
      var element = $compile('<div df-tag-add></div>')(scope);
      scope.$digest();
      element.find('input').val('bar');
      element.find('form').trigger('submit');
      element.find('button.add').click();
      scope.$digest();
      expect(element.find('input').val()).toBe('');
    });
  });
});

describe('dfTag', function() {
  'use strict';

  var scope, $compile;
  beforeEach(module('dataform.directives'));
  beforeEach(inject(function(_$rootScope_, _$compile_, _$window_) {
    scope = _$rootScope_.$new();
    $compile = _$compile_;
  }));

  describe('compiling this directive', function() {
    it('should throw an error if we have no $scope.items', function() {
      function compile() {
        $compile('<div df-tag>foo</div>')(scope);
      }
{'fraction_non_alphanumeric': 0.20631904026606485, 'fraction_numerical': 0.0, 'mean_word_length': 3.601092896174863, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7234182', 'n_tokens_mistral': 2493, 'n_tokens_neox': 2446, 'n_words': 534}