2020-10-22 22:13:14 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { render, fireEvent } from '@testing-library/react';
|
|
|
|
import { useUserPreferences } from '@woocommerce/data';
|
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { DisplayOptions } from '../';
|
|
|
|
|
|
|
|
jest.mock( '@woocommerce/tracks', () => ( { recordEvent: jest.fn() } ) );
|
|
|
|
jest.mock( '@woocommerce/data', () => ( {
|
|
|
|
...jest.requireActual( '@woocommerce/data' ),
|
|
|
|
useUserPreferences: jest
|
|
|
|
.fn()
|
|
|
|
.mockReturnValue( { updateUserPreferences: jest.fn() } ),
|
|
|
|
} ) );
|
2021-11-15 20:57:13 +00:00
|
|
|
jest.mock( '@wordpress/data', () => {
|
|
|
|
const originalModule = jest.requireActual( '@wordpress/data' );
|
|
|
|
|
|
|
|
return {
|
|
|
|
__esModule: true,
|
|
|
|
...originalModule,
|
|
|
|
useSelect: jest.fn().mockReturnValue( {
|
|
|
|
defaultHomescreenLayout: 'single_column',
|
|
|
|
taskListComplete: false,
|
|
|
|
isTaskListHidde: false,
|
|
|
|
} ),
|
|
|
|
};
|
|
|
|
} );
|
2020-10-22 22:13:14 +00:00
|
|
|
|
|
|
|
describe( 'Activity Panel - Homescreen Display Options', () => {
|
|
|
|
it( 'correctly tracks opening the options', () => {
|
|
|
|
const { getByRole } = render( <DisplayOptions /> );
|
|
|
|
|
|
|
|
fireEvent.click( getByRole( 'button', { name: 'Display options' } ) );
|
|
|
|
|
|
|
|
expect( recordEvent ).toHaveBeenCalledWith(
|
|
|
|
'homescreen_display_click'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'correctly updates the homepage layout option', () => {
|
|
|
|
const updateUserPreferences = jest.fn();
|
|
|
|
useUserPreferences.mockReturnValue( {
|
|
|
|
updateUserPreferences,
|
|
|
|
homepage_layout: '',
|
|
|
|
} );
|
|
|
|
const { getByText, getByRole } = render( <DisplayOptions /> );
|
|
|
|
|
|
|
|
fireEvent.click( getByRole( 'button', { name: 'Display options' } ) );
|
|
|
|
|
|
|
|
// Verify the default of two columns.
|
|
|
|
expect(
|
|
|
|
getByText( 'Single column', { selector: 'button' } )
|
2020-11-06 17:53:03 +00:00
|
|
|
).toBeChecked();
|
2020-10-22 22:13:14 +00:00
|
|
|
expect(
|
|
|
|
getByText( 'Two columns', { selector: 'button' } )
|
2020-11-06 17:53:03 +00:00
|
|
|
).not.toBeChecked();
|
2020-10-22 22:13:14 +00:00
|
|
|
|
2020-11-06 17:53:03 +00:00
|
|
|
fireEvent.click( getByText( 'Two columns', { selector: 'button' } ) );
|
2020-10-22 22:13:14 +00:00
|
|
|
|
|
|
|
expect( recordEvent ).toHaveBeenCalledWith(
|
|
|
|
'homescreen_display_option',
|
|
|
|
{
|
2020-11-06 17:53:03 +00:00
|
|
|
display_option: 'two_columns',
|
2020-10-22 22:13:14 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
expect( updateUserPreferences ).toHaveBeenCalledWith( {
|
2020-11-06 17:53:03 +00:00
|
|
|
homepage_layout: 'two_columns',
|
2020-10-22 22:13:14 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|