Skip to content

Commit

Permalink
Create cases features
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Nov 30, 2021
1 parent 3223032 commit 0f2432a
Show file tree
Hide file tree
Showing 26 changed files with 154 additions and 154 deletions.
7 changes: 7 additions & 0 deletions x-pack/plugins/cases/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/
import { ConnectorTypes } from './api';
import { CasesContextValue } from './ui/types';

export const DEFAULT_DATE_FORMAT = 'dateFormat';
export const DEFAULT_DATE_FORMAT_TZ = 'dateFormat:tz';
Expand Down Expand Up @@ -102,3 +103,9 @@ export const MAX_CONCURRENT_SEARCHES = 10;
*/

export const MAX_TITLE_LENGTH = 64;

/**
* Cases features
*/

export const DEFAULT_FEATURES: CasesContextValue['features'] = { alerts: { sync: true } };
13 changes: 13 additions & 0 deletions x-pack/plugins/cases/common/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ import {
ActionConnector,
} from '../api';

interface CasesFeatures {
alerts: { sync: boolean };
}

export interface CasesContextValue {
owner: string[];
appId: string;
appTitle: string;
userCanCrud: boolean;
basePath: string;
features: CasesFeatures;
}

export interface CasesUiConfigType {
markdownPlugins: {
lens: boolean;
Expand Down
34 changes: 22 additions & 12 deletions x-pack/plugins/cases/public/common/mock/test_providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,41 @@ import { euiDarkVars } from '@kbn/ui-shared-deps-src/theme';
import { I18nProvider } from '@kbn/i18n-react';
import React from 'react';
import { ThemeProvider } from 'styled-components';
import { SECURITY_SOLUTION_OWNER } from '../../../common';
import { CasesContextValue, DEFAULT_FEATURES, SECURITY_SOLUTION_OWNER } from '../../../common';
import { CasesProvider } from '../../components/cases_context';
import { createKibanaContextProviderMock } from '../lib/kibana/kibana_react.mock';
import { FieldHook } from '../shared_imports';

interface Props {
children: React.ReactNode;
userCanCrud?: boolean;
features?: CasesContextValue['features'];
}

window.scrollTo = jest.fn();
const MockKibanaContextProvider = createKibanaContextProviderMock();

/** A utility for wrapping children in the providers required to run most tests */
const TestProvidersComponent: React.FC<Props> = ({ children, userCanCrud = true }) => (
<I18nProvider>
<MockKibanaContextProvider>
<ThemeProvider theme={() => ({ eui: euiDarkVars, darkMode: true })}>
<CasesProvider value={{ owner: [SECURITY_SOLUTION_OWNER], userCanCrud }}>
{children}
</CasesProvider>
</ThemeProvider>
</MockKibanaContextProvider>
</I18nProvider>
);
const TestProvidersComponent: React.FC<Props> = ({
children,
userCanCrud = true,
features = {},
}) => {
const featuresOptions = { ...DEFAULT_FEATURES, ...features };
return (
<I18nProvider>
<MockKibanaContextProvider>
<ThemeProvider theme={() => ({ eui: euiDarkVars, darkMode: true })}>
<CasesProvider
value={{ owner: [SECURITY_SOLUTION_OWNER], userCanCrud, features: featuresOptions }}
>
{children}
</CasesProvider>
</ThemeProvider>
</MockKibanaContextProvider>
</I18nProvider>
);
};

export const TestProviders = React.memo(TestProvidersComponent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { useUpdateCases } from '../../containers/use_bulk_update_case';
import { useGetActionLicense } from '../../containers/use_get_action_license';
import { useConnectors } from '../../containers/configure/use_connectors';
import { useKibana } from '../../common/lib/kibana';
import { AllCasesList, AllCasesListProps } from './all_cases_list';
import { AllCasesList } from './all_cases_list';
import { CasesColumns, GetCasesColumn, useCasesColumns } from './columns';
import { triggersActionsUiMock } from '../../../../triggers_actions_ui/public/mocks';
import { registerConnectorsToMockActionRegistry } from '../../common/mock/register_connectors';
Expand Down Expand Up @@ -64,10 +64,6 @@ const mockKibana = () => {
};

describe('AllCasesListGeneric', () => {
const defaultAllCasesListProps: AllCasesListProps = {
disableAlerts: false,
};

const dispatchResetIsDeleted = jest.fn();
const dispatchResetIsUpdated = jest.fn();
const dispatchUpdateCaseProperty = jest.fn();
Expand Down Expand Up @@ -161,7 +157,7 @@ describe('AllCasesListGeneric', () => {

const wrapper = mount(
<TestProviders>
<AllCasesList {...defaultAllCasesListProps} />
<AllCasesList />
</TestProviders>
);

Expand Down Expand Up @@ -215,7 +211,7 @@ describe('AllCasesListGeneric', () => {
});
const wrapper = mount(
<TestProviders>
<AllCasesList {...defaultAllCasesListProps} />
<AllCasesList />
</TestProviders>
);
const checkIt = (columnName: string, key: number) => {
Expand Down Expand Up @@ -245,7 +241,7 @@ describe('AllCasesListGeneric', () => {
});
const wrapper = mount(
<TestProviders>
<AllCasesList {...defaultAllCasesListProps} />
<AllCasesList />
</TestProviders>
);
await waitFor(() => {
Expand Down Expand Up @@ -281,7 +277,7 @@ describe('AllCasesListGeneric', () => {
});
const wrapper = mount(
<TestProviders>
<AllCasesList {...defaultAllCasesListProps} />
<AllCasesList />
</TestProviders>
);

Expand All @@ -293,7 +289,7 @@ describe('AllCasesListGeneric', () => {
it('should tableHeaderSortButton AllCasesList', async () => {
const wrapper = mount(
<TestProviders>
<AllCasesList {...defaultAllCasesListProps} />
<AllCasesList />
</TestProviders>
);
wrapper.find('[data-test-subj="tableHeaderSortButton"]').first().simulate('click');
Expand All @@ -310,7 +306,7 @@ describe('AllCasesListGeneric', () => {
it('Updates status when status context menu is updated', async () => {
const wrapper = mount(
<TestProviders>
<AllCasesList {...defaultAllCasesListProps} />
<AllCasesList />
</TestProviders>
);
wrapper.find(`[data-test-subj="case-view-status-dropdown"] button`).first().simulate('click');
Expand Down Expand Up @@ -351,7 +347,7 @@ describe('AllCasesListGeneric', () => {

const wrapper = mount(
<TestProviders>
<AllCasesList {...defaultAllCasesListProps} />
<AllCasesList />
</TestProviders>
);

Expand Down Expand Up @@ -388,7 +384,7 @@ describe('AllCasesListGeneric', () => {

const wrapper = mount(
<TestProviders>
<AllCasesList {...defaultAllCasesListProps} />
<AllCasesList />
</TestProviders>
);

Expand Down Expand Up @@ -431,7 +427,7 @@ describe('AllCasesListGeneric', () => {

const wrapper = mount(
<TestProviders>
<AllCasesList {...defaultAllCasesListProps} />
<AllCasesList />
</TestProviders>
);
wrapper.find('[data-test-subj="case-table-bulk-actions"] button').first().simulate('click');
Expand All @@ -458,7 +454,7 @@ describe('AllCasesListGeneric', () => {

const wrapper = mount(
<TestProviders>
<AllCasesList {...defaultAllCasesListProps} />
<AllCasesList />
</TestProviders>
);
wrapper.find('[data-test-subj="case-table-bulk-actions"] button').first().simulate('click');
Expand All @@ -481,7 +477,7 @@ describe('AllCasesListGeneric', () => {

const wrapper = mount(
<TestProviders>
<AllCasesList {...defaultAllCasesListProps} />
<AllCasesList />
</TestProviders>
);
wrapper.find('[data-test-subj="case-table-bulk-actions"] button').first().simulate('click');
Expand All @@ -500,7 +496,7 @@ describe('AllCasesListGeneric', () => {

const wrapper = mount(
<TestProviders>
<AllCasesList {...defaultAllCasesListProps} />
<AllCasesList />
</TestProviders>
);
wrapper.find('[data-test-subj="case-table-bulk-actions"] button').first().simulate('click');
Expand All @@ -521,7 +517,7 @@ describe('AllCasesListGeneric', () => {

mount(
<TestProviders>
<AllCasesList {...defaultAllCasesListProps} />
<AllCasesList />
</TestProviders>
);
await waitFor(() => {
Expand All @@ -539,7 +535,7 @@ describe('AllCasesListGeneric', () => {

mount(
<TestProviders>
<AllCasesList {...defaultAllCasesListProps} />
<AllCasesList />
</TestProviders>
);
await waitFor(() => {
Expand All @@ -552,7 +548,7 @@ describe('AllCasesListGeneric', () => {
it('should not render table utility bar when isSelectorView=true', async () => {
const wrapper = mount(
<TestProviders>
<AllCasesList {...defaultAllCasesListProps} isSelectorView={true} />
<AllCasesList isSelectorView={true} />
</TestProviders>
);
await waitFor(() => {
Expand All @@ -566,7 +562,7 @@ describe('AllCasesListGeneric', () => {
it('case table should not be selectable when isSelectorView=true', async () => {
const wrapper = mount(
<TestProviders>
<AllCasesList {...defaultAllCasesListProps} isSelectorView={true} />
<AllCasesList isSelectorView={true} />
</TestProviders>
);
await waitFor(() => {
Expand All @@ -588,7 +584,7 @@ describe('AllCasesListGeneric', () => {

const wrapper = mount(
<TestProviders>
<AllCasesList {...defaultAllCasesListProps} isSelectorView={true} onRowClick={onRowClick} />
<AllCasesList isSelectorView={true} onRowClick={onRowClick} />
</TestProviders>
);
wrapper.find('[data-test-subj="cases-table-add-case"]').first().simulate('click');
Expand All @@ -600,7 +596,7 @@ describe('AllCasesListGeneric', () => {
it('should call onRowClick when clicking a case with modal=true', async () => {
const wrapper = mount(
<TestProviders>
<AllCasesList {...defaultAllCasesListProps} isSelectorView={true} onRowClick={onRowClick} />
<AllCasesList isSelectorView={true} onRowClick={onRowClick} />
</TestProviders>
);

Expand Down Expand Up @@ -657,7 +653,7 @@ describe('AllCasesListGeneric', () => {
it('should NOT call onRowClick when clicking a case with modal=true', async () => {
const wrapper = mount(
<TestProviders>
<AllCasesList {...defaultAllCasesListProps} isSelectorView={false} />
<AllCasesList isSelectorView={false} />
</TestProviders>
);
wrapper.find('[data-test-subj="cases-table-row-1"]').first().simulate('click');
Expand All @@ -669,7 +665,7 @@ describe('AllCasesListGeneric', () => {
it('should change the status to closed', async () => {
const wrapper = mount(
<TestProviders>
<AllCasesList {...defaultAllCasesListProps} isSelectorView={false} />
<AllCasesList isSelectorView={false} />
</TestProviders>
);
wrapper.find('button[data-test-subj="case-status-filter"]').simulate('click');
Expand All @@ -684,7 +680,7 @@ describe('AllCasesListGeneric', () => {
it('should change the status to in-progress', async () => {
const wrapper = mount(
<TestProviders>
<AllCasesList {...defaultAllCasesListProps} isSelectorView={false} />
<AllCasesList isSelectorView={false} />
</TestProviders>
);
wrapper.find('button[data-test-subj="case-status-filter"]').simulate('click');
Expand All @@ -699,7 +695,7 @@ describe('AllCasesListGeneric', () => {
it('should change the status to open', async () => {
const wrapper = mount(
<TestProviders>
<AllCasesList {...defaultAllCasesListProps} isSelectorView={false} />
<AllCasesList isSelectorView={false} />
</TestProviders>
);
wrapper.find('button[data-test-subj="case-status-filter"]').simulate('click');
Expand All @@ -714,7 +710,7 @@ describe('AllCasesListGeneric', () => {
it('should show the correct count on stats', async () => {
const wrapper = mount(
<TestProviders>
<AllCasesList {...defaultAllCasesListProps} isSelectorView={false} />
<AllCasesList isSelectorView={false} />
</TestProviders>
);
wrapper.find('button[data-test-subj="case-status-filter"]').simulate('click');
Expand All @@ -734,7 +730,7 @@ describe('AllCasesListGeneric', () => {
it('should not render status when isSelectorView=true', async () => {
const wrapper = mount(
<TestProviders>
<AllCasesList {...defaultAllCasesListProps} isSelectorView={true} />
<AllCasesList isSelectorView={true} />
</TestProviders>
);

Expand Down Expand Up @@ -769,7 +765,7 @@ describe('AllCasesListGeneric', () => {

const wrapper = mount(
<TestProviders>
<AllCasesList {...defaultAllCasesListProps} isSelectorView={false} doRefresh={doRefresh} />
<AllCasesList isSelectorView={false} doRefresh={doRefresh} />
</TestProviders>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ const getSortField = (field: string): SortFieldCase =>

export interface AllCasesListProps {
alertData?: Omit<CommentRequestAlertType, 'type'>;
disableAlerts?: boolean;
hiddenStatuses?: CaseStatusWithAllStatus[];
isSelectorView?: boolean;
onRowClick?: (theCase?: Case | SubCase) => void;
Expand All @@ -64,7 +63,6 @@ export interface AllCasesListProps {
export const AllCasesList = React.memo<AllCasesListProps>(
({
alertData,
disableAlerts,
hiddenStatuses = [],
isSelectorView = false,
onRowClick,
Expand Down Expand Up @@ -168,7 +166,6 @@ export const AllCasesList = React.memo<AllCasesListProps>(
const showActions = userCanCrud && !isSelectorView;

const columns = useCasesColumns({
disableAlerts,
dispatchUpdateCaseProperty,
filterStatus: filterOptions.status,
handleIsLoading,
Expand Down
Loading

0 comments on commit 0f2432a

Please sign in to comment.