//import { getUserSpecificSelectionFilters, getSelectionFiltersForMongoQuery, getSelectionFiltersBySearchCriteria } from '../containers/Logbook/SelectionFilterHelper';
import getUIConfiguration from '../uiConfig';

require('it-each')({ testPerIteration: true });

const resources = require('./resources/selectionFilterHelper.resource');

describe('selectionFilterHelper', () => {
  describe('getUserSpecificSelectionFilters', () => {
    describe('handle errors', () => {
      it.each(
        resources.getUserSpecificSelectionFilters,
        '[note: %s ]',
        ['description'],
        (element, next) => {
          const getUserSpecificSelectionFilters = require('../../containers/Logbook/SelectionFilterHelper')
            .getUserSpecificSelectionFilters;
          expect(getUserSpecificSelectionFilters(element.criteria)).toEqual(
            element.expected
          );
          next();
        }
      );
    });
  });

  describe('getSelectionFiltersBySearchCriteria', () => {
    describe('handle errors', () => {
      it.each(
        resources.getSelectionFiltersBySearchCriteria,
        '[note: %s ]',
        ['description'],
        (element, next) => {
          const getSelectionFiltersBySearchCriteria = require('../../containers/Logbook/SelectionFilterHelper')
            .getSelectionFiltersBySearchCriteria;
          expect(
            getSelectionFiltersBySearchCriteria(element.criteria, element.view)
          ).toEqual(element.expected);
          next();
        }
      );
    });
  });

  describe('getSelectionFiltersForMongoQuery', () => {
    it.each(
      resources.getSelectionFiltersForMongoQuery,
      '[note: %s ]',
      ['description'],
      (element, next) => {
        //mock the configuration file. Since mockGetUIConfiguration is out of scope of jest.mock(), it must start with 'mock'.
        const mockGetUIConfiguration = getUIConfiguration({
          SORT_EVENTS_BY: element.SORT_EVENTS_BY,
          SORTING_ORDER: element.SORTING_ORDER,
        });
        jest.mock('../../config/ui/config', () => mockGetUIConfiguration);
        const getSelectionFiltersForMongoQuery = require('../../containers/Logbook/SelectionFilterHelper')
          .getSelectionFiltersForMongoQuery;
        expect(
          getSelectionFiltersForMongoQuery(
            element.criteria,
            { [element.SORT_EVENTS_BY]: element.SORTING_ORDER },
            element.view
          )
        ).toEqual(element.expected);
        next();
      }
    );
  });
});
