"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _index = _interopRequireDefault(require("../index"));

var _immutable = require("immutable");

var _featureCheck = require("../../../../common/util/featureCheck");

var _reduxStore = require("../../../../reduxStore");

describe('connected BankEntry', function () {
  var connectedTestbed = createTestbed(withContext(_index.default, {
    banks: {
      1: {
        title: 'Very distinctive name',
        updatedAt: Date.now()
      }
    },
    bankEntries: {
      5: {
        entry: {
          id: '100'
        },
        entryType: 'Item'
      },
      6: {
        entry: {
          id: '101'
        },
        entryType: 'Stimulus'
      }
    },
    items: {
      100: {
        id: '100'
      }
    },
    stimuli: {
      101: {
        id: '101'
      }
    },
    tagAssociations: {
      Item: {
        100: (0, _immutable.fromJS)([{
          id: 1,
          tag_value: 'waldo'
        }])
      }
    }
  }), {
    bankId: '1',
    bankEntryId: '5',
    navigateToBanks: function navigateToBanks() {},
    navigateToBank: function navigateToBank() {}
  });
  var newItemTestbed = createTestbed(withContext(_index.default, {
    modifications: {
      bankEntries: {
        TEMPORARY_BANK_ENTRY: {
          entry: 'TEMPORARY_ITEM',
          entryType: 'Item'
        }
      }
    },
    banks: {
      1: {
        title: 'Very distinctive name',
        updatedAt: Date.now()
      }
    }
  }), {
    bankId: '1',
    bankEntryId: 'new',
    navigateToBanks: function navigateToBanks() {},
    navigateToBank: function navigateToBank() {}
  });
  var fakeState = (0, _immutable.fromJS)({
    items: {
      100: {
        id: '100'
      }
    },
    stimuli: {
      101: {
        id: '101'
      }
    }
  });
  beforeEach(function () {
    return (0, _reduxStore.setFakeStore)(fakeState);
  });
  afterEach(function () {
    return (0, _reduxStore.unsetFakeStore)();
  });
  var fetchStub = sinon.stub();
  useFakeFetching({
    dispatchStub: sinon.stub(),
    getStateStub: sinon.stub(),
    fetchStub: fetchStub
  });
  it('fetches records on mount', function () {
    connectedTestbed.render();
    expect(fetchStub.calledWith('/api/banks/1/bank_entries/5')).to.be.true();
  });
  it('finds bank in store', function () {
    connectedTestbed.render();
    expect(connectedTestbed.getText()).to.include('Very distinctive name');
  });
  it('renders item', function () {
    connectedTestbed.render();
    expect(connectedTestbed.getText()).to.include('Item 100');
  });
  it('renders new item', function () {
    newItemTestbed.render();
  });
  describe('with tagging', function () {
    (0, _featureCheck.withTestFeatures)(['item_bank_tagging']);
    it('renders tag', function () {
      connectedTestbed.render({
        bankEntryId: '5'
      });
      expect(connectedTestbed.getText()).to.include('waldo');
    });
  });
});