Skip to content

Commit

Permalink
Fix bug (#141221)
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas authored Sep 21, 2022
1 parent f3331b9 commit 11588b3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
36 changes: 32 additions & 4 deletions x-pack/plugins/cases/public/components/recent_cases/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import React from 'react';
import { configure, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import RecentCases, { RecentCasesProps } from '.';
import { AppMockRenderer, createAppMockRenderer, TestProviders } from '../../common/mock';
import {
AppMockRenderer,
createAppMockRenderer,
noCasesCapabilities,
TestProviders,
} from '../../common/mock';
import { useGetCasesMockState } from '../../containers/mock';
import { useCurrentUser } from '../../common/lib/kibana/hooks';
import { useGetCases } from '../../containers/use_get_cases';
Expand Down Expand Up @@ -82,7 +87,7 @@ describe('RecentCases', () => {
</TestProviders>
);
expect(useGetCasesMock).toHaveBeenCalledWith({
filterOptions: { reporters: [] },
filterOptions: { reporters: [], owner: ['securitySolution'] },
queryParams: { perPage: 2 },
});
});
Expand All @@ -95,7 +100,7 @@ describe('RecentCases', () => {
);

expect(useGetCasesMock).toHaveBeenCalledWith({
filterOptions: { reporters: [] },
filterOptions: { reporters: [], owner: ['securitySolution'] },
queryParams: { perPage: 10 },
});

Expand All @@ -115,6 +120,7 @@ describe('RecentCases', () => {
username: 'damaged_raccoon',
},
],
owner: ['securitySolution'],
},
queryParams: { perPage: 10 },
});
Expand All @@ -126,6 +132,7 @@ describe('RecentCases', () => {
expect(useGetCasesMock).toHaveBeenLastCalledWith({
filterOptions: {
reporters: [],
owner: ['securitySolution'],
},
queryParams: { perPage: 10 },
});
Expand All @@ -141,7 +148,7 @@ describe('RecentCases', () => {
);

expect(useGetCasesMock).toHaveBeenCalledWith({
filterOptions: { reporters: [] },
filterOptions: { reporters: [], owner: ['securitySolution'] },
queryParams: { perPage: 10 },
});

Expand All @@ -160,8 +167,29 @@ describe('RecentCases', () => {
username: 'elastic',
},
],
owner: ['securitySolution'],
},
queryParams: { perPage: 10 },
});
});

it('sets all available solutions correctly', () => {
appMockRender = createAppMockRenderer({ owner: [] });
/**
* We set securitySolutionCases capability to not have
* any access to cases. This tests that we get the owners
* that have at least read access.
*/
appMockRender.coreStart.application.capabilities = {
...appMockRender.coreStart.application.capabilities,
securitySolutionCases: noCasesCapabilities(),
};

appMockRender.render(<RecentCases {...{ ...defaultProps, maxCasesToShow: 2 }} />);

expect(useGetCasesMock).toHaveBeenCalledWith({
filterOptions: { reporters: [], owner: ['cases'] },
queryParams: { perPage: 2 },
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { MarkdownRenderer } from '../markdown_editor';
import { FilterOptions } from '../../containers/types';
import { TruncatedText } from '../truncated_text';
import { initialData as initialGetCasesData, useGetCases } from '../../containers/use_get_cases';
import { useAvailableCasesOwners } from '../app/use_available_owners';
import { useCasesContext } from '../cases_context/use_cases_context';

const MarkdownContainer = styled.div`
max-height: 150px;
Expand All @@ -31,9 +33,13 @@ export interface RecentCasesProps {
}

export const RecentCasesComp = ({ filterOptions, maxCasesToShow }: RecentCasesProps) => {
const { owner } = useCasesContext();
const availableSolutions = useAvailableCasesOwners(['read']);
const hasOwner = !!owner.length;

const { data = initialGetCasesData, isLoading: isLoadingCases } = useGetCases({
queryParams: { perPage: maxCasesToShow },
filterOptions,
filterOptions: { ...filterOptions, owner: hasOwner ? owner : availableSolutions },
});

return isLoadingCases ? (
Expand Down

0 comments on commit 11588b3

Please sign in to comment.