<commit_before>import configureMockStore from 'redux-mock-store';

import middleware from './middleware';
import actions, { types } from './actions';

import util from 'util';

describe('test middleware behavior', () => {
  describe('when the network request is fine', () => {

    // Mock jQuery.
    class jQuery {
      constructor(selector, context) {}
      html() {}
    }
    const $ = (selector, context) => new jQuery(selector, context);
    $.ajax = () => {};
    $.templates = () => ({ render: () => {} });

    const mockStore = configureMockStore([middleware(types, actions, $)]);

    it('createBookmark action should triggers bookmarkCreated and setReposAreSaved action', () => {
      const store = mockStore({
        repos: { page: 1, data: [{ id: 1, full_name: 'foo/boo' }] },
        bookmarks: [],
      });

      const expectedActions = [
        actions.createBookmark(1, 'foo/boo'),
        actions.bookmarkCreated(1, 'foo/boo'),

        // There is no reducer included, so bookmarks array stil is empty.
        actions.setReposAreSaved([]),
      ]
      store.dispatch(expectedActions[0]);

      expect(store.getActions()).toEqual(expectedActions);
    });
  });
});<commit_msg>Add delete bookmark action test.<commit_after>import configureMockStore from 'redux-mock-store';

import middleware from './middleware';
import actions, { types } from './actions';

import util from 'util';

describe('test middleware behavior', () => {
  describe('when the network request is fine', () => {

    // Mock jQuery.
    class jQuery {
      constructor(selector, context) {}
      html() {}
    }
    const $ = (selector, context) => new jQuery(selector, context);
    $.ajax = () => {};
    $.templates = () => ({ render: () => {} });

    const mockStore = configureMockStore([middleware(types, actions, $)]);

    it('createBookmark action should triggers bookmarkCreated and setReposAreSaved action', () => {
      const store = mockStore({
        repos: { page: 1, data: [{ id: 1, full_name: 'foo/boo' }] },
        bookmarks: [],
      });

      const expectedActions = [
        actions.createBookmark(1, 'foo/boo'),
        actions.bookmarkCreated(1, 'foo/boo'),

        // There is no reducer included, so bookmarks array stil is empty.
        actions.setReposAreSaved([]),
      ]
      store.dispatch(expectedActions[0]);

      expect(store.getActions()).toEqual(expectedActions);
    });

    it('deleteBookmark action should triggers bookmarkDeleted and setReposAreSaved action', () => {
      const store = mockStore({
        repos: { page: 1, data: [{ id: 1, full_name: 'foo/boo' }] },
        bookmarks: [{ repo_id: 1, full_name: 'foo/boo' }],
      });

      const expectedActions = [
        actions.deleteBookmark(1),
        actions.bookmarkDeleted(1),

        // There is no reducer included, so bookmarks array stil is not empty.
        actions.setReposAreSaved([1]),
      ]
      store.dispatch(expectedActions[0]);

      expect(store.getActions()).toEqual(expectedActions);
    })
  });
});
{'fraction_non_alphanumeric': 0.15594221930400526, 'fraction_numerical': 0.005581089954038083, 'mean_word_length': 2.9468911917098444, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, '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': '942324', 'n_tokens_mistral': 899, 'n_tokens_neox': 872, 'n_words': 219}