From 67c320bceb0f85a48b99b53a5a5df0bc2cebe693 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Mon, 23 Oct 2023 14:21:12 -0400 Subject: [PATCH] Switch the home link to logout on security error pages (#1564) (#1629) * changing return to dashboards with functioning logout button on error page Signed-off-by: leanne.laceybyrne@eliatra.com Co-authored-by: Darshit Chanpura <35282393+DarshitChanpura@users.noreply.github.com> Co-authored-by: Peter Nied (cherry picked from commit 27c37d40221bdc07f0167eca6348806d6b876dd6) Co-authored-by: leanneeliatra <131779422+leanneeliatra@users.noreply.github.com> --- public/apps/customerror/custom-error.tsx | 11 +++- .../__snapshots__/custom-error.test.tsx.snap | 39 ++++++++++++ .../customerror/test/custom-error.test.tsx | 61 +++++++++++++++++++ 3 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 public/apps/customerror/test/__snapshots__/custom-error.test.tsx.snap create mode 100644 public/apps/customerror/test/custom-error.test.tsx diff --git a/public/apps/customerror/custom-error.tsx b/public/apps/customerror/custom-error.tsx index eb4dd9f2e..973068add 100644 --- a/public/apps/customerror/custom-error.tsx +++ b/public/apps/customerror/custom-error.tsx @@ -21,6 +21,7 @@ import { Router, Route } from 'react-router-dom'; import { ERROR_MISSING_ROLE_PATH } from '../../../common'; import { ClientConfigType } from '../../types'; import './_index.scss'; +import { logout } from '../account/utils'; interface CustomErrorDeps { title: string; @@ -45,8 +46,13 @@ export function CustomErrorPage(props: CustomErrorDeps) { {props.subtitle} - - Back to OpenSearch Dashboards Home + logout(props.http, '')} + data-test-subj="error-logout-button" + fullWidth + > + Logout ); @@ -74,3 +80,4 @@ export async function renderPage( ); return () => ReactDOM.unmountComponentAtNode(params.element); } +export { EuiButton }; diff --git a/public/apps/customerror/test/__snapshots__/custom-error.test.tsx.snap b/public/apps/customerror/test/__snapshots__/custom-error.test.tsx.snap new file mode 100644 index 000000000..ceb888fc1 --- /dev/null +++ b/public/apps/customerror/test/__snapshots__/custom-error.test.tsx.snap @@ -0,0 +1,39 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Custom error page test renders and clicks the button on the error page 1`] = ` + + + +

+ Title +

+
+ + + Sub Title + + + + Logout + +
+`; diff --git a/public/apps/customerror/test/custom-error.test.tsx b/public/apps/customerror/test/custom-error.test.tsx new file mode 100644 index 000000000..18291c351 --- /dev/null +++ b/public/apps/customerror/test/custom-error.test.tsx @@ -0,0 +1,61 @@ +/* + * Copyright OpenSearch Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +import { shallow } from 'enzyme'; +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(); +}); + +describe('Custom error page test', () => { + let component; + + beforeEach(() => { + component = shallow( + + Logout + + ); + }); + + it('renders and clicks the button on the error page', () => { + const wrapper = shallow( + + ); + + expect(wrapper).toMatchSnapshot(); + + component.find('[data-test-subj="error-logout-button"]').simulate('onClick', { + preventDefault: () => {}, + }); + }); +});