<commit_before>'use strict';

describe('ngMarkdown Directive', function () {

  var $scope,
      timeout,
      elem,
      template;

  beforeEach(module('ngMarkdown'));

  beforeEach(inject(function ($rootScope, $compile, $document, $timeout) {
    $scope = $rootScope;
    timeout = $timeout;

    var template = angular.element([
      '<content>',
        '<div class="wmd-button-bar"></div>',
        '<ng-markdown ng-model="bind"></ng-markdown>',
        '<div class="wmd-preview">initialize</div>',
      '</content>'
    ].join(''));

    var body = angular.element($document[0].body);
    body.append(template);

    elem = $compile(template)($scope);

    body.append(elem);
    $scope.$digest();
  }));

  afterEach(inject(function ($document) {
    clearContent();
  }));

  function getPreview () {
    return document.querySelector('.wmd-preview');
  }

  function clearContent () {
    var content = document.querySelector('content');
    content.parentNode.removeChild(content);
  }

  function newValue (value) {
    $scope.bind = value;
    timeout.flush();
  }

  function checkPreview (value) {
    expect(getPreview().innerHTML).toBe(value);
  }

  it('should equal 42', function () {
    newValue(42);
    expect(42).toBe(42);
    checkPreview('<p>42</p>');
  });

  it('should attach buttons to the toolbar', function () {
    expect(document.querySelectorAll('.wmd-button-bar div i').length).toBe(15);
  });

  it('should be italic', function () {
    newValue('*italic*');<commit_msg>test(unit): begin of possibility to change template<commit_after>'use strict';

describe('ngMarkdown Directive', function () {

  var $scope,
      $timeout,
      $document,
      $compile,
      elem;

  var defTemplate = [
    '<content>',
      '<div class="wmd-button-bar"></div>',
      '<ng-markdown ng-model="bind"></ng-markdown>',
      '<div class="wmd-preview">initialize</div>',
    '</content>'
  ].join('');

  beforeEach(module('ngMarkdown'));

  beforeEach(inject(function (_$rootScope_, _$timeout_, _$compile_, _$document_) {
    $scope = _$rootScope_;
    $document = _$document_;
    $timeout = _$timeout_;
    $compile = _$compile_;

    var template = angular.element(defTemplate);
    angular.element($document[0].body).append(template);

    $compile(template)($scope);
    $scope.$digest();
  }));

  afterEach(inject(function ($document) {
    clearContent();
  }));

  function recompile (tpl) {
    clearContent();

    var template = angular.element(tpl || defTemplate);
    console.log(template);
    //angular.element($document[0].body).append(template);

    $compile(template)($scope);
    $scope.$digest();
  }

  function getPreview () {
    return document.querySelector('.wmd-preview');
  }

  function clearContent () {
    var content = document.querySelector('content');
    content.parentNode.removeChild(content);
  }

  function newValue (value) {
    $scope.bind = value;
    $timeout.flush();
  }

  function checkPreview (value) {
    expect(getPreview().innerHTML).toBe(value);
  }

  /*
  it('should create a new elem', function () {
    recompile([
      '<content>',
        '<div class="wmd-button-bar"></div>',
        '<ng-markdown ng-model="bind" prefix="ok"></ng-markdown>',
        '<div class="wmd-preview">initialize</div>',
      '</content>'
    ].join(''));
    console.log(getPreview());
  });
  */

  it('should equal 42', function () {
    newValue(42);
    expect(42).toBe(42);
    checkPreview('<p>42</p>');
  });

  it('should attach buttons to the toolbar', function () {
    expect(document.querySelectorAll('.wmd-button-bar div i').length).toBe(15);
  });

  it('should be italic', function () {
    newValue('*italic*');
{'fraction_non_alphanumeric': 0.18535530937584438, 'fraction_numerical': 0.007295325587679005, 'mean_word_length': 3.4176610978520285, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, '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': '216339', 'n_tokens_mistral': 1165, 'n_tokens_neox': 1145, 'n_words': 207}