From 5b9d1c82fcdb8163de665c9e1a1f4f90bab80d58 Mon Sep 17 00:00:00 2001 From: Miki Date: Fri, 1 Sep 2023 06:21:08 -0700 Subject: [PATCH] Refactor login logo usage (#1568) Signed-off-by: Miki (cherry picked from commit ecb15d56aa96c549f1fd0ca07c86e677cbe6ddbc) --- public/apps/customerror/custom-error.tsx | 5 +-- public/apps/login/login-app.tsx | 5 ++- public/apps/login/login-page.tsx | 4 +-- .../__snapshots__/login-page.test.tsx.snap | 4 +-- public/apps/login/test/login-page.test.tsx | 34 +++++++++++++++---- public/assets/opensearch_logo_h.svg | 10 ------ 6 files changed, 38 insertions(+), 24 deletions(-) delete mode 100644 public/assets/opensearch_logo_h.svg diff --git a/public/apps/customerror/custom-error.tsx b/public/apps/customerror/custom-error.tsx index d228b0320..eb4dd9f2e 100644 --- a/public/apps/customerror/custom-error.tsx +++ b/public/apps/customerror/custom-error.tsx @@ -19,7 +19,6 @@ import React from 'react'; import ReactDOM from 'react-dom'; import { Router, Route } from 'react-router-dom'; import { ERROR_MISSING_ROLE_PATH } from '../../../common'; -import defaultBrandImage from '../../assets/opensearch_logo_h.svg'; import { ClientConfigType } from '../../types'; import './_index.scss'; @@ -27,6 +26,7 @@ interface CustomErrorDeps { title: string; subtitle: string; http: CoreStart['http']; + chrome: CoreStart['chrome']; config: ClientConfigType['ui']['basicauth']['login']; } @@ -34,7 +34,7 @@ export function CustomErrorPage(props: CustomErrorDeps) { return ( {props.config.showbrandimage && ( - + )} @@ -62,6 +62,7 @@ export async function renderPage( , params.element); + ReactDOM.render( + , + params.element + ); return () => ReactDOM.unmountComponentAtNode(params.element); } diff --git a/public/apps/login/login-page.tsx b/public/apps/login/login-page.tsx index 82019cba7..22421e3a7 100644 --- a/public/apps/login/login-page.tsx +++ b/public/apps/login/login-page.tsx @@ -28,7 +28,6 @@ import { } from '@elastic/eui'; import { CoreStart } from '../../../../../src/core/public'; import { ClientConfigType } from '../../types'; -import defaultBrandImage from '../../assets/opensearch_logo_h.svg'; import { validateCurrentPassword } from '../../utils/login-utils'; import { ANONYMOUS_AUTH_LOGIN, @@ -39,6 +38,7 @@ import { interface LoginPageDeps { http: CoreStart['http']; + chrome: CoreStart['chrome']; config: ClientConfigType; } @@ -259,7 +259,7 @@ export function LoginPage(props: LoginPageDeps) { )} diff --git a/public/apps/login/test/__snapshots__/login-page.test.tsx.snap b/public/apps/login/test/__snapshots__/login-page.test.tsx.snap index a73477edc..c2dac62c1 100644 --- a/public/apps/login/test/__snapshots__/login-page.test.tsx.snap +++ b/public/apps/login/test/__snapshots__/login-page.test.tsx.snap @@ -366,7 +366,7 @@ exports[`Login page renders renders with default value: string 1`] = ` ({ validateCurrentPassword: jest.fn(), @@ -84,12 +85,17 @@ describe('test extractNextUrlFromWindowLocation', () => { }); describe('Login page', () => { + let chrome: ReturnType; const mockHttpStart = { basePath: { serverBasePath: '/app/opensearch-dashboards', }, }; + beforeEach(() => { + chrome = chromeServiceMock.createStartContract(); + }); + describe('renders', () => { it('renders with config value: string array', () => { const config: ClientConfigType = { @@ -99,7 +105,9 @@ describe('Login page', () => { logout_url: API_AUTH_LOGOUT, }, }; - const component = shallow(); + const component = shallow( + + ); expect(component).toMatchSnapshot(); }); @@ -111,7 +119,9 @@ describe('Login page', () => { logout_url: API_AUTH_LOGOUT, }, }; - const component = shallow(); + const component = shallow( + + ); expect(component).toMatchSnapshot(); }); @@ -123,7 +133,9 @@ describe('Login page', () => { logout_url: API_AUTH_LOGOUT, }, }; - const component = shallow(); + const component = shallow( + + ); expect(component).toMatchSnapshot(); }); @@ -134,7 +146,9 @@ describe('Login page', () => { type: [''], }, }; - const component = shallow(); + const component = shallow( + + ); expect(component).toMatchSnapshot(); }); @@ -145,7 +159,9 @@ describe('Login page', () => { type: '', }, }; - const component = shallow(); + const component = shallow( + + ); expect(component).toMatchSnapshot(); }); }); @@ -162,7 +178,9 @@ describe('Login page', () => { }; beforeEach(() => { useState.mockImplementation((initialValue) => [initialValue, setState]); - component = shallow(); + component = shallow( + + ); }); it('should update user name field on change event', () => { @@ -195,7 +213,9 @@ describe('Login page', () => { beforeEach(() => { useState.mockImplementation(() => ['user1', setState]); useState.mockImplementation(() => ['password1', setState]); - component = shallow(); + component = shallow( + + ); }); it('submit click event', () => { diff --git a/public/assets/opensearch_logo_h.svg b/public/assets/opensearch_logo_h.svg deleted file mode 100644 index cb329cadf..000000000 --- a/public/assets/opensearch_logo_h.svg +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - -