From 219e27b40906188857d9d85123dd565fd33bb916 Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Fri, 18 Feb 2022 16:30:57 -0300 Subject: [PATCH] 17754: Disables self-serve account linking offering on inactive account page. (when LoginCluster is set) Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- .../inactive-panel/inactive-panel.test.tsx | 63 +++++++++++++++++++ src/views/inactive-panel/inactive-panel.tsx | 37 +++++++---- 2 files changed, 88 insertions(+), 12 deletions(-) create mode 100644 src/views/inactive-panel/inactive-panel.test.tsx diff --git a/src/views/inactive-panel/inactive-panel.test.tsx b/src/views/inactive-panel/inactive-panel.test.tsx new file mode 100644 index 00000000..c694f9db --- /dev/null +++ b/src/views/inactive-panel/inactive-panel.test.tsx @@ -0,0 +1,63 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +import React from 'react'; +import { mount, configure } from 'enzyme'; +import Adapter from "enzyme-adapter-react-16"; +import { CustomTheme } from 'common/custom-theme'; +import { InactivePanelStateProps, CssRules, InactivePanelRoot } from './inactive-panel'; +import { MuiThemeProvider, StyledComponentProps } from '@material-ui/core'; + +configure({ adapter: new Adapter() }); + +describe('InactivePanel', () => { + let props: InactivePanelStateProps & StyledComponentProps; + + beforeEach(() => { + props = { + classes: { + root: 'root', + title: 'title', + ontop: 'ontop', + }, + isLoginClusterFederation: false, + inactivePageText: 'Inactive page content', + }; + }); + + it('should render content and link account option', () => { + // given + const expectedMessage = "Inactive page content"; + const expectedLinkAccountText = 'If you would like to use this login to access another account click "Link Account"'; + + // when + const wrapper = mount( + + + + ); + + // then + expect(wrapper.find('p').first().text()).toContain(expectedMessage); + expect(wrapper.find('p').at(1).text()).toContain(expectedLinkAccountText); + }) + + it('should render content and link account warning on LoginCluster federations', () => { + // given + props.isLoginClusterFederation = true; + const expectedMessage = "Inactive page content"; + const expectedLinkAccountText = 'If you would like to use this login to access another account, please contact your administrator'; + + // when + const wrapper = mount( + + + + ); + + // then + expect(wrapper.find('p').first().text()).toContain(expectedMessage); + expect(wrapper.find('p').at(1).text()).toContain(expectedLinkAccountText); + }) +}); \ No newline at end of file diff --git a/src/views/inactive-panel/inactive-panel.tsx b/src/views/inactive-panel/inactive-panel.tsx index 6d8bbf59..8a7c7928 100644 --- a/src/views/inactive-panel/inactive-panel.tsx +++ b/src/views/inactive-panel/inactive-panel.tsx @@ -11,7 +11,7 @@ import { ArvadosTheme } from 'common/custom-theme'; import { navigateToLinkAccount } from 'store/navigation/navigation-action'; import { RootState } from 'store/store'; -type CssRules = 'root' | 'ontop' | 'title'; +export type CssRules = 'root' | 'ontop' | 'title'; const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ root: { @@ -47,32 +47,45 @@ const mapDispatchToProps = (dispatch: Dispatch): InactivePanelActionProps => ({ } }); +const mapStateToProps = (state: RootState): InactivePanelStateProps => ({ + inactivePageText: state.auth.config.clusterConfig.Workbench.InactivePageHTML, + isLoginClusterFederation: state.auth.config.clusterConfig.Login.LoginCluster !== '', +}); + export interface InactivePanelStateProps { inactivePageText: string; + isLoginClusterFederation: boolean; } type InactivePanelProps = WithStyles & InactivePanelActionProps & InactivePanelStateProps; -export const InactivePanel = connect((state: RootState) => ({ - inactivePageText: state.auth.config.clusterConfig.Workbench.InactivePageHTML -}), mapDispatchToProps)(withStyles(styles)((({ classes, startLinking, inactivePageText }: InactivePanelProps) => + +export const InactivePanelRoot = ({ classes, startLinking, inactivePageText, isLoginClusterFederation }: InactivePanelProps) => -
+ - + { !isLoginClusterFederation + ? <> - If you would like to use this login to access another account click "Link Account". - + If you would like to use this login to access another account click "Link Account". + - - -))); + + + : <> + + If you would like to use this login to access another account, please contact your administrator. + + } + ; + +export const InactivePanel = connect(mapStateToProps, mapDispatchToProps)( + withStyles(styles)(InactivePanelRoot)); -- 2.30.2