woocommerce/plugins/woocommerce-admin/client/activity-panel/test/index.js

412 lines
10 KiB
JavaScript
Raw Normal View History

/**
* External dependencies
*/
import {
render,
screen,
fireEvent,
act,
createEvent,
} from '@testing-library/react';
import { useSelect } from '@wordpress/data';
import { useUser } from '@woocommerce/data';
import { useState } from '@wordpress/element';
/**
* Internal dependencies
*/
import { ActivityPanel } from '../activity-panel';
import { Panel } from '../panel';
jest.mock( '@woocommerce/admin-layout', () => {
const mockContext = {
layoutPath: [ 'home' ],
layoutString: 'home',
extendLayout: () => {},
isDescendantOf: () => false,
};
return {
...jest.requireActual( '@woocommerce/admin-layout' ),
useLayoutContext: jest.fn().mockReturnValue( mockContext ),
useExtendLayout: jest.fn().mockReturnValue( mockContext ),
};
} );
jest.mock( '~/launch-your-store', () => ( {
useLaunchYourStore: jest.fn( () => ( {
comingSoon: 'yes',
launchYourStoreEnabled: true,
isLoading: true,
} ) ),
} ) );
jest.mock( '@woocommerce/data', () => ( {
...jest.requireActual( '@woocommerce/data' ),
useUser: jest.fn().mockReturnValue( { currentUserCan: () => true } ),
useUserPreferences: jest.fn().mockReturnValue( {
updateUserPreferences: () => {},
} ),
} ) );
// We aren't testing the <DisplayOptions /> component here.
jest.mock( '../display-options', () => ( {
DisplayOptions: jest.fn().mockReturnValue( '[DisplayOptions]' ),
} ) );
jest.mock( '../highlight-tooltip', () => ( {
HighlightTooltip: jest.fn().mockReturnValue( '[HighlightTooltip]' ),
} ) );
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( {} ),
};
} );
jest.mock( '../panel', () => {
const originalModule = jest.requireActual( '../panel' );
return {
__esModule: true,
...originalModule,
Panel: jest.fn(),
};
} );
describe( 'Activity Panel', () => {
beforeEach( () => {
useSelect.mockImplementation( () => ( {
Show task and activity notifications in the Inbox panel (https://github.com/woocommerce/woocommerce-admin/pull/7017) * Added abbreviated panels This commit adds abbreviated panels * Added notifications getter * Variables renamed * Added unread-indicators refactor * Open panel by default * Refactor unread-indicators * Renamed a few files and added event recording * Modified "critical alert" presentation * Removed useless control * Renamed const * Added control to InboxPanel component * Multiple critical alerts handling * Fixed styles * Moved Inbox panel styles # Conflicts: # packages/experimental/src/inbox-note/style.scss * Added tests * Inbox panel width reduced * Small refactor for unread notifications * Renamed abbreviated card component * Added changelog # Conflicts: # readme.txt # Conflicts: # readme.txt * Renamed inbox-panel and the cards config file * Renamed unread notifications variable * Fixed abbreviated card box-shadow * Small refactor to unread-indicators file * Refactored method getInitialState * Added scroll to task list # Conflicts: # client/task-list/task-list.js * Small CSS changes to titles * Fixed changelog # Conflicts: # readme.txt # Conflicts: # readme.txt * Added param to filter `woocommerce_admin_onboarding_task_list` * Removed extensibility from `getAbbreviatedNotifications` * Fixed chunk name * Removed `critical` prop from `AbbreviatedCard` comopnent * Moved AbbreviatedCard component to `packages` This commit moves the component `AbbreviatedCard` to `packages` # Conflicts: # docs/components/_sidebar.md # packages/components/CHANGELOG.md # packages/components/src/index.js # Conflicts: # packages/components/CHANGELOG.md * Removed `critical alerts` tag from abbreviated card This commit removes the tag `critical alerts` from the `Things to do next` abbreviated card * Removed filter `woocommerce_admin_abbreviated_card_list` * Fixed icon * Added defaut value to `hasUnreadNotifications` * Fix mapSelect error when the dismissed tasks option isn't populated. * Added AbbreviatedNotificationsPanel * Added tests * Renamed `getUnreadNotes` to `isNotesPanelVisible` * Removed abbreviated-card.js * Added singular/plural copy handling * Renamed method `getInitialState` to `getInitialOpenState` * Fixed Link prop * Revert "Fixed Link prop" This reverts commit 74e6a7fae030766eb5d6be098caa15478f2cb2c6. * Fixed Link prop * Added task list visibility check * Fixed scroll after redirect # Conflicts: # client/task-list/index.js * Added propType to `AbbreviatedCard` * Fixed `Add-task doc example * Removed default values from ActivityPanel * Fixed multiple calls to a filter Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com> Co-authored-by: Jeff Stieler <jeff.m.stieler@gmail.com>
2021-06-09 13:56:45 +00:00
hasUnreadNotifications: false,
requestingTaskListOptions: false,
setupTaskListComplete: false,
setupTaskListHidden: false,
trackedCompletedTasks: [],
} ) );
Panel.mockImplementation( jest.requireActual( '../panel' ).Panel );
useUser.mockImplementation( () => ( {
currentUserCan: () => true,
} ) );
} );
it( 'should render inbox tab on embedded pages', () => {
render( <ActivityPanel isEmbedded query={ {} } /> );
expect( screen.getByText( 'Activity' ) ).toBeDefined();
} );
it( 'should render inbox tab if not on home screen', () => {
render(
<ActivityPanel query={ { page: 'wc-admin', path: '/customers' } } />
);
expect( screen.getByText( 'Activity' ) ).toBeDefined();
} );
it( 'should not render inbox tab on home screen', () => {
render( <ActivityPanel query={ { page: 'wc-admin' } } /> );
expect( screen.queryByText( 'Inbox' ) ).toBeNull();
} );
2022-04-22 13:53:46 +00:00
it( 'should render preview store tab on home screen', () => {
2022-04-22 13:09:32 +00:00
render( <ActivityPanel query={ { page: 'wc-admin' } } /> );
expect( screen.getByText( 'Preview store' ) ).toBeDefined();
} );
it( 'should not render help tab if not on home screen', () => {
render(
<ActivityPanel query={ { page: 'wc-admin', path: '/customers' } } />
);
expect( screen.queryByTestId( 'activity-panel-tab-help' ) ).toBeNull();
} );
it( 'should render help tab if on home screen', () => {
render( <ActivityPanel query={ { page: 'wc-admin' } } /> );
expect(
screen.queryByTestId( 'activity-panel-tab-help' )
).toBeDefined();
} );
it( 'should render help tab before options load', async () => {
useSelect.mockImplementation( () => ( {
requestingTaskListOptions: true,
} ) );
render(
<ActivityPanel
query={ {
task: 'products',
} }
/>
);
const tabs = await screen.findAllByRole( 'tab' );
// Expect that the only tab is "Help".
expect( tabs ).toHaveLength( 1 );
expect(
screen.queryByTestId( 'activity-panel-tab-help' )
).toBeDefined();
} );
it( 'should not render help tab when not on main route', () => {
render(
<ActivityPanel
query={ {
page: 'wc-admin',
task: 'products',
path: '/customers',
} }
/>
);
// Expect that "Help" tab is absent.
expect( screen.queryByText( 'Help' ) ).toBeNull();
} );
it( 'should render display options if on home screen', () => {
render(
<ActivityPanel
query={ {
page: 'wc-admin',
} }
/>
);
expect( screen.getByText( '[DisplayOptions]' ) ).toBeDefined();
} );
it( 'should only render the finish setup link when TaskList is not complete', () => {
const { queryByText, rerender } = render(
<ActivityPanel
query={ {
task: 'products',
} }
/>
);
expect( queryByText( 'Finish setup' ) ).toBeDefined();
useSelect.mockImplementation( () => ( {
requestingTaskListOptions: false,
setupTaskListComplete: true,
setupTaskListHidden: false,
} ) );
rerender(
<ActivityPanel
query={ {
task: 'products',
} }
/>
);
expect( queryByText( 'Finish setup' ) ).toBeNull();
} );
it( 'should not render the finish setup link when on the home screen and TaskList is not complete', () => {
const { queryByText } = render(
<ActivityPanel
query={ {
page: 'wc-admin',
task: '',
} }
/>
);
expect( queryByText( 'Finish setup' ) ).toBeNull();
} );
it( 'should render the finish setup link when on embedded pages and TaskList is not complete', () => {
const { getByText } = render(
<ActivityPanel isEmbedded query={ {} } />
);
expect( getByText( 'Finish setup' ) ).toBeInTheDocument();
} );
Fix/37502: Correct spelling errors. (#37887) * change reference of Catpure to Capture Co-Authored-By: Vikram <93216400+vikrampm1@users.noreply.github.com> * change reference of expicitly to explicitly Co-Authored-By: Vikram <93216400+vikrampm1@users.noreply.github.com> * change reference 'cutted' to 'cut' * change reference 'determening' to 'determining' * change reference 'retreive' to 'retrieve' * change reference 'neccessary' to 'necessary' * change reference 'Fitler' to 'Filter' * change reference of "seperate" to "separate" Co-Authored-By: Ankit K Gupta <ankit.himcs@gmail.com> * change reference of "wether" to "whether" Co-Authored-By: Sumit Bagthariya <67687255+qasumitbagthariya@users.noreply.github.com> * change reference of "staus" to "status" * change reference of "retrive" to "retrieve" * change references of "gatways" to "gateways" * change references of "existant" to "existent" * change reference of "requries" to "requires" * change reference of "configuation" to "configuration" * change reference of "processsing" to "processing" * change reference of "represenation" to "representation" * change reference of "dimentions" to "dimensions" * change references of "reigster" to "register" * change reference of "colum" to "column" * change reference of "transtions" to "transitions" * change references of "intially" to "initially" * change references of "orignal" to "original" * change references of "deprected" to "deprecated" * change references of "paramter" to "parameter" * change reference of "intance" to "instance" * change reference of "elemets" to "elements" * change references of "funcitons" to "functions" * change reference of "specificed" to "specified" * change references of "atributes" to "attributes" * change reference of "tast" to "task" * change reference of "chaning" to "changing" * change reference of "retreiving" to "retrieving" * change reference of "caluclation" to "calculation" * change references of "Invaid" to "Invalid" * change references of "paramaters" to "parameters" * change reference of "Additonal" to "Additional" * change reference of "teh" to "the" * change reference of "evalutes" to "evaluates" * change reference of "addedd" to "added" * change reference of "excempt" to "exempt" * change reference of "sequencially" to "sequentially" * change reference of "previos" to "previous" * change reference of "elegible" to "eligible" * change references of "Boostrap" to "Bootstrap" * change references of "compability" to "compatibility" * change reference of "heirarchy" to "hierarchy" * change references of "visibilty" to "visibility" * change reference of "comparsion" to "comparison" * change reference of "capabilties" to "capabilities" * change reference of "datatores" to "datastores" * change reference of "occured" to "occurred" * change reference of "coresponding" to "corresponding" * change references of "thier" to "their" * change reference of "sucessfully" to "successfully" * change reference of "insde" to "inside" * change reference of "nagivation" to "navigation" * change references of "visiblity" to "visibility" * change reference of "documentaiton" to "documentation" * change reference of "anayltics" to "analytics" * change reference of "intalling" to "installing" * change reference of "mininum" to "minimum" * change references of "intial" to "initial" * change reference of "Feld" to "Field" * change reference of "taks" to "task" * change reference of "trasnfer" to "transfer" * change reference of "respone" to "response" * change reference of "Extenstions" to "Extensions" * change reference of "detault" to "default" * change reference of "simultanious" to "simultaneous" * change reference of "overides" to "overrides" * change references of "Indvidual" to "Individual" * change reference of "refering" to "referring" * change reference of "aginst" to "against" * change reference of "execuatable" to "executable" * change reference of "repsonse" to "response" * change reference of "documention" to "documentation" * change reference of "asumed" to "assumed" * change reference of "Minium" to "Minimum" * change reference of "unqiue" to "unique" * change references of "existance" to "existence" * change reference of "compatability" to "compatibility" * change reference of "Taxnomy" to "Taxonomy" * change reference of "quering" to "querying" * change reference of "retrun" to "return" * change reference of "informations" to "information" Co-Authored-By: Viktor Szépe <viktor@szepe.net> * Add changelog * Add changelog * Fix typo --------- Co-authored-by: Vikram <93216400+vikrampm1@users.noreply.github.com> Co-authored-by: Ankit K Gupta <ankit.himcs@gmail.com> Co-authored-by: Sumit Bagthariya <67687255+qasumitbagthariya@users.noreply.github.com> Co-authored-by: Viktor Szépe <viktor@szepe.net> Co-authored-by: Chi-Hsuan Huang <chihsuan.tw@gmail.com>
2023-05-08 07:55:09 +00:00
it( 'should not render the finish setup link when a user does not have capabilities', () => {
useUser.mockImplementation( () => ( {
currentUserCan: () => false,
} ) );
const { queryByText } = render(
<ActivityPanel
query={ {
task: 'products',
} }
/>
);
expect( queryByText( 'Finish setup' ) ).toBeDefined();
} );
describe( 'panel', () => {
it( 'should set focus when panel opened/closed without removing element when onTransitionEnd is triggered', () => {
const content = 'test';
const TestComponent = () => {
const [ panelOpen, setPanelOpen ] = useState( true );
return (
<div>
<button onClick={ () => setPanelOpen( ! panelOpen ) }>
Toggle
</button>
<Panel
isPanelOpen={ panelOpen }
tab={ {} }
content={ content }
clearPanel={ () => {} }
/>
</div>
);
};
const { container, queryByText, getByRole } = render(
<TestComponent />
);
expect( queryByText( 'test' ) ).toBeInTheDocument();
expect( document.activeElement ).toEqual(
container.getElementsByClassName(
'woocommerce-layout__activity-panel-wrapper'
)[ 0 ]
);
getByRole( 'button' ).focus();
expect( document.activeElement ).not.toEqual(
container.getElementsByClassName(
'woocommerce-layout__activity-panel-wrapper'
)[ 0 ]
);
fireEvent.click( getByRole( 'button' ) );
fireEvent.click( getByRole( 'button' ) );
const event = createEvent.transitionEnd(
container.getElementsByClassName(
'woocommerce-layout__activity-panel-wrapper'
)[ 0 ]
);
Object.defineProperty( event, 'propertyName', {
value: 'transform',
} );
fireEvent(
container.getElementsByClassName(
'woocommerce-layout__activity-panel-wrapper'
)[ 0 ],
event
);
expect( document.activeElement ).toEqual(
container.getElementsByClassName(
'woocommerce-layout__activity-panel-wrapper'
)[ 0 ]
);
} );
} );
describe( 'panel open and closing', () => {
let clearPanel;
beforeEach( () => {
Panel.mockImplementation(
( { isPanelOpen, isPanelSwitching, tab, ...props } ) => {
clearPanel = props.clearPanel;
return (
<div>
<span>[panel]</span>
<span>[panelOpen={ isPanelOpen.toString() }]</span>
<span>
[panelSwitching={ isPanelSwitching.toString() }]
</span>
<span>[hasTab={ tab ? 'true' : 'false' }]</span>
</div>
);
}
);
} );
it( 'should have panel open and panel switching as false by default', () => {
const { queryByText } = render(
<ActivityPanel
query={ {
task: 'products',
} }
/>
);
expect( queryByText( '[panel]' ) ).toBeInTheDocument();
expect( queryByText( '[panelOpen=false]' ) ).toBeInTheDocument();
expect(
queryByText( '[panelSwitching=false]' )
).toBeInTheDocument();
fireEvent.click(
screen.queryByTestId( 'activity-panel-tab-help' )
);
} );
it( 'should allow user to toggle, an individual panel without setting panelSwitching to true', () => {
const { queryByText } = render(
<ActivityPanel
query={ {
task: '',
page: 'wc-admin',
} }
/>
);
expect( queryByText( '[panel]' ) ).toBeInTheDocument();
expect( queryByText( '[panelOpen=false]' ) ).toBeInTheDocument();
expect(
queryByText( '[panelSwitching=false]' )
).toBeInTheDocument();
// toggle open
fireEvent.click(
screen.queryByTestId( 'activity-panel-tab-help' )
);
expect( queryByText( '[panelOpen=true]' ) ).toBeInTheDocument();
expect(
queryByText( '[panelSwitching=false]' )
).toBeInTheDocument();
// toggle close
fireEvent.click(
screen.queryByTestId( 'activity-panel-tab-help' )
);
expect( queryByText( '[panelOpen=false]' ) ).toBeInTheDocument();
expect(
queryByText( '[panelSwitching=false]' )
).toBeInTheDocument();
} );
it( 'should remove panel element after clearPanel is triggered', () => {
const { queryByText } = render(
<ActivityPanel
query={ {
task: '',
page: 'wc-admin',
} }
/>
);
// toggle open
fireEvent.click(
screen.queryByTestId( 'activity-panel-tab-help' )
);
expect( queryByText( '[panelOpen=true]' ) ).toBeInTheDocument();
expect(
queryByText( '[panelSwitching=false]' )
).toBeInTheDocument();
// toggle close
fireEvent.click(
screen.queryByTestId( 'activity-panel-tab-help' )
);
expect( queryByText( '[panelOpen=false]' ) ).toBeInTheDocument();
expect( queryByText( '[hasTab=true]' ) ).toBeInTheDocument();
expect(
queryByText( '[panelSwitching=false]' )
).toBeInTheDocument();
act( () => {
clearPanel();
} );
expect( queryByText( '[hasTab=false]' ) ).toBeInTheDocument();
} );
} );
} );