<commit_before>import Loader from '../../src/models/loader';
import { delay } from 'lodash';

jest.useFakeTimers();

class TestModel {
  fetch = jest.fn(() => Promise.resolve());
}


describe('Model Loader', () => {
  let model;
  let loader;

  beforeEach(() => {
    model = new TestModel();
    loader = new Loader({ model });
  });

  it('fetches immediately', () => {
    const props = { foo: 'bar' };
    const fetcher = new Loader({ model, fetch: props });
    expect(model.fetch).toHaveBeenCalledWith(props);
    expect(fetcher.isLoading(props)).toBeTruthy();
  });

  it('will not load when load is in progress', () => {
    expect(model.fetch).toHaveBeenCalledTimes(0);
    const args = { one: 1, two: 2 };
    loader.fetch(args);
    expect(model.fetch).toHaveBeenCalledTimes(1);
    loader.fetch(args);
    expect(model.fetch).toHaveBeenCalledTimes(1);
  });

  fit('will reload once complete', () => {
    expect(model.fetch).toHaveBeenCalledTimes(0);
    const args = { one: 1, two: 2 };
    loader.fetch(args);
    jest.runAllTimers();
    expect(model.fetch).toHaveBeenCalledTimes(1);
    expect(loader.isLoading(args)).toBeFalsy();
    expect(loader.hasLoaded(args)).toBeTruthy();
    expect(model.fetch).toHaveBeenCalledTimes(1);
    loader.fetch(args, { reload: true });
    expect(model.fetch).toHaveBeenCalledTimes(2);
  });

});<commit_msg>run all specs<commit_after>import Loader from '../../src/models/loader';
import { delay } from 'lodash';

jest.useFakeTimers();

class TestModel {
  fetch = jest.fn(() => Promise.resolve());
}


describe('Model Loader', () => {
  let model;
  let loader;

  beforeEach(() => {
    model = new TestModel();
    loader = new Loader({ model });
  });

  it('fetches immediately', () => {
    const props = { foo: 'bar' };
    const fetcher = new Loader({ model, fetch: props });
    expect(model.fetch).toHaveBeenCalledWith(props);
    expect(fetcher.isLoading(props)).toBeTruthy();
  });

  it('will not load when load is in progress', () => {
    expect(model.fetch).toHaveBeenCalledTimes(0);
    const args = { one: 1, two: 2 };
    loader.fetch(args);
    expect(model.fetch).toHaveBeenCalledTimes(1);
    loader.fetch(args);
    expect(model.fetch).toHaveBeenCalledTimes(1);
  });

  it('will reload once complete', () => {
    expect(model.fetch).toHaveBeenCalledTimes(0);
    const args = { one: 1, two: 2 };
    loader.fetch(args);
    jest.runAllTimers();
    expect(model.fetch).toHaveBeenCalledTimes(1);
    expect(loader.isLoading(args)).toBeFalsy();
    expect(loader.hasLoaded(args)).toBeTruthy();
    expect(model.fetch).toHaveBeenCalledTimes(1);
    loader.fetch(args, { reload: true });
    expect(model.fetch).toHaveBeenCalledTimes(2);
  });

});
{'fraction_non_alphanumeric': 0.17774513404333456, 'fraction_numerical': 0.008079324274697026, 'mean_word_length': 3.838365896980462, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '6593005', 'n_tokens_mistral': 910, 'n_tokens_neox': 896, 'n_words': 168}