Skip to content

Commit

Permalink
Merge branch 'main' into read-only-tenant-logic-poc
Browse files Browse the repository at this point in the history
Signed-off-by: Kajetan Nobel <kajetan.nobel@eliatra.com>
  • Loading branch information
kajetan-nobel committed Oct 25, 2023
2 parents 10c5784 + c784665 commit 8ec5413
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 2 deletions.
4 changes: 4 additions & 0 deletions public/apps/configuration/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ export const CLUSTER_PERMISSIONS: string[] = [
'cluster:admin/opensearch/ql/datasources/read',
'cluster:admin/opensearch/ql/datasources/update',
'cluster:admin/opensearch/ql/datasources/delete',
'cluster:admin/opensearch/ql/datasources/patch',
'cluster:admin/opensearch/ql/async_query/create',
'cluster:admin/opensearch/ql/async_query/result',
'cluster:admin/opensearch/ql/async_query/delete',
'cluster:admin/opensearch/ppl',
'cluster:admin/opensearch/ml/create_model_meta',
'cluster:admin/opensearch/ml/execute',
Expand Down
11 changes: 9 additions & 2 deletions public/apps/customerror/custom-error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,8 +46,13 @@ export function CustomErrorPage(props: CustomErrorDeps) {
{props.subtitle}
</EuiText>
<EuiSpacer size="s" />
<EuiButton fill href={props.http.basePath.serverBasePath} fullWidth>
Back to OpenSearch Dashboards Home
<EuiButton
fill
onClick={() => logout(props.http, '')}
data-test-subj="error-logout-button"
fullWidth
>
Logout
</EuiButton>
</EuiListGroup>
);
Expand Down Expand Up @@ -74,3 +80,4 @@ export async function renderPage(
);
return () => ReactDOM.unmountComponentAtNode(params.element);
}
export { EuiButton };
Original file line number Diff line number Diff line change
@@ -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`] = `
<EuiListGroup
className="custom-error-wrapper"
>
<EuiSpacer
size="s"
/>
<EuiText
size="m"
textAlign="center"
>
<h3>
Title
</h3>
</EuiText>
<EuiSpacer
size="s"
/>
<EuiText
size="s"
textAlign="center"
>
Sub Title
</EuiText>
<EuiSpacer
size="s"
/>
<EuiButton
data-test-subj="error-logout-button"
fill={true}
fullWidth={true}
onClick={[Function]}
>
Logout
</EuiButton>
</EuiListGroup>
`;
61 changes: 61 additions & 0 deletions public/apps/customerror/test/custom-error.test.tsx
Original file line number Diff line number Diff line change
@@ -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(
<EuiButton fill onClick={logout} data-test-subj="error-logout-button" fullWidth>
Logout
</EuiButton>
);
});

it('renders and clicks the button on the error page', () => {
const wrapper = shallow(
<CustomErrorPage
title="Title"
subtitle="Sub Title"
http={undefined}
chrome={undefined}
config={{
title: '',
subtitle: '',
showbrandimage: false,
brandimage: '',
buttonstyle: '',
}}
/>
);

expect(wrapper).toMatchSnapshot();

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

0 comments on commit 8ec5413

Please sign in to comment.