Skip to content

Commit

Permalink
disable web terminal when MCH flag is available
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinandan13jan committed Jun 24, 2021
1 parent bbdf5a3 commit aafbffd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { connect } from 'react-redux';
import { RootState } from '@console/internal/redux';
import { toggleCloudShellExpanded } from '../../redux/actions/cloud-shell-actions';
import { isCloudShellExpanded } from '../../redux/reducers/cloud-shell-selectors';
import useMCHDetection from '../../utils/useMCHDetection';
import useCloudShellAvailable from './useCloudShellAvailable';

type DispatchProps = {
Expand All @@ -20,9 +21,11 @@ type Props = StateProps & DispatchProps;

const ClouldShellMastheadButton: React.FC<Props> = ({ onClick, open }) => {
const terminalAvailable = useCloudShellAvailable();
const [isMCHAvailable, flagLoading] = useMCHDetection();

const { t } = useTranslation();

if (!terminalAvailable) {
if (!terminalAvailable || (!flagLoading && isMCHAvailable)) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import { useTranslation } from 'react-i18next';
import { Redirect } from 'react-router';
import { MCH_AVAILABILITY_FLAG } from '@console/app/src/features';
import { InlineTechPreviewBadge, useFlag } from '@console/shared';
import { FLAG_DEVWORKSPACE } from '../../consts';
import CloudShellTerminal from './CloudShellTerminal';
Expand All @@ -9,8 +10,9 @@ import './CloudShellTab.scss';
const CloudShellTab: React.FC = () => {
const { t } = useTranslation();
const devWorkspaceFlag = useFlag(FLAG_DEVWORKSPACE);
const mchFLag = useFlag(MCH_AVAILABILITY_FLAG);

if (devWorkspaceFlag === false) return <Redirect to="/" />;
if (devWorkspaceFlag === false || mchFLag === true) return <Redirect to="/" />;

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import { shallow } from 'enzyme';
import { Redirect } from 'react-router';
import * as shared from '@console/shared';
import { FLAG_DEVWORKSPACE } from '../../../consts';
import CloudShellTab from '../CloudShellTab';
import CloudShellTerminal from '../CloudShellTerminal';

Expand All @@ -14,21 +15,27 @@ jest.mock('react-i18next', () => {
});

describe('CloudShellTab', () => {
it('should render CloudShellTerminal', () => {
spyOn(shared, 'useFlag').and.returnValue(true);
const cloudShellTabWrapper = shallow(<CloudShellTab />);
expect(cloudShellTabWrapper.find(CloudShellTerminal).exists()).toBe(true);
});

it('should not render redirect component if flag check is pending', () => {
it('should not render redirect component if both flag check is pending', () => {
spyOn(shared, 'useFlag').and.returnValue(undefined);
const cloudShellTabWrapper = shallow(<CloudShellTab />);
expect(cloudShellTabWrapper.find(Redirect).exists()).toBe(false);
});

it('should render redirect component if terminal operator is not installed', () => {
it('should render redirect component if both Devworkspaceflag and MCH is false', () => {
spyOn(shared, 'useFlag').and.returnValue(false);
const cloudShellTabWrapper = shallow(<CloudShellTab />);
expect(cloudShellTabWrapper.find(Redirect).exists()).toBe(true);
});

it('should not render CloudShellTerminal when both flags are true', () => {
spyOn(shared, 'useFlag').and.returnValue(true);
const cloudShellTabWrapper = shallow(<CloudShellTab />);
expect(cloudShellTabWrapper.find(CloudShellTerminal).exists()).toBe(false);
});

it('should render CloudShellTerminal when Devworkspaceflag is true and MCH flag is false', () => {
spyOn(shared, 'useFlag').and.callFake((arg) => arg === FLAG_DEVWORKSPACE);
const cloudShellTabWrapper = shallow(<CloudShellTab />);
expect(cloudShellTabWrapper.find(CloudShellTerminal).exists()).toBe(true);
});
});

0 comments on commit aafbffd

Please sign in to comment.