<commit_before>// Prevent jshinf from raising the "Expected an assignment or function call and instead saw an expression" warning
// jshint -W030

$(function() {
  'use strict';

  module('filterable plugin');

  test('should be defined on jquery object', function() {
    ok($(document.body).filterable, 'filterable method is defined');
  });

  module('filterable', {
    setup: function() {
      // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode
      $.fn.suiFilterable = $.fn.filterable.noConflict();
    },
    teardown: function() {
      $.fn.filterable = $.fn.suiFilterable;
      delete $.fn.suiFilterable;
    }
  });

  test('should provide no conflict', function() {
    strictEqual($.fn.filterable, undefined, 'filterable was set back to undefined (original value)');
  });

  test('should return jquery collection containing the element', function() {
    var $filterable = $(document).suiFilterable();
    ok($filterable instanceof $, 'returns jquery collection');
    strictEqual($filterable[0], $(document)[0], 'collection contains element');
  });


  // Filter related tests
  test('should fire filter.sui.filterable when filtering is started', function() {
    stop();
    $(document).on('filtered.sui.filterable', function() {
      $(document).off('filtered.sui.filterable');
      ok(false, 'filtered.sui.filterable fired before filter.sui.filterable');
    });
    $(document).on('filter.sui.filterable', function() {
      $(document).off('filtered.sui.filterable');
      $(document).off('filter.sui.filterable');
      ok(true, 'event fired');
      start();
    });
    var $filterable = $(document).suiFilterable();
  });

  test('should fire filtered.sui.filterable when filtering is finished', function() {
    stop();
    $(document).on('filter.sui.filterable', function() {
      $(document).off('filter.sui.filterable');
      $(document).on('filtered.sui.filterable', function() {
        $(document).off('filtered.sui.filterable');
        ok(true, 'event fired');
        start();
      });
    });
    var $filterable = $(document).suiFilterable();
  });

  test('should filter elements for: filterValue = [], dataValue = [], operator = "subset"', function() {
    stop();
    $('#qunit-fixture')
      .append('<div data-tags=\'["tag1", "tag2"]\'>')
      .append('<div data-tags=\'["tag1", "tag2", "tag3"]\'>')
      .append('<div data-tags=\'["tag1"]\'>');

    $(document).on('filtered.sui.filterable', function() {
      $(document).off('filtered.sui.filterable');
      ok($('#qunit-fixture div[data-tags=\'["tag1", "tag2"]\']').is(':visible') === true, '["tag1", "tag2"] is the same as ["tag1", "tag2"] -> visible');<commit_msg>improved the logif of event firing tests<commit_after>// Prevent jshinf from raising the "Expected an assignment or function call and instead saw an expression" warning
// jshint -W030

$(function() {
  'use strict';

  module('filterable plugin');

  test('should be defined on jquery object', function() {
    ok($(document.body).filterable, 'filterable method is defined');
  });

  module('filterable', {
    setup: function() {
      // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode
      $.fn.suiFilterable = $.fn.filterable.noConflict();
    },
    teardown: function() {
      $.fn.filterable = $.fn.suiFilterable;
      delete $.fn.suiFilterable;
    }
  });

  test('should provide no conflict', function() {
    strictEqual($.fn.filterable, undefined, 'filterable was set back to undefined (original value)');
  });

  test('should return jquery collection containing the element', function() {
    var $filterable = $(document).suiFilterable();
    ok($filterable instanceof $, 'returns jquery collection');
    strictEqual($filterable[0], $(document)[0], 'collection contains element');
  });


  // Filter related tests
  test('should fire filter.sui.filterable when filtering is started', function() {
    stop();
    $('#qunit-fixture').append('<div data-tags="tag1">');

    $(document).on('filter.sui.filterable', function() {
      $(document).off('filter.sui.filterable');
      ok($('#qunit-fixture div[data-tags="tag1"]').is(':visible') === true, 'event fired before filtering');
      start();
    });

    $('#qunit-fixture div').suiFilterable([{
      'filter-attrib': 'tags',
      'filter-operator': 'subset',
      'filter-value': 'tag2'
    }]);
  });

  test('should fire filtered.sui.filterable when filtering is finished', function() {
    stop();
    $('#qunit-fixture').append('<div data-tags="tag1">');

    $(document).on('filtered.sui.filterable', function() {
      $(document).off('filtered.sui.filterable');
      ok($('#qunit-fixture div[data-tags="tag1"]').is(':visible') === false, 'event fired after filtering');
      start();
    });

    $('#qunit-fixture div').suiFilterable([{
      'filter-attrib': 'tags',
      'filter-operator': 'subset',
      'filter-value': 'tag2'
    }]);
  });

  test('should filter elements for: filterValue = [], dataValue = [], operator = "subset"', function() {
    stop();
    $('#qunit-fixture')
      .append('<div data-tags=\'["tag1", "tag2"]\'>')
      .append('<div data-tags=\'["tag1", "tag2", "tag3"]\'>')
      .append('<div data-tags=\'["tag1"]\'>');

    $(document).on('filtered.sui.filterable', function() {
      $(document).off('filtered.sui.filterable');
      ok($('#qunit-fixture div[data-tags=\'["tag1", "tag2"]\']').is(':visible') === true, '["tag1", "tag2"] is the same as ["tag1", "tag2"] -> visible');
{'fraction_non_alphanumeric': 0.19603288062902072, 'fraction_numerical': 0.007147962830593281, 'mean_word_length': 3.6797658862876252, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '5372913', 'n_tokens_mistral': 1737, 'n_tokens_neox': 1679, 'n_words': 399}