Skip to content

Commit

Permalink
pr changes
Browse files Browse the repository at this point in the history
  • Loading branch information
stephmilovic committed Apr 9, 2020
1 parent 1f7d605 commit 9848122
Show file tree
Hide file tree
Showing 14 changed files with 134 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
*/

import { Router } from 'react-router-dom';
/* eslint-disable @kbn/eslint/module_migration */
// eslint-disable-next-line @kbn/eslint/module_migration
import routeData from 'react-router';
/* eslint-enable @kbn/eslint/module_migration */
type Action = 'PUSH' | 'POP' | 'REPLACE';
const pop: Action = 'POP';
const location = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import { Router, routeData, mockHistory, mockLocation } from '../__mock__/router

import { useInsertTimeline } from '../../../../components/timeline/insert_timeline_popover/use_insert_timeline';
import { usePostComment } from '../../../../containers/case/use_post_comment';
jest.mock('../../../../components/timeline/insert_timeline_popover/use_insert_timeline');
jest.mock('../../../../containers/case/use_post_comment');
import { useForm } from '../../../../../../../../../src/plugins/es_ui_shared/static/forms/hook_form_lib/hooks/use_form';
import { wait } from '../../../../lib/helpers';
jest.mock(
'../../../../../../../../../src/plugins/es_ui_shared/static/forms/hook_form_lib/hooks/use_form'
);
jest.mock('../../../../components/timeline/insert_timeline_popover/use_insert_timeline');
jest.mock('../../../../containers/case/use_post_comment');

export const useFormMock = useForm as jest.Mock;

Expand Down Expand Up @@ -78,6 +78,7 @@ describe('AddComment ', () => {
</Router>
</TestProviders>
);
expect(wrapper.find(`[data-test-subj="add-comment"]`).exists()).toBeTruthy();
expect(wrapper.find(`[data-test-subj="loading-spinner"]`).exists()).toBeFalsy();

wrapper
Expand All @@ -90,7 +91,7 @@ describe('AddComment ', () => {
expect(formHookMock.reset).toBeCalled();
});

it('should render spinner when loading', () => {
it('should render spinner and disable submit when loading', () => {
usePostCommentMock.mockImplementation(() => ({ ...defaultPostCommment, isLoading: true }));
const wrapper = mount(
<TestProviders>
Expand All @@ -100,6 +101,29 @@ describe('AddComment ', () => {
</TestProviders>
);
expect(wrapper.find(`[data-test-subj="loading-spinner"]`).exists()).toBeTruthy();
expect(
wrapper
.find(`[data-test-subj="submit-comment"]`)
.first()
.prop('isDisabled')
).toBeTruthy();
});

it('should disable submit button when disabled prop passed', () => {
usePostCommentMock.mockImplementation(() => ({ ...defaultPostCommment, isLoading: true }));
const wrapper = mount(
<TestProviders>
<Router history={mockHistory}>
<AddComment {...{ ...addCommentProps, disabled: true }} />
</Router>
</TestProviders>
);
expect(
wrapper
.find(`[data-test-subj="submit-comment"]`)
.first()
.prop('isDisabled')
).toBeTruthy();
});

it('should insert a quote if one is available', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const AddComment = React.memo<AddCommentProps>(
componentProps={{
idAria: 'caseComment',
isDisabled: isLoading,
dataTestSubj: 'caseComment',
dataTestSubj: 'add-comment',
placeholder: i18n.ADD_COMMENT_HELP_TEXT,
onCursorPositionUpdate: handleCursorChange,
bottomRightContent: (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import { TestProviders } from '../../../../mock';

import { useGetTags } from '../../../../containers/case/use_get_tags';
import { useGetReporters } from '../../../../containers/case/use_get_reporters';
import { DEFAULT_FILTER_OPTIONS } from '../../../../containers/case/use_get_cases';
jest.mock('../../../../components/timeline/insert_timeline_popover/use_insert_timeline');
jest.mock('../../../../containers/case/use_get_reporters');
import { DEFAULT_FILTER_OPTIONS } from '../../../../containers/case/use_get_cases';
jest.mock('../../../../containers/case/use_get_tags');

const onFilterChanged = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ describe('CaseCallOut ', () => {
message: 'we have one message',
};
const wrapper = mount(<CaseCallOut {...props} />);
expect(wrapper.find(`[data-test-subj="case-call-out"]`).exists()).toBeTruthy();
wrapper
.find(`[data-test-subj="callout-dismiss"]`)
.last()
.simulate('click');
expect(wrapper).toEqual({});
expect(wrapper.find(`[data-test-subj="case-call-out"]`).exists()).toBeFalsy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const CaseCallOutComponent = ({ title, message, messages }: CaseCallOutProps) =>

return showCallOut ? (
<>
<EuiCallOut title={title} color="primary" iconType="gear">
<EuiCallOut title={title} color="primary" iconType="gear" data-test-subj="case-call-out">
{!isEmpty(messages) && (
<EuiDescriptionList data-test-subj="callout-messages" listItems={messages} />
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const CaseViewActionsComponent: React.FC<CaseViewActions> = ({ caseData, disable
),
[isDisplayConfirmDeleteModal, caseData]
);
// TO DO refactor each of these const's into their own components
const propertyActions = useMemo(
() => [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('CaseView ', () => {
).toEqual(data.status);
expect(
wrapper
.find(`[data-test-subj="case-view-tag-list"] .euiBadge__text`)
.find(`[data-test-subj="case-view-tag-list"] [data-test-subj="case-tag"]`)
.first()
.text()
).toEqual(data.tags[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { TestProviders } from '../../../../mock';
import { wait } from '../../../../lib/helpers';
import { useForm } from '../../../../../../../../../src/plugins/es_ui_shared/static/forms/hook_form_lib/hooks';
import { act } from 'react-dom/test-utils';

jest.mock(
'../../../../../../../../../src/plugins/es_ui_shared/static/forms/hook_form_lib/hooks/use_form'
);
Expand Down Expand Up @@ -79,6 +80,47 @@ describe('TagList ', () => {
expect(onSubmit).toBeCalledWith(sampleTags);
});
});
it('Cancels on cancel', async () => {
const props = {
...defaultProps,
tags: ['pepsi'],
};
const wrapper = mount(
<TestProviders>
<TagList {...props} />
</TestProviders>
);
expect(
wrapper
.find(`[data-test-subj="case-tag"]`)
.last()
.exists()
).toBeTruthy();
wrapper
.find(`[data-test-subj="tag-list-edit-button"]`)
.last()
.simulate('click');
await act(async () => {
expect(
wrapper
.find(`[data-test-subj="case-tag"]`)
.last()
.exists()
).toBeFalsy();
wrapper
.find(`[data-test-subj="edit-tags-cancel"]`)
.last()
.simulate('click');
await wait();
wrapper.update();
expect(
wrapper
.find(`[data-test-subj="case-tag"]`)
.last()
.exists()
).toBeTruthy();
});
});
it('Renders disabled button', () => {
const props = { ...defaultProps, disabled: true };
const wrapper = mount(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ export const TagList = React.memo(
)}
</EuiFlexGroup>
<EuiHorizontalRule margin="xs" />
<MyFlexGroup gutterSize="xs">
<MyFlexGroup gutterSize="xs" data-test-subj="grr">
{tags.length === 0 && !isEditTags && <p data-test-subj="no-tags">{i18n.NO_TAGS}</p>}
{tags.length > 0 &&
!isEditTags &&
tags.map((tag, key) => (
<EuiFlexItem grow={false} key={`${tag}${key}`}>
<EuiBadge color="hollow">{tag}</EuiBadge>
<EuiBadge data-test-subj="case-tag" color="hollow">
{tag}
</EuiBadge>
</EuiFlexItem>
))}
{isEditTags && (
Expand Down Expand Up @@ -117,6 +119,7 @@ export const TagList = React.memo(
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButtonEmpty
data-test-subj="edit-tags-cancel"
iconType="cross"
onClick={setIsEditTags.bind(null, false)}
size="s"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
/* eslint-disable react/display-name */
// import React from 'react';
import { renderHook, act } from '@testing-library/react-hooks';
import { usePushToService, ReturnUsePushToService, UsePushToService } from './';
import { TestProviders } from '../../../../mock';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('UserActionTree ', () => {
jest.spyOn(routeData, 'useLocation').mockReturnValue(mockLocation);
});

it('Loading spinner when user actions loading', () => {
it('Loading spinner when user actions loading and displays fullName/username', () => {
const wrapper = mount(
<TestProviders>
<Router history={mockHistory}>
Expand All @@ -64,6 +64,56 @@ describe('UserActionTree ', () => {
</TestProviders>
);
expect(wrapper.find(`[data-test-subj="user-actions-loading"]`).exists()).toBeTruthy();

expect(
wrapper
.find(`[data-test-subj="user-action-avatar"]`)
.first()
.prop('name')
).toEqual(defaultProps.data.createdBy.fullName);
expect(
wrapper
.find(`[data-test-subj="user-action-title"] strong`)
.first()
.text()
).toEqual(defaultProps.data.createdBy.username);
});
it('Renders service now update line with top and bottom when push is required', () => {
const ourActions = [
getUserAction(['comment'], 'push-to-service'),
getUserAction(['comment'], 'update'),
];
const props = {
...defaultProps,
caseUserActions: ourActions,
lastIndexPushToService: 0,
};
const wrapper = mount(
<TestProviders>
<Router history={mockHistory}>
<UserActionTree {...props} />
</Router>
</TestProviders>
);
expect(wrapper.find(`[data-test-subj="show-top-footer"]`).exists()).toBeTruthy();
expect(wrapper.find(`[data-test-subj="show-bottom-footer"]`).exists()).toBeTruthy();
});
it('Renders service now update line with top only when push is up to date', () => {
const ourActions = [getUserAction(['comment'], 'push-to-service')];
const props = {
...defaultProps,
caseUserActions: ourActions,
lastIndexPushToService: 0,
};
const wrapper = mount(
<TestProviders>
<Router history={mockHistory}>
<UserActionTree {...props} />
</Router>
</TestProviders>
);
expect(wrapper.find(`[data-test-subj="show-top-footer"]`).exists()).toBeTruthy();
expect(wrapper.find(`[data-test-subj="show-bottom-footer"]`).exists()).toBeFalsy();
});

it('Outlines comment when update move to link is clicked', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export const UserActionTree = React.memo(

const handleSaveComment = useCallback(
({ id, version }: { id: string; version: string }, content: string) => {
// handleManageMarkdownEditId(id);
patchComment({
caseId: caseData.id,
commentId: id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ export const UserActionItem = ({
</EuiFlexGroup>
</EuiFlexItem>
{showTopFooter && (
<PushedContainer>
<PushedContainer data-test-subj="show-top-footer">
<PushedInfoContainer>
<EuiText size="xs" color="subdued">
{i18n.ALREADY_PUSHED_TO_SERVICE}
</EuiText>
</PushedInfoContainer>
<EuiHorizontalRule />
{showBottomFooter && (
<PushedInfoContainer>
<PushedInfoContainer data-test-subj="show-bottom-footer">
<EuiText size="xs" color="subdued">
{i18n.REQUIRED_UPDATE_TO_SERVICE}
</EuiText>
Expand Down

0 comments on commit 9848122

Please sign in to comment.