<commit_before>import deepFreeze from 'deep-freeze';
import ucastniciTestData from '../../entities/ucastnici/ucastniciTestData';
import { SortDirTypes } from '../../sort';
import {
  createKategorieFilterChange,
  createTextFilterChange
} from '../Filterable/FilterableActions';
import { createSortDirChange } from '../UcastniciTable/UcastniciTableActions';
import { kategorieSubFilterChange } from './PoradiActions';
import poradiReducer, { getPoradiSorted } from './poradiReducer';

const actionPrefix = 'PORADI';
const kategorieFilterChange = createKategorieFilterChange(actionPrefix);
const sortDirChange = createSortDirChange(actionPrefix);
const textFilterChange = createTextFilterChange(actionPrefix);

it('na začátku', () => {
  const stateBefore = undefined;

  const stateAfter = poradiReducer(stateBefore, {});
  expect(stateAfter.kategorieFilter).toEqual('');
  expect(stateAfter.kategorieSubFilter).toEqual('');
  expect(stateAfter.textFilter).toEqual('');
  expect(stateAfter.sortColumn).toBe(undefined);
  expect(stateAfter.sortDir).toEqual(SortDirTypes.NONE);
});

it('přepínání kategorieSubFilter', () => {
  const stateBefore = { kategorieFilter: 'maraton' };
  const stateAfter = { ...stateBefore, kategorieSubFilter: '5a587e1a051c181132cf83ba' };
  deepFreeze(stateBefore);

  expect(poradiReducer(stateBefore, kategorieSubFilterChange('5a587e1a051c181132cf83ba'))).toEqual(
    stateAfter
  );
});

it('přepínání kategorieFilter - vypnout', () => {
  const stateBefore = {
    kategorieFilter: 'maraton',
    kategorieSubFilter: '5a587e1a051c181132cf83ba'
  };
  const stateAfter = { kategorieFilter: '', kategorieSubFilter: '' };
  deepFreeze(stateBefore);

  expect(poradiReducer(stateBefore, kategorieFilterChange(''))).toEqual(stateAfter);
});

it('přepínání kategorieFilter - přepnout', () => {
  const stateBefore = {
    kategorieFilter: 'maraton',
    kategorieSubFilter: '5a587e1a051c181132cf83ba'
  };
  const stateAfter = { kategorieFilter: 'cyklo', kategorieSubFilter: '' };
  deepFreeze(stateBefore);

  expect(poradiReducer(stateBefore, kategorieFilterChange('cyklo'))).toEqual(stateAfter);
});

it('řadit dle příjmení vzestupně', () => {
  const stateBefore = { sortColumn: undefined, sortDir: SortDirTypes.NONE };
  const stateAfter = { sortColumn: 'prijmeni', sortDir: SortDirTypes.ASC };
  deepFreeze(stateBefore);

  expect(poradiReducer(stateBefore, sortDirChange('prijmeni'))).toEqual(stateAfter);
});

it('řadit dle příjmení sestupně', () => {
  const stateBefore = { sortColumn: 'prijmeni', sortDir: SortDirTypes.ASC };
  const stateAfter = { sortColumn: 'prijmeni', sortDir: SortDirTypes.DESC };
  deepFreeze(stateBefore);

  expect(poradiReducer(stateBefore, sortDirChange('prijmeni'))).toEqual(stateAfter);
});

it('řadit dle příjmení zase vzestupně', () => {
  const stateBefore = { sortColumn: 'prijmeni', sortDir: SortDirTypes.DESC };
  const stateAfter = { ...stateBefore, sortColumn: 'prijmeni', sortDir: SortDirTypes.ASC };
  deepFreeze(stateBefore);

  expect(poradiReducer(stateBefore, sortDirChange('prijmeni'))).toEqual(stateAfter);
});

it('filtrovat na dvě písmena', () => {
  const stateBefore = { textFilter: '' };
  const stateAfter = { textFilter: 'kl' };
  deepFreeze(stateBefore);

  expect(poradiReducer(stateBefore, textFilterChange('Kl'))).toEqual(stateAfter);
});

it('getPoradiSorted() by default', () => {
  const state = {
    ...ucastniciTestData,
    registrator: {
      poradi: {
        sortColumn: undefined,
        sortDir: undefined,
        kategorieFilter: '',
        kategorieSubFilter: '',
        textFilter: ''
      }
    }
  };
  const selected = [
    {
      id: '5a09b1fd371dec1e99b7e1c9',
      prijmeni: 'Balabák',
      jmeno: 'Roman',
      narozeni: { rok: 1956 },
      kategorie: {
        id: '<KEY>',
        pohlavi: 'muž',
        typ: 'půlmaraton',
        vek: { min: 60, max: 150 }
      },
      startCislo: 15,
      dokonceno: false
    },
    {
      id: '7a09b1fd371dec1e99b7e142',
      prijmeni: 'Zralá',
      jmeno: 'Hana',
      narozeni: { den: 25, mesic: 7, rok: 1999 },
      kategorie: {
        id: '<KEY>',
        typ: 'půlmaraton',
        pohlavi: 'žena',
        vek: { min: 18, max: 39 }
      },
      startCislo: 11,
      dokonceno: true,
      cas: 'PT2H06M32.6S'
    }
  ];
  deepFreeze(state);

  const {
    entities,
    registrator: { poradi: props }
  } = state;
  expect(getPoradiSorted({ ...entities, ...props })).toEqual(selected);
});<commit_msg>More test cases for poradiReducer.<commit_after>import deepFreeze from 'deep-freeze';
import ucastniciTestData from '../../entities/ucastnici/ucastniciTestData';
import { SortDirTypes } from '../../sort';
import {
  createKategorieFilterChange,
  createTextFilterChange
} from '../Filterable/FilterableActions';
import { createSortDirChange } from '../UcastniciTable/UcastniciTableActions';
import { kategorieSubFilterChange } from './PoradiActions';
import poradiReducer, { getPoradiSorted } from './poradiReducer';

const actionPrefix = 'PORADI';
const kategorieFilterChange = createKategorieFilterChange(actionPrefix);
const sortDirChange = createSortDirChange(actionPrefix);
const textFilterChange = createTextFilterChange(actionPrefix);

it('na začátku', () => {
  const stateBefore = undefined;

  const stateAfter = poradiReducer(stateBefore, {});
  expect(stateAfter.kategorieFilter).toEqual('');
  expect(stateAfter.kategorieSubFilter).toEqual('');
  expect(stateAfter.textFilter).toEqual('');
  expect(stateAfter.sortColumn).toBe(undefined);
  expect(stateAfter.sortDir).toEqual(SortDirTypes.NONE);
});

it('přepínání kategorieSubFilter', () => {
  const stateBefore = { kategorieFilter: 'maraton' };
  const stateAfter = { ...stateBefore, kategorieSubFilter: '5a587e1a051c181132cf83ba' };
  deepFreeze(stateBefore);

  expect(poradiReducer(stateBefore, kategorieSubFilterChange('5a587e1a051c181132cf83ba'))).toEqual(
    stateAfter
  );
});

it('přepínání kategorieFilter - vypnout', () => {
  const stateBefore = {
    kategorieFilter: 'maraton',
    kategorieSubFilter: '5a587e1a051c181132cf83ba'
  };
  const stateAfter = { kategorieFilter: '', kategorieSubFilter: '' };
  deepFreeze(stateBefore);

  expect(poradiReducer(stateBefore, kategorieFilterChange(''))).toEqual(stateAfter);
});

it('přepínání kategorieFilter - přepnout', () => {
  const stateBefore = {
    kategorieFilter: 'maraton',
    kategorieSubFilter: '5a587e1a051c181132cf83ba'
  };
  const stateAfter = { kategorieFilter: 'cyklo', kategorieSubFilter: '' };
  deepFreeze(stateBefore);

  expect(poradiReducer(stateBefore, kategorieFilterChange('cyklo'))).toEqual(stateAfter);
});

it('řadit dle příjmení vzestupně', () => {
  const stateBefore = { sortColumn: undefined, sortDir: SortDirTypes.NONE };
  const stateAfter = { sortColumn: 'prijmeni', sortDir: SortDirTypes.ASC };
  deepFreeze(stateBefore);

  expect(poradiReducer(stateBefore, sortDirChange('prijmeni'))).toEqual(stateAfter);
});

it('řadit dle příjmení sestupně', () => {
  const stateBefore = { sortColumn: 'prijmeni', sortDir: SortDirTypes.ASC };
  const stateAfter = { sortColumn: 'prijmeni', sortDir: SortDirTypes.DESC };
  deepFreeze(stateBefore);

  expect(poradiReducer(stateBefore, sortDirChange('prijmeni'))).toEqual(stateAfter);
});

it('řadit dle příjmení zase vzestupně', () => {
  const stateBefore = { sortColumn: 'prijmeni', sortDir: SortDirTypes.DESC };
  const stateAfter = { ...stateBefore, sortColumn: 'prijmeni', sortDir: SortDirTypes.ASC };
  deepFreeze(stateBefore);

  expect(poradiReducer(stateBefore, sortDirChange('prijmeni'))).toEqual(stateAfter);
});

it('filtrovat na dvě písmena', () => {
  const stateBefore = { textFilter: '' };
  const stateAfter = { textFilter: 'kl' };
  deepFreeze(stateBefore);

  expect(poradiReducer(stateBefore, textFilterChange('Kl'))).toEqual(stateAfter);
});

it('getPoradiSorted() by default', () => {
  const state = {
    ...ucastniciTestData,
    registrator: {
      poradi: {
        sortColumn: undefined,
        sortDir: undefined,
        kategorieFilter: '',
        kategorieSubFilter: '',
        textFilter: ''
      }
    }
  };
  const selected = [
    {
      id: '5a09b1fd371dec1e99b7e1c9',
      prijmeni: 'Balabák',
      jmeno: 'Roman',
      narozeni: { rok: 1956 },
      kategorie: {
        id: '<KEY>',
        pohlavi: 'muž',
        typ: 'půlmaraton',
        vek: { min: 60, max: 150 }
      },
      startCislo: 15,
      dokonceno: false
    },
    {
      id: '7a09b1fd371dec1e99b7e142',
      prijmeni: 'Zralá',
      jmeno: 'Hana',
      narozeni: { den: 25, mesic: 7, rok: 1999 },
      kategorie: {
        id: '<KEY>',
        typ: 'půlmaraton',
        pohlavi: 'žena',
        vek: { min: 18, max: 39 }
      },
      startCislo: 11,
      dokonceno: true,
      cas: 'PT2H06M32.6S'
    }
  ];
  deepFreeze(state);

  const {
    entities,
    registrator: { poradi: props }
  } = state;
  expect(getPoradiSorted({ ...entities, ...props })).toEqual(selected);
});

it('getPoradiSorted() - filter for startovní číslo 11', () => {
  const state = {
    ...ucastniciTestData,
    registrator: {
      poradi: {
        sortColumn: undefined,
        sortDir: undefined,
        kategorieFilter: '',
        kategorieSubFilter: '',
        textFilter: '11'
      }
    }
  };
  const selected = [
    {
      id: '7a09b1fd371dec1e99b7e142',
      prijmeni: 'Zralá',
      jmeno: 'Hana',
      narozeni: { den: 25, mesic: 7, rok: 1999 },
      kategorie: {
        id: '5a587e1b051c181132cf83d9',
        typ: 'půlmaraton',
        pohlavi: 'žena',
        vek: { min: 18, max: 39 }
      },
      startCislo: 11,
      dokonceno: true,
      cas: 'PT2H06M32.6S'
    }
  ];
  deepFreeze(state);

  const {
    entities,
    registrator: { poradi: props }
  } = state;
  expect(getPoradiSorted({ ...entities, ...props })).toEqual(selected);
});

it('getPoradiSorted() - filter for kategorie půlmaraton/žena/18-39', () => {
  const state = {
    ...ucastniciTestData,
    registrator: {
      poradi: {
        sortColumn: undefined,
        sortDir: undefined,
        kategorieFilter: 'půlmaraton',
        kategorieSubFilter: '5a587e1b051c181132cf83d9',
        textFilter: ''
      }
    }
  };
  const selected = [
    {
      id: '7a09b1fd371dec1e99b7e142',
      prijmeni: 'Zralá',
      jmeno: 'Hana',
      narozeni: { den: 25, mesic: 7, rok: 1999 },
      kategorie: {
        id: '5a587e1b051c181132cf83d9',
        typ: 'půlmaraton',
        pohlavi: 'žena',
        vek: { min: 18, max: 39 }
      },
      startCislo: 11,
      dokonceno: true,
      cas: 'PT2H06M32.6S'
    }
  ];
  deepFreeze(state);

  const {
    entities,
    registrator: { poradi: props }
  } = state;
  expect(getPoradiSorted({ ...entities, ...props })).toEqual(selected);
});
{'fraction_non_alphanumeric': 0.14603409933283915, 'fraction_numerical': 0.034006671608598965, 'mean_word_length': 3.7048823016564953, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 27, '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': '4222156', 'n_tokens_mistral': 4074, 'n_tokens_neox': 3877, 'n_words': 650}