Skip to content

Commit

Permalink
add missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
WafaaNasr committed Oct 18, 2022
1 parent 2e25a95 commit 8ca35cf
Show file tree
Hide file tree
Showing 11 changed files with 2,117 additions and 123 deletions.

Large diffs are not rendered by default.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import React from 'react';
import { fireEvent, render } from '@testing-library/react';
import { EditModal } from '.';

const onSave = jest.fn();
const onCancel = jest.fn();

describe('EditModal', () => {
it('should render the title and description from listDetails', () => {
const wrapper = render(
<EditModal
listDetails={{ name: 'list name', description: 'list description' }}
onSave={onSave}
onCancel={onCancel}
/>
);
expect(wrapper).toMatchSnapshot();
expect(wrapper.getByTestId('editModalTitle')).toHaveTextContent('list name');
});
it('should call onSave', () => {
const wrapper = render(
<EditModal
listDetails={{ name: 'list name', description: 'list description' }}
onSave={onSave}
onCancel={onCancel}
/>
);
fireEvent.submit(wrapper.getByTestId('editModalForm'));
expect(onSave).toBeCalled();
});
it('should call onCancel', () => {
const wrapper = render(
<EditModal
listDetails={{ name: 'list name', description: 'list description' }}
onSave={onSave}
onCancel={onCancel}
/>
);
fireEvent.click(wrapper.getByTestId('editModalCancelBtn'));
expect(onCancel).toBeCalled();
});

it('should call change title, description and call onSave with the new props', () => {
const wrapper = render(
<EditModal
listDetails={{ name: 'list name', description: 'list description' }}
onSave={onSave}
onCancel={onCancel}
/>
);
fireEvent.change(wrapper.getByTestId('editModalNameTextField'), {
target: { value: 'New list name' },
});
fireEvent.change(wrapper.getByTestId('editModalDescriptionTextField'), {
target: { value: 'New description name' },
});
fireEvent.submit(wrapper.getByTestId('editModalForm'));

expect(onSave).toBeCalledWith({
name: 'New list name',
description: 'New description name',
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,32 @@ const EditModalComponent: FC<EditModalProps> = ({ listDetails, onSave, onCancel
onSave(newListDetails);
};
return (
<EuiModal onClose={onSubmit} initialFocus="[name=popswitch]">
<EuiModal data-test-subj="EditModal" onClose={onSubmit} initialFocus="[name=popswitch]">
<EuiModalHeader>
<EuiModalHeaderTitle>
<EuiModalHeaderTitle data-test-subj="editModalTitle">
<h1>{i18n.EXCEPTION_LIST_HEADER_EDIT_MODAL_TITLE(listDetails.name)}</h1>
</EuiModalHeaderTitle>
</EuiModalHeader>

<EuiModalBody>
<EuiForm id={modalFormId} component="form" onSubmit={onSubmit}>
<EuiForm
id={modalFormId}
data-test-subj="editModalForm"
component="form"
onSubmit={onSubmit}
>
<EuiFormRow label={i18n.EXCEPTION_LIST_HEADER_NAME_TEXTBOX}>
<EuiFieldText name="name" value={newListDetails.name} onChange={onChange} />
<EuiFieldText
data-test-subj="editModalNameTextField"
name="name"
value={newListDetails.name}
onChange={onChange}
/>
</EuiFormRow>

<EuiFormRow label={i18n.EXCEPTION_LIST_HEADER_DESCRIPTION_TEXTBOX}>
<EuiFieldText
data-test-subj="editModalDescriptionTextField"
name="description"
value={newListDetails.description}
onChange={onChange}
Expand All @@ -64,11 +75,17 @@ const EditModalComponent: FC<EditModalProps> = ({ listDetails, onSave, onCancel
</EuiModalBody>

<EuiModalFooter>
<EuiButtonEmpty onClick={onCancel}>
<EuiButtonEmpty data-test-subj="editModalCancelBtn" onClick={onCancel}>
{i18n.EXCEPTION_LIST_HEADER_EDIT_MODAL_CANCEL_BUTTON}
</EuiButtonEmpty>

<EuiButton type="submit" form={modalFormId} onClick={onSubmit} fill>
<EuiButton
data-test-subj="editModalSaveBtn"
type="submit"
form={modalFormId}
onClick={onSubmit}
fill
>
{i18n.EXCEPTION_LIST_HEADER_EDIT_MODAL_SAVE_BUTTON}
</EuiButton>
</EuiModalFooter>
Expand Down
Loading

0 comments on commit 8ca35cf

Please sign in to comment.