<commit_before>jest.dontMock('../Hooks');
jest.dontMock('../../config/Config');
jest.dontMock('../../constants/EventTypes');
jest.dontMock('../../events/AppDispatcher');
jest.dontMock('../../events/ConfigActions');
jest.dontMock('../../stores/ConfigStore');

const Hooks = require('../Hooks');

describe('HooksAPI', function () {

  describe('#applyFilter', function () {

    beforeEach(function () {
      this.fakeFilter = jest.genMockFunction();
      this.fakeFilter.mockImplementation(function (value) {
        return value.replace('bar', 'baz');
      });

      Hooks.addFilter('foo', this.fakeFilter);

      this.filteredContent = Hooks.applyFilter('foo', 'foo bar', 'qux');
    });

    it('should receive the arguments that we defined', function () {
      expect(this.fakeFilter.mock.calls[0]).toEqual(['foo bar', 'qux']);
    });

    it('should call the filter once', function () {
      expect(this.fakeFilter.mock.calls.length).toEqual(1);
    });

    it('should return the filtered content when a filter is applied',
      function () {
        expect(this.filteredContent).toEqual('foo baz');
      });

    it('should apply the filters in the order of priority', function () {
      var lowPriorityFilter = jest.genMockFunction();
      var highPriorityFilter = jest.genMockFunction();

      lowPriorityFilter.mockImplementation(function (value) {
        return value.replace('bar', 'baz');
      });

      highPriorityFilter.mockImplementation(function (value) {
        return value.replace('bar', 'qux');
      });

      Hooks.addFilter('corge', lowPriorityFilter, 20);
      Hooks.addFilter('corge', highPriorityFilter, 1);

      var filteredContent = Hooks.applyFilter('corge', 'foo bar');

      expect(filteredContent).toEqual('foo qux');
    });

  });

  describe('#doAction', function () {

    beforeEach(function () {
      this.fakeAction = jest.genMockFunction();
      Hooks.addAction('foo', this.fakeAction);
    });

    it('should be called only once when an action is performed', function () {
      Hooks.doAction('foo', 'bar');
      expect(this.fakeAction.mock.calls.length).toEqual(1);
    });

    it('should receive arguments when an action is performed', function () {
      Hooks.doAction('foo', 'bar');
      expect(this.fakeAction.mock.calls[0][0]).toEqual('bar');
    });

    it('should not receive arguments when arguments are not passed',
      function () {
        this.noArgumentsAction = jest.genMockFunction();
        Hooks.addAction('qux', this.noArgumentsAction);
        Hooks.doAction('qux');
        expect(this.noArgumentsAction.mock.calls[0].length).toEqual(0);
      });

    it('should receive two arguments when two arguments are passed',
      function () {
        this.twoArgumentsAction = jest.genMockFunction();
        Hooks.addAction('quux', this.twoArgumentsAction);
        Hooks.doAction('quux', 'baz', 'bar');<commit_msg>Fixing tests<commit_after>jest.dontMock('../Hooks');

const Hooks = require('../Hooks');

describe('HooksAPI', function () {

  describe('#applyFilter', function () {

    beforeEach(function () {
      this.fakeFilter = jest.genMockFunction();
      this.fakeFilter.mockImplementation(function (value) {
        return value.replace('bar', 'baz');
      });

      this.hooks = new Hooks();
      this.hooks.addFilter('foo', this.fakeFilter);

      this.filteredContent = this.hooks.applyFilter('foo', 'foo bar', 'qux');
    });

    it('should receive the arguments that we defined', function () {
      expect(this.fakeFilter.mock.calls[0]).toEqual(['foo bar', 'qux']);
    });

    it('should call the filter once', function () {
      expect(this.fakeFilter.mock.calls.length).toEqual(1);
    });

    it('should return the filtered content when a filter is applied',
      function () {
        expect(this.filteredContent).toEqual('foo baz');
      });

    it('should apply the filters in the order of priority', function () {
      var lowPriorityFilter = jest.genMockFunction();
      var highPriorityFilter = jest.genMockFunction();

      lowPriorityFilter.mockImplementation(function (value) {
        return value.replace('bar', 'baz');
      });

      highPriorityFilter.mockImplementation(function (value) {
        return value.replace('bar', 'qux');
      });

      this.hooks.addFilter('corge', lowPriorityFilter, 20);
      this.hooks.addFilter('corge', highPriorityFilter, 1);

      var filteredContent = this.hooks.applyFilter('corge', 'foo bar');

      expect(filteredContent).toEqual('foo qux');
    });

  });

  describe('#doAction', function () {

    beforeEach(function () {
      this.hooks = new Hooks();
      this.fakeAction = jest.genMockFunction();
      this.hooks.addAction('foo', this.fakeAction);
    });

    it('should be called only once when an action is performed', function () {
      this.hooks.doAction('foo', 'bar');
      expect(this.fakeAction.mock.calls.length).toEqual(1);
    });

    it('should receive arguments when an action is performed', function () {
      this.hooks.doAction('foo', 'bar');
      expect(this.fakeAction.mock.calls[0][0]).toEqual('bar');
    });

    it('should not receive arguments when arguments are not passed',
      function () {
        this.noArgumentsAction = jest.genMockFunction();
        this.hooks.addAction('qux', this.noArgumentsAction);
        this.hooks.doAction('qux');
        expect(this.noArgumentsAction.mock.calls[0].length).toEqual(0);
      });

    it('should receive two arguments when two arguments are passed',
      function () {
        this.twoArgumentsAction = jest.genMockFunction();
        this.hooks.addAction('quux', this.twoArgumentsAction);
        this.hooks.doAction('quux', 'baz', 'bar');
{'fraction_non_alphanumeric': 0.15988118119867203, 'fraction_numerical': 0.0034946706272933775, 'mean_word_length': 3.281226626776365, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5387212', 'n_tokens_mistral': 1654, 'n_tokens_neox': 1624, 'n_words': 329}