<commit_before>import {expectSaga} from 'redux-saga-test-plan'
import * as matchers from 'redux-saga-test-plan/matchers'
import {select, takeEvery, takeLatest, all} from 'redux-saga/effects'
import {rest} from 'tocco-app-extensions'

import * as actions from './actions'
import rootSaga, * as sagas from './sagas'

describe('input-edit', () => {
  describe('input-edit-table', () => {
    describe('sagas', () => {
      test('should fork child sagas', () => {
        const generator = rootSaga()
        expect(generator.next().value).to.deep.equal(all([
          takeLatest(actions.INITIALIZE_TABLE, sagas.initialize),
          takeLatest(actions.LOAD_DATA, sagas.loadData),
          takeEvery(actions.UPDATE_VALUE, sagas.updateValue),
          takeLatest(actions.SET_SORTING, sagas.sortData)
        ]))
        expect(generator.next().done).to.be.true
      })

      describe('initialize', () => {
        test('should load forms', () => {
          const expectedEditForm = [{
            editform: 'editform'
          }]
          const expectedDataForm = {
            dataform: 'dataform'
          }
          return expectSaga(sagas.initialize, actions.initializeTable())
            .provide([
              [select(sagas.inputSelector), {inputEntityKey: 12}],
              [matchers.call.fn(rest.requestSaga), {
                body: expectedEditForm
              }],
              [matchers.call.fn(rest.fetchForm), expectedDataForm],
              [matchers.call.fn(sagas.loadData)]
            ])
            .put(actions.setEditForm({inputEditForm: expectedEditForm}))
            .put(actions.setDataForm({inputDataForm: expectedDataForm}))
            .call(sagas.loadData)
            .run()
        })
      })

      describe('load-data', () => {
        test('should load data', () => {
          const expectedData = {
            1: {
              pk: 123
            }
          }
          const expectedSorting = {
            field: 'field',
            direction: 'asc'
          }
          return expectSaga(sagas.loadData, expectedSorting)
            .provide([
              [select(sagas.inputSelector), {inputEntityKey: 12}],
              [select(sagas.inputEditTableSelector), {sorting: {field: 'state sorting'}}],
              [matchers.call.fn(rest.requestSaga), {
                body: expectedData
              }]
            ])
            .call(rest.requestSaga, 'inputEdit/12/data/search', {
              method: 'POST',
              body: {
                sorting: expectedSorting
              }
            })
            .put(actions.setData({data: expectedData}))
            .run()
        })
        test('should use sorting from state if none is passed', () => {
          const expectedSorting = {
            field: 'field',
            direction: 'asc'
          }
          return expectSaga(sagas.loadData)
            .provide([
              [select(sagas.inputSelector), {inputEntityKey: 12}],
              [select(sagas.inputEditTableSelector), {sorting: expectedSorting}],
              [matchers.call.fn(rest.requestSaga), {body: {}}]
            ])
            .call(rest.requestSaga, 'inputEdit/12/data/search', {
              method: 'POST',
              body: {
                sorting: expectedSorting
              }
            })
            .run()
        })
      })

      describe('sort-data', () => {
        test('should pass sorting to loadData', () => {
          return expectSaga(sagas.sortData, actions.setSorting('field', 'desc'))
            .provide([
              [matchers.call.fn(sagas.loadData)]
            ])
            .call(sagas.loadData, {
              field: 'field',
              direction: 'desc'
            })
            .run()
        })
      })<commit_msg>feat(input-edit): adjust tests to work with search and pagination<commit_after>import {expectSaga} from 'redux-saga-test-plan'
import * as matchers from 'redux-saga-test-plan/matchers'
import {select, takeEvery, takeLatest, all} from 'redux-saga/effects'
import {rest} from 'tocco-app-extensions'

import * as actions from './actions'
import rootSaga, * as sagas from './sagas'

describe('input-edit', () => {
  describe('input-edit-table', () => {
    describe('sagas', () => {
      test('should fork child sagas', () => {
        const generator = rootSaga()
        expect(generator.next().value).to.deep.equal(all([
          takeLatest(actions.INITIALIZE_TABLE, sagas.initialize),
          takeLatest(actions.LOAD_DATA, sagas.loadData),
          takeEvery(actions.UPDATE_VALUE, sagas.updateValue),
          takeLatest(actions.SET_SORTING, sagas.sortData)
        ]))
        expect(generator.next().done).to.be.true
      })

      describe('initialize', () => {
        test('should load forms', () => {
          const expectedEditForm = [{
            editform: 'editform'
          }]
          const expectedDataForm = {
            dataform: 'dataform'
          }
          return expectSaga(sagas.initialize)
            .provide([
              [select(sagas.inputSelector), {inputEntityKey: 12}],
              [matchers.call.fn(rest.requestSaga), {
                body: expectedEditForm
              }],
              [matchers.call.fn(rest.fetchForm), expectedDataForm],
              [matchers.call.fn(sagas.loadData), {}]
            ])
            .put(actions.setEditForm({inputEditForm: expectedEditForm}))
            .put(actions.setDataForm({inputDataForm: expectedDataForm}))
            .call(sagas.loadData, {})
            .run()
        })
      })

      describe('load-data', () => {
        test('should load data', () => {
          const expectedData = {
            count: 50,
            data: [
              {
                pk: 123
              }
            ]
          }
          const expectedSorting = {
            field: 'field',
            direction: 'asc'
          }
          const expectedSearchQueries = [
            'firstname == \'something\''
          ]
          const expectedPagination = {
            offset: 25,
            recordsPerPage: 25
          }
          return expectSaga(sagas.loadData, {
            newSorting: expectedSorting,
            newSearchQueries: expectedSearchQueries,
            newPage: 2
          })
            .provide([
              [select(sagas.inputSelector), {inputEntityKey: 12}],
              [select(sagas.inputEditTableSelector), {sorting: {field: 'state sorting'}}],
              [select(sagas.searchQueriesSelector), []],
              [select(sagas.inputEditPaginationSelector), {
                count: 0,
                currentPage: 1,
                recordsPerPage: 25
              }],
              [matchers.call.fn(rest.requestSaga), {
                body: expectedData
              }]
            ])
            .call.like({
              fn: rest.requestSaga,
              args: [
                'inputEdit/12/data/search',
                {
                  method: 'POST',
                  body: {
                    sorting: expectedSorting,
                    searchQueries: expectedSearchQueries,
                    pagination: expectedPagination
                  }
                }
              ]
            })
            .put(actions.setData(expectedData))
            .run()
        })
        test('should load data from state if no arguments are passed', () => {
          const expectedSorting = {
            field: 'field',
            direction: 'asc'
          }
          const expectedSearchQueries = [
            'firstname == \'whatever\''
          ]
          const expectedPagination = {
            offset: 0,
            recordsPerPage: 25
          }
          return expectSaga(sagas.loadData, {})
            .provide([
              [select(sagas.inputSelector), {inputEntityKey: 12}],
              [select(sagas.inputEditTableSelector), {sorting: expectedSorting}],
              [select(sagas.searchQueriesSelector), expectedSearchQueries],
              [select(sagas.inputEditPaginationSelector), {
                count: 0,
                currentPage: 1,
                recordsPerPage: 25
              }],
              [matchers.call.fn(rest.requestSaga), {body: {}}]
            ])
            .call.like({
              fn: rest.requestSaga,
              args: [
                'inputEdit/12/data/search',
                {
                  method: 'POST',
                  body: {
                    sorting: expectedSorting,
                    searchQueries: expectedSearchQueries,
                    pagination: expectedPagination
                  }
                }
              ]
            })
            .run()
        })
      })

      describe('sort-data', () => {
        test('should pass sorting to loadData', () => {
          return expectSaga(sagas.sortData, actions.setSorting('field', 'desc'))
            .provide([
              [matchers.call.fn(sagas.loadData)]
            ])
            .call(sagas.loadData, {
              newSorting: {
                field: 'field',
                direction: 'desc'
              }
            })
            .run()
        })
      })
{'fraction_non_alphanumeric': 0.1248638047504903, 'fraction_numerical': 0.0049030289823490955, 'mean_word_length': 1.4882081865004066, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '2767061', 'n_tokens_mistral': 2575, 'n_tokens_neox': 2471, 'n_words': 414}