"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.createTestStore = exports.preloadedState = exports.renderWithRouterAndReduxProvider = exports.renderWithReduxProvider = exports.withReduxProvider = void 0;

var _react = _interopRequireDefault(require("react"));

var _reactRedux = require("react-redux");

var _componentsTestUtils = require("@looker/components-test-utils");

var _redux = require("@looker/redux");

var _extensionUtils = require("@looker/extension-utils");

var _runIt = require("@looker/run-it");

var _state = require("../state");

var _testData = require("../test-data");

var _router = require("./router");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var withReduxProvider = function withReduxProvider(consumers) {
  var store = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : createTestStore();
  (0, _extensionUtils.registerEnvAdaptor)(new _extensionUtils.BrowserAdaptor((0, _runIt.initRunItSdk)()));
  return _react.default.createElement(_reactRedux.Provider, {
    store: store
  }, consumers);
};

exports.withReduxProvider = withReduxProvider;

var renderWithReduxProvider = (consumers, store, options) => (0, _componentsTestUtils.renderWithTheme)(withReduxProvider(consumers, store), options);

exports.renderWithReduxProvider = renderWithReduxProvider;

var renderWithRouterAndReduxProvider = function renderWithRouterAndReduxProvider(consumers) {
  var initialEntries = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['/'];
  var store = arguments.length > 2 ? arguments[2] : undefined;
  var options = arguments.length > 3 ? arguments[3] : undefined;
  return (0, _router.renderWithRouter)(withReduxProvider(consumers, store), initialEntries, options);
};

exports.renderWithRouterAndReduxProvider = renderWithRouterAndReduxProvider;
var preloadedState = {
  settings: _state.defaultSettingsState,
  lodes: _state.defaultLodesState,
  specs: _state.defaultSpecsState
};
exports.preloadedState = preloadedState;

var createTestStore = overrides => (0, _redux.createStore)({
  preloadedState: {
    settings: _objectSpread(_objectSpread({}, preloadedState.settings), overrides === null || overrides === void 0 ? void 0 : overrides.settings),
    lodes: _objectSpread(_objectSpread({}, _state.defaultLodesState), overrides === null || overrides === void 0 ? void 0 : overrides.lodes),
    specs: _objectSpread(_objectSpread({}, _testData.specState), overrides === null || overrides === void 0 ? void 0 : overrides.specs)
  },
  reducer: {
    settings: _state.settingsSlice.reducer,
    lodes: _state.lodesSlice.reducer,
    specs: _state.specsSlice.reducer
  }
});

exports.createTestStore = createTestStore;
//# sourceMappingURL=redux.js.map