<commit_before>import sagaHelper from 'redux-saga-testing';
import { put, select } from 'redux-saga/effects';

import { getSavedQuery, updateSaveQuery } from '../savedQuery';
import { getQueryCreator } from '../queryCreator';

import { updateUI } from '../../redux/actionCreators/ui';

import { loadPersitedState, persistState } from './saga';

import { b64EncodeUnicode } from '../../utils/base64';
import { URL_STATE } from './constants';

describe('persistState() - equal states', () => {
  const it = sagaHelper(persistState());

  // @ts-ignore
  const windowSpy = jest.spyOn(global, 'window', 'get');

  const storeState = {
    userInterface: { analysisType: 'count' },
    savedQuery: { name: 'query' },
  };

  const persistedState = b64EncodeUnicode(JSON.stringify(storeState));

  windowSpy.mockImplementation(() => ({
    location: {
      href: `http://keen-explorer.io?${URL_STATE}=${persistedState}`,
    } as Location,
  }));

  it('should get query creator state', (result) => {
    expect(result).toEqual(select(getQueryCreator));
    return storeState.userInterface;
  });

  it('should current saved query', (result) => {
    expect(result).toEqual(select(getSavedQuery));
    return storeState.savedQuery;
  });

  it('should terminate saga for equal states', (result) => {
    expect(result).toBeUndefined();
  });

  windowSpy.mockRestore();
});

describe('loadPersitedState()', () => {
  const it = sagaHelper(loadPersitedState());

  // @ts-ignore
  const windowSpy = jest.spyOn(global, 'window', 'get');

  const storeState = {
    userInterface: { analysisType: 'count' },
    savedQuery: { name: 'query' },
  };

  const persistedState = b64EncodeUnicode(JSON.stringify(storeState));

  windowSpy.mockImplementation(() => ({
    location: {
      href: `http://keen-explorer.io?${URL_STATE}=${persistedState}`,
    } as Location,
  }));

  it('should dispatch action to update query creator', (result) => {
    const action = updateUI({
      ...storeState.userInterface,
      autoload: true,
    });

    expect(result).toEqual(put(action));
  });

  it('should dispatch action to restore saved query', (result) => {
    const action = updateSaveQuery({
      ...storeState.savedQuery,
    });

    expect(result).toEqual(put(action));
  });

  windowSpy.mockRestore();
});<commit_msg>chore: 🤖 tests<commit_after>import sagaHelper from 'redux-saga-testing';
import { put, select } from 'redux-saga/effects';

import { getSavedQuery, updateSaveQuery } from '../savedQuery';
import { getQueryCreator } from '../queryCreator';

import { updateUI } from '../../redux/actionCreators/ui';

import { loadPersitedState, persistState } from './saga';

import { b64EncodeUnicode } from '../../utils/base64';
import { URL_STATE } from './constants';

describe('persistState() - equal states', () => {
  const it = sagaHelper(persistState());

  // @ts-ignore
  const windowSpy = jest.spyOn(global, 'window', 'get');

  const storeState = {
    userInterface: { analysisType: 'count' },
    savedQuery: { name: 'query' },
  };

  const persistedState = b64EncodeUnicode(JSON.stringify(storeState));

  // @ts-ignore
  windowSpy.mockImplementation(() => ({
    location: {
      href: `http://keen-explorer.io?${URL_STATE}=${persistedState}`,
    },
  }));

  it('should get query creator state', (result) => {
    expect(result).toEqual(select(getQueryCreator));
    return storeState.userInterface;
  });

  it('should current saved query', (result) => {
    expect(result).toEqual(select(getSavedQuery));
    return storeState.savedQuery;
  });

  it('should terminate saga for equal states', (result) => {
    expect(result).toBeUndefined();
  });

  windowSpy.mockRestore();
});

describe('loadPersitedState()', () => {
  const it = sagaHelper(loadPersitedState());

  // @ts-ignore
  const windowSpy = jest.spyOn(global, 'window', 'get');

  const storeState = {
    userInterface: { analysisType: 'count' },
    savedQuery: { name: 'query' },
  };

  const persistedState = b64EncodeUnicode(JSON.stringify(storeState));

  // @ts-ignore
  windowSpy.mockImplementation(() => ({
    location: {
      href: `http://keen-explorer.io?${URL_STATE}=${persistedState}`,
    },
  }));

  it('should dispatch action to update query creator', (result) => {
    const action = updateUI({
      ...storeState.userInterface,
      autoload: true,
    });

    expect(result).toEqual(put(action));
  });

  it('should dispatch action to restore saved query', (result) => {
    const action = updateSaveQuery({
      ...storeState.savedQuery,
    });

    expect(result).toEqual(put(action));
  });

  windowSpy.mockRestore();
});
{'fraction_non_alphanumeric': 0.17201983186031472, 'fraction_numerical': 0.0034490191851692174, 'mean_word_length': 3.858638743455497, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '7230681', 'n_tokens_mistral': 1481, 'n_tokens_neox': 1438, 'n_words': 292}