'use strict';

var _redux = require('redux');

var _dist = require('../dist');

var _dist2 = _interopRequireDefault(_dist);

var _tape = require('tape');

var _tape2 = _interopRequireDefault(_tape);

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

var increment = function increment() {
  return { type: 'INCREMENT' };
};

var decrement = function decrement() {
  return { type: 'DECREMENT' };
};

var initState = 0;

var reducer = function reducer() {
  var state = arguments.length <= 0 || arguments[0] === undefined ? initState : arguments[0];
  var _ref = arguments[1];
  var type = _ref.type;
  var payload = _ref.payload;

  var newState = undefined;
  switch (type) {
    case 'INCREMENT':
      newState = state + 1;
      break;
    case 'DECREMENT':
      newState = state - 1;
      break;
    default:
      newState = state;
  }
  return newState;
};

var record = (0, _dist2.default)({ reducer: reducer, includeReducer: true });
var createStoreWithMiddleware = (0, _redux.applyMiddleware)(record.middleware)(_redux.createStore);
var store = createStoreWithMiddleware(reducer);
record.props.startRecord();
store.dispatch(increment());
store.dispatch(increment());
store.dispatch(increment());
store.dispatch(decrement());
eval(record.props.getTest());

var initState2 = {
  add: 0,
  subtract: 0
};
var add = function add() {
  var state = arguments.length <= 0 || arguments[0] === undefined ? initState2.add : arguments[0];
  var _ref2 = arguments[1];
  var type = _ref2.type;
  var payload = _ref2.payload;

  var newState = undefined;
  switch (type) {
    case 'INCREMENT':
      newState = state + 1;
      break;
    default:
      newState = state;
  }
  return newState;
};

var subtract = function subtract() {
  var state = arguments.length <= 0 || arguments[0] === undefined ? initState2.subtract : arguments[0];
  var _ref3 = arguments[1];
  var type = _ref3.type;
  var payload = _ref3.payload;

  var newState = undefined;
  switch (type) {
    case 'DECREMENT':
      newState = state - 1;
      break;
    default:
      newState = state;
  }
  return newState;
};
var combined = (0, _redux.combineReducers)({ add: add, subtract: subtract });
var record2 = (0, _dist2.default)({ reducer: add, includeReducer: true, stateKey: 'add', actionSubset: { INCREMENT: 'INCREMENT' } });
var createStoreWithMiddleware2 = (0, _redux.applyMiddleware)(record2.middleware)(_redux.createStore);
var store2 = createStoreWithMiddleware2(combined);
record2.props.startRecord();
store2.dispatch(increment());
store2.dispatch(increment());
store2.dispatch(increment());
store2.dispatch(decrement());
eval(record2.props.getTest());

var record3 = (0, _dist2.default)({
  reducer: add,
  includeReducer: false
});

(0, _tape2.default)('reducer not included when includeReducer = false', function (assert) {
  assert.plan(1);
  var generatedTest = record3.props.getTest();
  assert.ok(generatedTest.includes('/* import reducer from YOUR_REDUCER_LOCATION_HERE */'), "test includes note to import reducer");
});

(0, _tape2.default)('startRecord makes getRecordingStatus return true, and calling stop makes false', function (assert) {
  assert.plan(2);
  record3.props.startRecord();
  assert.ok(record3.props.getRecordingStatus(), 'getRecordingStatus is true after start');
  record3.props.stopRecord();
  assert.notOk(record3.props.getRecordingStatus(), 'getRecordingStatus is false after stop');
});

(0, _tape2.default)('shouldShowTest is true after stopRecord is fired and false after hideTest is fired', function (assert) {
  assert.plan(2);
  record3.props.stopRecord();
  assert.ok(record3.props.shouldShowTest(), 'should show test after stopRecord is fired');
  record3.props.hideTest();
  assert.notOk(record3.props.shouldShowTest(), 'should hide test after hideTest is fired');
});

var record4 = (0, _dist2.default)({
  reducer: add,
  imports: 'var equal = reqire(\'deep-equal\');'
});

(0, _tape2.default)('extra imports are included when import arg is given', function (assert) {
  assert.plan(1);
  var generatedTest = record4.props.getTest();
  assert.ok(generatedTest.includes('var equal = reqire(\'deep-equal\');'), "test includes additional imports");
});
