diff --git a/client/transactions/index.js b/client/transactions/index.js index c59f5a6a2fd..d673fea93b4 100644 --- a/client/transactions/index.js +++ b/client/transactions/index.js @@ -27,7 +27,7 @@ const headers = [ { key: 'risk_level', label: 'Risk Level', hiddenByDefault: true }, ]; -const TransactionsList = ( props ) => { +export const TransactionsList = ( props ) => { const { transactions, showPlaceholder } = props; const transactionsData = transactions.data || []; // Do not display table loading view if data is already available. diff --git a/client/transactions/test/__snapshots__/index.js.snap b/client/transactions/test/__snapshots__/index.js.snap index 1ad242e7be2..335f3bb55be 100644 --- a/client/transactions/test/__snapshots__/index.js.snap +++ b/client/transactions/test/__snapshots__/index.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Transactions page renders correctly 1`] = ` +exports[`Transactions list renders correctly 1`] = ` + – + , + "value": undefined, + }, + Object { + "display": null, + }, + Object { + "display": null, + }, + Object { + "display": null, + }, + Object { + "display": "$10.00", + "value": 10, + }, + Object { + "display": "$0.50", + "value": 0.5, + }, + Object { + "display": "$9.50", + "value": 9.5, + }, + Object { + "display": null, + }, + ], + Array [ + Object { + "display": "Nov 1, 2019 / 12:00AM", + "value": 1572580800000, + }, + Object { + "display": "Charge", + "value": "charge", + }, + Object { + "display": + visa + , + "value": "visa", + }, + Object { + "display": + – + , + "value": undefined, + }, + Object { + "display": "My name", + "value": "My name", + }, + Object { + "display": "a@b.com", + "value": "a@b.com", + }, + Object { + "display": "US", + "value": "US", + }, + Object { + "display": "$15.00", + "value": 15, + }, + Object { + "display": "$0.50", + "value": 0.5, + }, + Object { + "display": "$14.50", + "value": 14.5, + }, + Object { + "display": "Normal", + "value": "normal", + }, + ], + ] + } rowsPerPage={10} showMenu={true} title="Transactions" diff --git a/client/transactions/test/index.js b/client/transactions/test/index.js index 0b7fde5b423..4afff9c48c1 100644 --- a/client/transactions/test/index.js +++ b/client/transactions/test/index.js @@ -2,56 +2,61 @@ /** * External dependencies */ -import renderer from 'react-test-renderer'; -import { mount, shallow } from 'enzyme'; -import apiFetch from '@wordpress/api-fetch'; - -jest.mock( '@wordpress/api-fetch' ); +import { shallow } from 'enzyme'; /** * Internal dependencies */ -import TransactionsPage from '../'; +import { TransactionsList } from '../'; -describe( 'Transactions page', () => { +describe( 'Transactions list', () => { test( 'renders correctly', () => { - apiFetch.mockResolvedValue( { - data: [ - { - created: 1572590800, - type: 'refund', - amount: 1000, - fee: 50, - // available_on: 1573199200, - }, - { - created: 1572580800, - type: 'charge', - source: { - payment_method_details: { - card: { - brand: 'visa', - }, - }, - billing_details: { - name: 'My name', - email: 'a@b.com', - address: { - country: 'US', - }, - }, - outcome: { - risk_level: 'normal', - }, - }, - amount: 1500, - fee: 50, - // available_on: 1573189200, - }, - ], - } ); + const transactions = { + data: [ + { + created: 1572590800, + type: 'refund', + source: { + object: 'refund', + }, + amount: 1000, + fee: 50, + // available_on: 1573199200, + }, + { + created: 1572580800, + type: 'charge', + source: { + object: 'charge', + payment_method_details: { + card: { + brand: 'visa', + }, + }, + billing_details: { + name: 'My name', + email: 'a@b.com', + address: { + country: 'US', + }, + }, + outcome: { + risk_level: 'normal', + }, + }, + amount: 1500, + fee: 50, + // available_on: 1573189200, + }, + ], + }; - const tree = shallow( ); - expect( tree ).toMatchSnapshot(); + const list = shallow( + + ); + expect( list ).toMatchSnapshot(); } ); } ); diff --git a/tests/js/jest-global-setup.js b/tests/js/jest-global-setup.js new file mode 100644 index 00000000000..8e66f71c404 --- /dev/null +++ b/tests/js/jest-global-setup.js @@ -0,0 +1,5 @@ +/** @format **/ + +module.exports = async () => { + process.env.TZ = 'America/New_York'; +} diff --git a/tests/js/setup-globals.js b/tests/js/jest-test-file-setup.js similarity index 100% rename from tests/js/setup-globals.js rename to tests/js/jest-test-file-setup.js diff --git a/tests/js/jest.config.json b/tests/js/jest.config.json index d2f628691cd..514f61d0c13 100644 --- a/tests/js/jest.config.json +++ b/tests/js/jest.config.json @@ -2,10 +2,11 @@ "rootDir": "../../", "moduleDirectories": ["node_modules", "/client"], "moduleNameMapper": { - }, + }, + "globalSetup": "/tests/js/jest-global-setup.js", "setupFiles": [ "/node_modules/@wordpress/jest-preset-default/scripts/setup-globals.js", - "/tests/js/setup-globals" + "/tests/js/jest-test-file-setup.js" ], "preset": "@wordpress/jest-preset-default", "testPathIgnorePatterns": [