@kiwicom/smart-faq
Version:
130 lines (115 loc) • 3.98 kB
JavaScript
// @flow
import * as React from 'react';
import MockDate from 'mockdate';
import { shallow } from 'enzyme';
import { RawBookingDetail } from '../BookingDetail';
import Notification from '../bookingItem/Notification';
import featureToggles from '../../../feature-toggles.json';
beforeEach(() => MockDate.set('06/01/2018 00:00:00'));
afterEach(() => MockDate.reset());
const mockRefType: any = null;
const createBookingStub = (outboundDate, inboundDate) => ({
$refType: mockRefType,
$fragmentRefs: mockRefType,
outbound: {
departure: {
time: new Date(outboundDate),
},
},
isPastBooking: new Date() > new Date(inboundDate),
directAccessURL: 'https://example.com/asd',
type: 'BookingReturn',
status: 'CONFIRMED',
assets: null,
availableServices: null,
});
const defaults = {
log: jest.fn(),
onSetFAQSection: jest.fn(),
// $FlowExpectedError: we don't need all
history: {
push: jest.fn(),
},
};
describe('BookingDetail >', () => {
if (featureToggles.notification) {
describe('Notification', () => {
it('is displayed before the departure', () => {
const booking = createBookingStub('06/12/2018', '06/19/2018');
const wrapper = shallow(
<RawBookingDetail {...defaults} booking={booking} />,
);
expect(wrapper.find(Notification).exists()).toBeTruthy();
});
it('is not displayed after the departure', () => {
const booking = createBookingStub('05/01/2017', '05/19/2017');
const wrapper = shallow(
<RawBookingDetail {...defaults} booking={booking} />,
);
expect(wrapper.find(Notification).exists()).toBeFalsy();
});
it('has prop isUrgent true when there is less than 48 before departure', () => {
const booking48HoursAgo = createBookingStub('06/02/2018', '06/19/2018');
const wrapper = shallow(
<RawBookingDetail {...defaults} booking={booking48HoursAgo} />,
);
expect(wrapper.find(Notification).props().isUrgent).toBeTruthy();
});
[
'REFUNDED',
'PENDING',
'CANCELLED',
'DELETED',
'CLOSED',
'EXPIRED',
].forEach(status =>
it(`is not displayed for booking with ${status} status`, () => {
const booking48HoursAgo = createBookingStub(
'06/02/2018',
'06/19/2018',
);
const refundedBooking = { ...booking48HoursAgo, status };
const wrapper = shallow(
<RawBookingDetail {...defaults} booking={refundedBooking} />,
);
expect(wrapper.find(Notification).exists()).toBeFalsy();
}),
);
});
}
it('has prop isFuture true when inbound flight is in future and outbound flight date already passed', () => {
const bookingBetweenDepartureAndArrival = createBookingStub(
'05/02/2018',
'06/19/2018',
);
const wrapper = shallow(
<RawBookingDetail
{...defaults}
booking={bookingBetweenDepartureAndArrival}
/>,
);
expect(wrapper.find('[data-test="upcoming"]').exists()).toBeTruthy();
});
describe('Contact', () => {
it('is displayed when there is less than 48 before departure', () => {
const booking48HoursAgo = createBookingStub('06/02/2018', '06/19/2018');
const wrapper = shallow(
<RawBookingDetail {...defaults} booking={booking48HoursAgo} />,
);
expect(wrapper.find('[dataTest="contact"]').exists()).toBeTruthy();
});
it('displayed when inbound flight is in future and outbound flight date already passed', () => {
const bookingBetweenDepartureAndArrival = createBookingStub(
'05/02/2018',
'06/19/2018',
);
const wrapper = shallow(
<RawBookingDetail
{...defaults}
booking={bookingBetweenDepartureAndArrival}
/>,
);
expect(wrapper.find('[dataTest="contact"]').exists()).toBeTruthy();
});
});
});