Skip to content

Commit

Permalink
finish testing
Browse files Browse the repository at this point in the history
  • Loading branch information
stephmilovic committed Apr 8, 2020
1 parent 2520299 commit 33b00f6
Show file tree
Hide file tree
Showing 15 changed files with 601 additions and 246 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,105 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SortFieldCase } from '../../../../../containers/case/types';
import { UseGetCasesState } from '../../../../../containers/case/use_get_cases';
import { CaseProps } from '../case_view';
import { Case, Comment, SortFieldCase } from '../../../../containers/case/types';
import { UseGetCasesState } from '../../../../containers/case/use_get_cases';
import { UserAction, UserActionField } from '../../../../../../../../plugins/case/common/api/cases';

const updateCase = jest.fn();
const fetchCase = jest.fn();

const basicCaseId = 'basic-case-id';
const basicCommentId = 'basic-comment-id';
const basicCreatedAt = '2020-02-20T23:06:33.798Z';
const elasticUser = {
fullName: 'Leslie Knope',
username: 'lknope',
email: '[email protected]',
};

export const basicComment: Comment = {
comment: 'Solve this fast!',
id: basicCommentId,
createdAt: basicCreatedAt,
createdBy: elasticUser,
pushedAt: null,
pushedBy: null,
updatedAt: '2020-02-20T23:06:33.798Z',
updatedBy: {
username: 'elastic',
},
version: 'WzQ3LDFc',
};

export const basicCase: Case = {
closedAt: null,
closedBy: null,
id: basicCaseId,
comments: [basicComment],
createdAt: '2020-02-13T19:44:23.627Z',
createdBy: elasticUser,
description: 'Security banana Issue',
externalService: null,
status: 'open',
tags: ['defacement'],
title: 'Another horrible breach!!',
totalComment: 1,
updatedAt: '2020-02-19T15:02:57.995Z',
updatedBy: {
username: 'elastic',
},
version: 'WzQ3LDFd',
};

export const caseProps: CaseProps = {
caseId: basicCaseId,
userCanCrud: true,
caseData: basicCase,
fetchCase,
updateCase,
};

export const caseClosedProps: CaseProps = {
...caseProps,
caseData: {
...caseProps.caseData,
closedAt: '2020-02-20T23:06:33.798Z',
closedBy: {
username: 'elastic',
},
status: 'closed',
},
};

export const basicCaseClosed: Case = {
...caseClosedProps.caseData,
};

const basicAction = {
actionAt: basicCreatedAt,
actionBy: elasticUser,
oldValue: null,
newValue: 'what a cool value',
caseId: basicCaseId,
commentId: null,
};
export const caseUserActions = [
{
...basicAction,
actionBy: elasticUser,
actionField: ['comment'],
action: 'create',
actionId: 'tt',
},
];

export const useGetCasesMockState: UseGetCasesState = {
data: {
countClosedCases: 0,
countOpenCases: 5,
cases: [
{
closedAt: null,
closedBy: null,
id: '3c4ddcc0-4e99-11ea-9290-35d05cb55c15',
createdAt: '2020-02-13T19:44:23.627Z',
createdBy: { username: 'elastic' },
comments: [],
description: 'Security banana Issue',
externalService: null,
status: 'open',
tags: ['defacement'],
title: 'Another horrible breach',
totalComment: 0,
updatedAt: null,
updatedBy: null,
version: 'WzQ3LDFd',
},
basicCase,
{
closedAt: null,
closedBy: null,
Expand Down Expand Up @@ -129,3 +203,24 @@ export const useGetCasesMockState: UseGetCasesState = {
},
filterOptions: { search: '', reporters: [], tags: [], status: 'open' },
};

const basicPush = {
connector_id: 'connector_id',
connector_name: 'connector name',
external_id: 'external_id',
external_title: 'external title',
external_url: 'basicPush.com',
pushed_at: basicCreatedAt,
pushed_by: elasticUser,
};
export const getUserAction = (af: UserActionField, a: UserAction) => ({
...basicAction,
actionId: `${af[0]}-${a}`,
actionField: af,
action: a,
commentId: af[0] === 'comment' ? basicCommentId : null,
newValue:
a === 'push-to-service' && af[0] === 'pushed'
? JSON.stringify(basicPush)
: basicAction.newValue,
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { mount } from 'enzyme';

import { ServiceNowColumn } from './columns';

import { useGetCasesMockState } from './__mock__';
import { useGetCasesMockState } from '../__mock__/case_data';

describe('ServiceNowColumn ', () => {
it('Not pushed render', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { mount } from 'enzyme';
import moment from 'moment-timezone';
import { AllCases } from './';
import { TestProviders } from '../../../../mock';
import { useGetCasesMockState } from './__mock__';
import { useGetCasesMockState } from '../__mock__/case_data';
import * as i18n from './translations';

import { getEmptyTagValue } from '../../../../components/empty_value';
Expand Down Expand Up @@ -120,7 +120,7 @@ describe('AllCases', () => {
.find(`[data-test-subj="case-table-column-createdBy"]`)
.first()
.text()
).toEqual(useGetCasesMockState.data.cases[0].createdBy.username);
).toEqual(useGetCasesMockState.data.cases[0].createdBy.fullName);
expect(
wrapper
.find(`[data-test-subj="case-table-column-createdAt"]`)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { mount } from 'enzyme';

import { useDeleteCases } from '../../../../containers/case/use_delete_cases';
import { TestProviders } from '../../../../mock';
import { data } from './__mock__';
import { basicCase } from '../__mock__/case_data';
import { CaseViewActions } from './actions';
jest.mock('../../../../containers/case/use_delete_cases');
const useDeleteCasesMock = useDeleteCases as jest.Mock;
Expand All @@ -34,7 +34,7 @@ describe('CaseView actions', () => {
it('clicking trash toggles modal', () => {
const wrapper = mount(
<TestProviders>
<CaseViewActions caseData={data} />
<CaseViewActions caseData={basicCase} />
</TestProviders>
);

Expand All @@ -54,12 +54,14 @@ describe('CaseView actions', () => {
}));
const wrapper = mount(
<TestProviders>
<CaseViewActions caseData={data} />
<CaseViewActions caseData={basicCase} />
</TestProviders>
);

expect(wrapper.find('[data-test-subj="confirm-delete-case-modal"]').exists()).toBeTruthy();
wrapper.find('button[data-test-subj="confirmModalConfirmButton"]').simulate('click');
expect(handleOnDeleteConfirm.mock.calls[0][0]).toEqual([{ id: data.id, title: data.title }]);
expect(handleOnDeleteConfirm.mock.calls[0][0]).toEqual([
{ id: basicCase.id, title: basicCase.title },
]);
});
});
Loading

0 comments on commit 33b00f6

Please sign in to comment.