"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 _helpers = require("../../../helpers");
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 DICTIONARY = {
  'common.label.accommodation_type': '{type,select, =1 {room} =2 {apartment} =3 {pitch} =4 {accommodation} other {villa}}',
  'common.label.accommodation_type_plural': '{type,select, =1 {Rooms} =2 {Apartments} =3 {Pitches} =4 {Accommodations} other {Villas}}'
};
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 = _ref.children,
    _ref$value = _ref.value,
    value = _ref$value === void 0 ? {} : _ref$value;
  return /*#__PURE__*/_react2.default.createElement(_dataSources.StoreProvider, {
    value: value
  }, children);
};
describe('<BookingSummary>', () => {
  it('renders', async () => {
    const _render = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_locale.LocaleProvider, null, /*#__PURE__*/_react2.default.createElement(_BookingSummary.BookingSummary, DEFAULTS))),
      asFragment = _render.asFragment;
    expect(asFragment()).toMatchSnapshot();
  });
  it('with a store', async () => {
    const _render2 = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(Store, null, /*#__PURE__*/_react2.default.createElement(_locale.LocaleProvider, null, /*#__PURE__*/_react2.default.createElement(_BookingSummary.BookingSummary, DEFAULTS)))),
      asFragment = _render2.asFragment;
    expect(asFragment()).toMatchSnapshot();
  });
  it('uses hotel accommodation type in booking details', async () => {
    const _render3 = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(Store, {
        value: {
          hotel: {
            accommodationType: _helpers.ACCOMMODATION_TYPE.VILLA
          }
        }
      }, /*#__PURE__*/_react2.default.createElement(_locale.LocaleProvider, {
        dictionary: DICTIONARY
      }, /*#__PURE__*/_react2.default.createElement(_BookingSummary.BookingSummary, DEFAULTS)))),
      container = _render3.container;
    expect(container.textContent).toContain('1 villa');
    expect(container.textContent).not.toContain('1 room');
  });
  it('uses variant lodging denomination in booking details', async () => {
    const _render4 = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(Store, {
        value: {
          hotel: {
            accommodationType: _helpers.ACCOMMODATION_TYPE.ROOM,
            id: 'villa-hotel',
            variants: {
              'villa-hotel': {
                accommodationType: _helpers.ACCOMMODATION_TYPE.APARTMENT
              }
            }
          }
        }
      }, /*#__PURE__*/_react2.default.createElement(_locale.LocaleProvider, {
        dictionary: DICTIONARY
      }, /*#__PURE__*/_react2.default.createElement(_BookingSummary.BookingSummary, DEFAULTS)))),
      container = _render4.container;
    expect(container.textContent).toContain('1 apartment');
    expect(container.textContent).not.toContain('1 room');
    expect(container.textContent).not.toContain('1 villa');
  });
  it('uses individual lodging denomination in booking details', async () => {
    const _render5 = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(Store, {
        value: {
          hotel: {
            accommodationType: _helpers.ACCOMMODATION_TYPE.VILLA
          }
        }
      }, /*#__PURE__*/_react2.default.createElement(_locale.LocaleProvider, {
        dictionary: DICTIONARY
      }, /*#__PURE__*/_react2.default.createElement(_BookingSummary.BookingSummary, DEFAULTS)))),
      container = _render5.container;
    expect(container.textContent).toContain('1 villa');
    expect(container.textContent).not.toContain('1 room');
  });
  it('renders booking details', async () => {
    const _render6 = (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
      })))),
      asFragment = _render6.asFragment,
      container = _render6.container,
      getByText = _render6.getByText;
    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.accommodationtypeplural');
    expect(container.textContent).toContain('core.label.extracount');
    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 _render7 = (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: []
        })
      })))),
      container = _render7.container,
      getByText = _render7.getByText,
      queryByText = _render7.queryByText;
    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 _render8 = (0, _react.render)(/*#__PURE__*/_react2.default.createElement(_locale.LocaleProvider, null, /*#__PURE__*/_react2.default.createElement(_BookingSummary.BookingSummary, _extends({}, DEFAULTS, {
        testId: "mirai"
      })))),
      asFragment = _render8.asFragment,
      getByTestId = _render8.getByTestId;
    expect(getByTestId('mirai')).toBeDefined();
    expect(asFragment()).toMatchSnapshot();
  });

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