2020-11-06 01:21:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* External dependencies
|
|
|
|
|
*/
|
|
|
|
|
import { render, screen } from '@testing-library/react';
|
2021-07-23 12:47:23 +00:00
|
|
|
|
import { useSelect } from '@wordpress/data';
|
2023-05-10 12:36:42 +00:00
|
|
|
|
import userEvent from '@testing-library/user-event';
|
|
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
2020-11-06 01:21:05 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Internal dependencies
|
|
|
|
|
*/
|
|
|
|
|
import OrdersPanel from '../';
|
|
|
|
|
|
2021-07-23 12:47:23 +00:00
|
|
|
|
jest.mock( '@wordpress/data', () => {
|
|
|
|
|
// Require the original module to not be mocked...
|
|
|
|
|
const originalModule = jest.requireActual( '@wordpress/data' );
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
__esModule: true, // Use it when dealing with esModules
|
|
|
|
|
...originalModule,
|
|
|
|
|
useSelect: jest.fn().mockReturnValue( {} ),
|
|
|
|
|
};
|
|
|
|
|
} );
|
|
|
|
|
|
2024-01-19 04:20:36 +00:00
|
|
|
|
jest.mock( '~/utils/admin-settings', () => ( {
|
|
|
|
|
...jest.requireActual( '~/utils/admin-settings' ),
|
|
|
|
|
getAdminSetting: jest.fn().mockReturnValue( {
|
|
|
|
|
currencySymbols: {
|
|
|
|
|
EUR: '€',
|
|
|
|
|
USD: '$',
|
|
|
|
|
},
|
|
|
|
|
} ),
|
|
|
|
|
} ) );
|
|
|
|
|
|
|
|
|
|
jest.mock( '@woocommerce/settings', () => ( {
|
|
|
|
|
...jest.requireActual( '@woocommerce/settings' ),
|
|
|
|
|
getAdminLink: jest.fn().mockReturnValue( '' ),
|
|
|
|
|
} ) );
|
|
|
|
|
|
2020-11-06 01:21:05 +00:00
|
|
|
|
describe( 'OrdersPanel', () => {
|
|
|
|
|
it( 'should render an empty order card', () => {
|
2021-07-23 12:47:23 +00:00
|
|
|
|
useSelect.mockReturnValue( {
|
|
|
|
|
orders: [],
|
|
|
|
|
isError: false,
|
|
|
|
|
isRequesting: false,
|
|
|
|
|
} );
|
2022-01-19 16:45:17 +00:00
|
|
|
|
render( <OrdersPanel orderStatuses={ [] } unreadOrdersCount={ 0 } /> );
|
2020-11-06 01:21:05 +00:00
|
|
|
|
expect(
|
|
|
|
|
screen.queryByText( 'You’ve fulfilled all your orders' )
|
|
|
|
|
).toBeInTheDocument();
|
|
|
|
|
} );
|
2024-01-19 04:20:36 +00:00
|
|
|
|
|
2023-05-10 12:36:42 +00:00
|
|
|
|
it( 'should record activity_panel_orders_orders_begin_fulfillment Tracks event when order is clicked', () => {
|
|
|
|
|
useSelect.mockReturnValue( {
|
|
|
|
|
orders: [
|
|
|
|
|
{
|
|
|
|
|
total: 123,
|
|
|
|
|
id: 1,
|
|
|
|
|
number: 1,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
isError: false,
|
|
|
|
|
isRequesting: false,
|
|
|
|
|
} );
|
|
|
|
|
const { getByText } = render(
|
|
|
|
|
<OrdersPanel orderStatuses={ [] } unreadOrdersCount={ 1 } />
|
|
|
|
|
);
|
|
|
|
|
userEvent.click( getByText( '0 products' ) );
|
|
|
|
|
expect( recordEvent ).toHaveBeenCalledWith(
|
|
|
|
|
'activity_panel_orders_orders_begin_fulfillment',
|
|
|
|
|
{}
|
|
|
|
|
);
|
|
|
|
|
} );
|
2024-01-19 04:20:36 +00:00
|
|
|
|
|
|
|
|
|
it( 'should format order total correctly with the same currency as store currency', () => {
|
|
|
|
|
useSelect.mockReturnValue( {
|
|
|
|
|
orders: [
|
|
|
|
|
{
|
|
|
|
|
total: 123,
|
|
|
|
|
id: 1,
|
|
|
|
|
number: 1,
|
|
|
|
|
currency: 'USD',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
isError: false,
|
|
|
|
|
isRequesting: false,
|
|
|
|
|
} );
|
|
|
|
|
const { getByText } = render(
|
|
|
|
|
<OrdersPanel orderStatuses={ [] } unreadOrdersCount={ 1 } />
|
|
|
|
|
);
|
|
|
|
|
expect( getByText( '$123.00' ) ).toBeInTheDocument();
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
it( 'should show order total correctly with a different currency from store currency', () => {
|
|
|
|
|
useSelect.mockReturnValue( {
|
|
|
|
|
orders: [
|
|
|
|
|
{
|
|
|
|
|
total: 123,
|
|
|
|
|
id: 1,
|
|
|
|
|
number: 1,
|
|
|
|
|
currency: 'EUR',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
isError: false,
|
|
|
|
|
isRequesting: false,
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
const { getByText } = render(
|
|
|
|
|
<OrdersPanel orderStatuses={ [] } unreadOrdersCount={ 1 } />
|
|
|
|
|
);
|
|
|
|
|
expect( getByText( '€123.00' ) ).toBeInTheDocument();
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
it( 'should show order total correctly with a currency not in currencySymbols', () => {
|
|
|
|
|
useSelect.mockReturnValue( {
|
|
|
|
|
orders: [
|
|
|
|
|
{
|
|
|
|
|
total: 123,
|
|
|
|
|
id: 1,
|
|
|
|
|
number: 1,
|
|
|
|
|
currency: 'BTC',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
isError: false,
|
|
|
|
|
isRequesting: false,
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
const { getByText } = render(
|
|
|
|
|
<OrdersPanel orderStatuses={ [] } unreadOrdersCount={ 1 } />
|
|
|
|
|
);
|
|
|
|
|
expect( getByText( 'BTC123' ) ).toBeInTheDocument();
|
|
|
|
|
} );
|
2020-11-06 01:21:05 +00:00
|
|
|
|
} );
|