Skip to content

Commit

Permalink
test: Add test and snapshot for ReceiptPage
Browse files Browse the repository at this point in the history
  • Loading branch information
julianajlk committed Jul 27, 2022
1 parent 4287db8 commit 46f483b
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/receipt/ReceiptPage.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react';
import { mount } from 'enzyme';
import { Provider } from 'react-redux';
import configureMockStore from 'redux-mock-store';
import { createMemoryHistory } from 'history';

import { IntlProvider } from '@edx/frontend-platform/i18n';

import ConnectedReceiptPage from './ReceiptPage';

const mockStore = configureMockStore();
const storeMocks = {
// eslint-disable-next-line global-require
ordersLoaded: require('./__mocks__/orderLoaded.mockStore.js'),
};
const requiredReceiptPageProps = {
fetchOrders: () => {},
};

describe('<ReceiptPage />', () => {
describe('Renders correctly', () => {
it('should render receipt page for an order', () => {
const mockHistory = createMemoryHistory('/receipt');

const renderedComponent = mount(
<IntlProvider locale="en">
<Provider store={mockStore(storeMocks.orderLoaded)}>
<ConnectedReceiptPage {...requiredReceiptPageProps} history={mockHistory} />
</Provider>
</IntlProvider>,
);
expect(renderedComponent).toMatchSnapshot();
});
});
});
91 changes: 91 additions & 0 deletions src/receipt/__mocks__/orderLoaded.mockStore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
module.exports = {
receipt: {
loadingReceipt: false,
loadingReceiptError: null,
order: {
basket_discounts: [
{
amount: 14.9,
benefit_value: 10,
code: "12345",
condition_name: "Cart includes 1 item(s) from range for coupon [14]",
contains_offer: true,
currency: "USD",
enterprise_customer_name: null,
offer_type: "Voucher",
}
],
billing_address: {
city: "Cambridge",
country: "US",
first_name: "Juliana",
last_name: "TEST",
line1: "123 Main Street",
line2: "",
postcode: "12346",
state: "CA",
},
currency: "USD",
dashboard_url: "http://edx.devstack.lms:18000/dashboard",
date_placed: "2022-06-21T16:43:02Z",
discount: "14.90",
enable_hoist_order_history: false,
enterprise_customer_info: null,
lines: [
{
title: 'Seat in edX Demonstration Course with verified certificate',
quantity: 1,
description: 'Seat in edX Demonstration Course with verified certificate',
line_price_excl_tax: "134.10",
product: {
expires: "2023-05-06T21:19:31.037600Z",
id: 3,
is_available_to_buy: true,
is_enrollment_code_product: false,
price: "149.00",
product_class: "Seat",
title: "Seat in edX Demonstration Course with verified certificate",
url: "http://localhost:18130/api/v2/products/",
},
quantity: 1,
status: "Complete",
title: "Seat in edX Demonstration Course with verified certificate",
unit_price_excl_tax: "149.00",
number: "EDX-100005",
offer_condition_name: null,
order_product_ids: "3",
payment_method: "Visa 411111XXXXXX1111",
payment_processor: "cybersource-rest",
status: "Complete",
total_before_discounts_incl_tax: "149.00",
total_excl_tax: "134.10",
user: {
email: "[email protected]",
username: "edx",
},
vouchers: [
{
benefit: {
type: 'Percentage',
value: 10
},
code: "12345",
date_created: "2022-06-21T16:27:31.294837Z",
end_datetime: "2024-04-01T00:00:00Z",
id: 2,
is_available_to_user: (2) [true, ''],
is_public: false,
num_basket_additions: 1,
num_orders: 1,
redeem_url: "http://localhost:18130/coupons/offer/?code=12345",
start_datetime: "2022-06-21T00:00:00Z",
total_discount: "14.90",
usage: "Multi-use",
}
],
}
],
},
}
};

7 changes: 7 additions & 0 deletions src/receipt/__snapshots__/ReceiptPage.test.jsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<ReceiptPage /> Renders correctly should render receipt page for an order 1`] = `
ReactWrapper {
"length": 1,
}
`;

0 comments on commit 46f483b

Please sign in to comment.