"use strict";

var _dataSources = require("@mirai/data-sources");
var _locale = require("@mirai/locale");
var _react = require("@testing-library/react");
var _react2 = _interopRequireDefault(require("react"));
var _checkout = _interopRequireDefault(require("../../../Checkout/mocks/checkout.json"));
var _BookingSummary = require("../BookingSummary");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /* eslint-disable react/prop-types */
const DEFAULTS = {
  dataSource: _checkout.default
};
const BOOKING_DATASOURCE = _objectSpread(_objectSpread({}, _checkout.default), {}, {
  cancellationPolicy: {
    caption: 'Until May 18',
    name: 'Free cancellation'
  },
  details: [_objectSpread(_objectSpread({}, _checkout.default.details[0]), {}, {
    amount: 1,
    extras: [{
      title: 'Extra name'
    }],
    occupation: {
      adults: 1,
      babies: 0,
      children: 1
    },
    type: 'Room name 1'
  }), _objectSpread(_objectSpread({}, _checkout.default.details[0]), {}, {
    amount: 1,
    extras: [],
    occupation: {
      adults: 1,
      babies: 1,
      children: 0
    },
    type: 'Room name 1'
  }), _objectSpread(_objectSpread({}, _checkout.default.details[0]), {}, {
    amount: 1,
    extras: [],
    occupation: {
      adults: 1,
      babies: 0,
      children: 0
    },
    type: 'Room name 2'
  })],
  extras: [{
    title: 'Global extra name'
  }],
  nights: 2
});
const Store = _ref => {
  let {
    children,
    value = {}
  } = _ref;
  return /*#__PURE__*/_react2.default.createElement(_dataSources.StoreProvider, {
    value: value
  }, children);
};
describe('<BookingSummary>', () => {
  it('renders', async () => {
    const {
      asFragment
    } = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_locale.LocaleProvider, null, /*#__PURE__*/_react2.default.createElement(_BookingSummary.BookingSummary, DEFAULTS)));
    expect(asFragment()).toMatchSnapshot();
  });
  it('with a store', async () => {
    const {
      asFragment
    } = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(Store, null, /*#__PURE__*/_react2.default.createElement(_locale.LocaleProvider, null, /*#__PURE__*/_react2.default.createElement(_BookingSummary.BookingSummary, DEFAULTS))));
    expect(asFragment()).toMatchSnapshot();
  });
  it('renders booking details', async () => {
    const {
      asFragment,
      container,
      getByText
    } = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(Store, null, /*#__PURE__*/_react2.default.createElement(_locale.LocaleProvider, null, /*#__PURE__*/_react2.default.createElement(_BookingSummary.BookingSummary, {
      dataSource: BOOKING_DATASOURCE
    }))));
    expect(getByText('core.label.your_booking')).toBeDefined();
    expect(getByText('Room name 1 (x2), Room name 2')).toBeDefined();
    expect(getByText('Extra name, Global extra name')).toBeDefined();
    expect(getByText('Free cancellation')).toBeDefined();
    expect(getByText('Until May 18')).toBeDefined();
    expect(container.textContent).toContain('common.label.nightcount');
    expect(container.textContent).toContain('common.label.roomcount');
    expect(container.textContent).toContain('label.extra_count');
    expect(container.textContent).toContain('common.label.guesttypeplural');
    expect(container.textContent).toContain('common.label.guesttype');
    expect(asFragment()).toMatchSnapshot();
  });
  it('renders without optional extras and cancellation', async () => {
    const {
      container,
      getByText,
      queryByText
    } = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(Store, null, /*#__PURE__*/_react2.default.createElement(_locale.LocaleProvider, null, /*#__PURE__*/_react2.default.createElement(_BookingSummary.BookingSummary, {
      dataSource: _objectSpread(_objectSpread({}, _checkout.default), {}, {
        cancellation: undefined,
        extras: []
      })
    }))));
    expect(getByText('core.label.your_booking')).toBeDefined();
    expect(container.textContent).not.toContain('extra_count');
    expect(container.textContent).not.toContain('0 common.label.guest');
    expect(queryByText('Free cancellation')).toBeNull();
  });

  // Testing
  it('testID', async () => {
    const {
      asFragment,
      getByTestId
    } = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_locale.LocaleProvider, null, /*#__PURE__*/_react2.default.createElement(_BookingSummary.BookingSummary, _extends({}, DEFAULTS, {
      testId: "mirai"
    }))));
    expect(getByTestId('mirai')).toBeDefined();
    expect(asFragment()).toMatchSnapshot();
  });

  // Styling
  it('inherit:className', async () => {
    const {
      asFragment
    } = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_locale.LocaleProvider, null, /*#__PURE__*/_react2.default.createElement(_BookingSummary.BookingSummary, _extends({}, DEFAULTS, {
      className: "mirai"
    }))));
    expect(asFragment()).toMatchSnapshot();
  });
});
//# sourceMappingURL=BookingSummary.test.js.map