Skip to content

Commit

Permalink
unit tests covering line 49, logout button click and linting fixed in…
Browse files Browse the repository at this point in the history
… tsx and .test.tsx files

Signed-off-by: [email protected] <[email protected]>
  • Loading branch information
leanneeliatra committed Sep 26, 2023
1 parent 8a43b03 commit 16cac6b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 39 deletions.
8 changes: 7 additions & 1 deletion public/apps/customerror/custom-error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ export function CustomErrorPage(props: CustomErrorDeps) {
{props.subtitle}
</EuiText>
<EuiSpacer size="s" />
<EuiButton fill onClick={() => logout(props.http, '')} fullWidth>
<EuiButton
fill
onClick={() => logout(props.http, '')}
data-test-subj="error-logout-button"
fullWidth
>
Logout
</EuiButton>
</EuiListGroup>
Expand Down Expand Up @@ -75,3 +80,4 @@ export async function renderPage(
);
return () => ReactDOM.unmountComponentAtNode(params.element);
}
export { EuiButton };
53 changes: 15 additions & 38 deletions public/apps/customerror/test/custom-error.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import React from 'react';
import { CustomErrorPage } from '../custom-error';
import { cleanup } from '@testing-library/react';
import '@testing-library/jest-dom';
import { EuiButton } from '../custom-error';
import { logout } from '../../account/utils';

afterEach(() => {
cleanup();
Expand All @@ -30,12 +32,18 @@ const configUiDefault = {
},
};

const mockLogout = jest.fn();

describe('Custom error test', () => {
let component;

beforeEach(() => {
component = shallow(
<EuiButton fill onClick={logout} data-test-subj="error-logout-button" fullWidth>
Logout
</EuiButton>
);
});

describe('Custom error test', () => {
it('renders and clicks the button on the error page', () => {
it('renders and clicks the button on the error page', () => {
const wrapper = shallow(
<CustomErrorPage
title="Title"
Expand All @@ -52,41 +60,10 @@ describe('Custom error test', () => {
/>
);

// jest.mock('../custom-error.tsx', () => {
// logout: mockLogout
// });

// const logoutButton = wrapper.find(`[data-testid="error-logout-button"]`).hostNodes();
// logoutButton.simulate("onClick")
// expect(mockLogout).toHaveBeenCalled();

expect(wrapper).toMatchSnapshot();

// describe('event trigger testing', () => {
// const setState = jest.fn();
// const useState = jest.spyOn(React, 'useState');
// const config: ClientConfigType = {
// ui: configUiDefault,
// auth: {
// type: 'basicauth',
// },
// };
// beforeEach(() => {
// useState.mockImplementation((initialValue) => [initialValue, setState]);
// // add addtional funtionality to test the logout button click and its reroute
// });
// });

// describe("should call logout function", () => {
// const logOutUser = jest.fn();

// const { getByTestId } = render(
// <CustomErrorPage logout={logout} />
// );

// fireEvent.click(getByTestId('error-logout-button'));

// expect(logOutUser).toHaveBeenCalled();
// });
component.find('[data-test-subj="error-logout-button"]').simulate('onClick', {
preventDefault: () => {},
});
});
});

0 comments on commit 16cac6b

Please sign in to comment.