flex-template-web/src/components/BookingBreakdown/BookingBreakdown.test.js
2017-09-05 15:40:28 +03:00

119 lines
3.4 KiB
JavaScript

import React from 'react';
import Decimal from 'decimal.js';
import { fakeIntl } from '../../util/test-data';
import { renderDeep } from '../../util/test-helpers';
import { types } from '../../util/sdkLoader';
import * as propTypes from '../../util/propTypes';
import { BookingBreakdownComponent } from './BookingBreakdown';
const { UUID, Money } = types;
const exampleBooking = attributes => {
return {
id: new UUID('example-booking'),
type: 'booking',
attributes,
};
};
const exampleTransaction = params => {
const created = new Date(Date.UTC(2017, 1, 1));
return {
id: new UUID('example-transaction'),
type: 'transaction',
attributes: {
createdAt: created,
lastTransitionedAt: created,
lastTransition: propTypes.TX_TRANSITION_PREAUTHORIZE,
state: propTypes.TX_STATE_PREAUTHORIZED,
// payinTotal, payoutTotal, and lineItems required in params
...params,
},
};
};
describe('BookingBreakdown', () => {
it('pretransaction data matches snapshot', () => {
const tree = renderDeep(
<BookingBreakdownComponent
userRole="customer"
transaction={exampleTransaction({
payinTotal: new Money(2000, 'USD'),
payoutTotal: new Money(2000, 'USD'),
lineItems: [
{
code: 'line-item/night',
quantity: new Decimal(2),
lineTotal: new Money(2000, 'USD'),
unitPrice: new Money(1000, 'USD'),
},
],
})}
booking={exampleBooking({
start: new Date(Date.UTC(2017, 3, 14)),
end: new Date(Date.UTC(2017, 3, 16)),
})}
intl={fakeIntl}
/>
);
expect(tree).toMatchSnapshot();
});
it('customer transaction data matches snapshot', () => {
const tree = renderDeep(
<BookingBreakdownComponent
userRole="customer"
transaction={exampleTransaction({
payinTotal: new Money(2000, 'USD'),
payoutTotal: new Money(2000, 'USD'),
lineItems: [
{
code: 'line-item/night',
quantity: new Decimal(2),
lineTotal: new Money(2000, 'USD'),
unitPrice: new Money(1000, 'USD'),
},
],
})}
booking={exampleBooking({
start: new Date(Date.UTC(2017, 3, 14)),
end: new Date(Date.UTC(2017, 3, 16)),
})}
intl={fakeIntl}
/>
);
expect(tree).toMatchSnapshot();
});
it('provider transaction data matches snapshot', () => {
const tree = renderDeep(
<BookingBreakdownComponent
userRole="provider"
transaction={exampleTransaction({
payinTotal: new Money(2000, 'USD'),
payoutTotal: new Money(1800, 'USD'),
lineItems: [
{
code: 'line-item/night',
quantity: new Decimal(2),
lineTotal: new Money(2000, 'USD'),
unitPrice: new Money(1000, 'USD'),
},
{
code: 'line-item/provider-commission',
lineTotal: new Money(-200, 'USD'),
unitPrice: new Money(-200, 'USD'),
},
],
})}
booking={exampleBooking({
start: new Date(Date.UTC(2017, 3, 14)),
end: new Date(Date.UTC(2017, 3, 16)),
})}
intl={fakeIntl}
/>
);
expect(tree).toMatchSnapshot();
});
});