Skip to content

Commit

Permalink
Fix Jest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kqualters-elastic committed Nov 13, 2024
1 parent 45cd5dd commit f5dd06c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 21 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions x-pack/plugins/cases/common/utils/capabilities.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('createUICapabilities', () => {
"update_cases",
"push_cases",
"cases_connectors",
"cases_settings",
],
"createComment": Array [
"create_comment",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const ActionColumnComponent: React.FC<{ theCase: CaseUI; disableActions: boolean
mainPanelItems.push(deleteAction.getAction([theCase]));
}

if (statusAction.canUpdateStatus) {
if (statusAction.canUpdateStatus || !shouldDisableStatus) {
panelsToBuild.push({
id: 1,
title: i18n.STATUS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,32 +559,37 @@ describe('useBulkActions', () => {

it('shows the correct actions with reopen permissions', async () => {
appMockRender = createAppMockRenderer({ permissions: onlyReopenCasesPermission() });
const { result, waitFor: waitForHook } = renderHook(
const { result } = renderHook(
() => useBulkActions({ onAction, onActionSuccess, selectedCases: [basicCaseClosed] }),
{
wrapper: appMockRender.AppWrapper,
}
);

const modals = result.current.modals;
const panels = result.current.panels;

const res = appMockRender.render(
const { modals, flyouts, panels } = result.current;
const renderResult = appMockRender.render(
<>
<EuiContextMenu initialPanelId={0} panels={panels} />
{modals}
{flyouts}
</>
);

await waitForHook(() => {
expect(res.queryByTestId('case-bulk-action-status')).toBeInTheDocument();
res.queryByTestId('case-bulk-action-status')?.click();
await waitFor(() => {
expect(renderResult.queryByTestId('case-bulk-action-status')).toBeInTheDocument();
expect(renderResult.queryByTestId('case-bulk-action-severity')).toBeInTheDocument();
expect(renderResult.queryByTestId('bulk-actions-separator')).not.toBeInTheDocument();
expect(renderResult.queryByTestId('case-bulk-action-delete')).not.toBeInTheDocument();
});

await waitForHook(() => {
expect(res.queryByTestId('cases-bulk-action-status-open')).not.toBeDisabled();
expect(res.queryByTestId('cases-bulk-action-status-in-progress')).not.toBeDisabled();
expect(res.queryByTestId('cases-bulk-action-status-closed')).toBeDisabled();
userEvent.click(renderResult.getByTestId('case-bulk-action-status'));

await waitFor(() => {
expect(renderResult.queryByTestId('cases-bulk-action-status-open')).not.toBeDisabled();
expect(
renderResult.queryByTestId('cases-bulk-action-status-in-progress')
).not.toBeDisabled();
expect(renderResult.queryByTestId('cases-bulk-action-status-closed')).not.toBeDisabled();
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ export const useBulkActions = ({

const panels = useMemo((): EuiContextMenuPanelDescriptor[] => {
const mainPanelItems: EuiContextMenuPanelItemDescriptor[] = [];
const panelsToBuild: EuiContextMenuPanelDescriptor[] = [
{ id: 0, items: mainPanelItems, title: i18n.ACTIONS },
];

if (canUpdate) {
mainPanelItems.push({
Expand Down Expand Up @@ -119,7 +116,13 @@ export const useBulkActions = ({
if (canDelete) {
mainPanelItems.push(deleteAction.getAction(selectedCases));
}

const panelsToBuild: EuiContextMenuPanelDescriptor[] = [
{
id: 0,
items: [...mainPanelItems], // Create a new array instead of using reference
title: i18n.ACTIONS,
},
];
if (canUpdate) {
panelsToBuild.push({
id: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ export const CasesTableUtilityBar: FunctionComponent<Props> = React.memo(
* Granular permission check for each action is performed
* in the useBulkActions hook.
*/
const showBulkActions = (permissions.update || permissions.delete) && selectedCases.length > 0;
const showBulkActions =
(permissions.update || permissions.delete || permissions.reopen) && selectedCases.length > 0;

const visibleCases =
pagination?.pageSize && totalCases > pagination.pageSize ? pagination.pageSize : totalCases;
Expand Down

0 comments on commit f5dd06c

Please sign in to comment.