Skip to content

Commit

Permalink
TerminalLoadingBox and related Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed May 21, 2020
1 parent 5bb04a1 commit b6de504
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import * as React from 'react';
import { LoadingBox } from '@console/internal/components/utils/status-box';

const TerminalLoadingBox: React.FC = () => (
<LoadingBox message="Connecting to your OpenShift command line terminal ..." />
type TerminalLoadingBoxProps = {
message?: string;
};
const TerminalLoadingBox: React.FC<TerminalLoadingBoxProps> = ({ message }) => (
<LoadingBox message={message || 'Connecting to your OpenShift command line terminal ...'} />
);

export default TerminalLoadingBox;
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as React from 'react';
import { shallow, mount } from 'enzyme';
import { shallow, ShallowWrapper } from 'enzyme';
import { useK8sWatchResource } from '@console/internal/components/utils/k8s-watch-hook';
import { LoadingBox } from '@console/internal/components/utils/status-box';
import { StatusBox } from '@console/internal/components/utils/status-box';
import { InternalCloudShellTerminal } from '../CloudShellTerminal';
import TerminalLoadingBox from '../TerminalLoadingBox';
import CloudShellSetup from '../setup/CloudShellSetup';

jest.mock('@console/internal/components/utils/k8s-watch-hook', () => ({
Expand All @@ -12,13 +13,19 @@ jest.mock('@console/internal/components/utils/k8s-watch-hook', () => ({
describe('CloudShellTerminal', () => {
it('should display loading box', () => {
(useK8sWatchResource as jest.Mock).mockReturnValueOnce([null, false]);
const wrapper = mount(<InternalCloudShellTerminal username="user" />);
expect(wrapper.find(LoadingBox)).toHaveLength(1);
const wrapper: ShallowWrapper = shallow(<InternalCloudShellTerminal username="user" />);
expect(wrapper.find(TerminalLoadingBox)).toHaveLength(1);
});

it('should display error statusBox', () => {
(useK8sWatchResource as jest.Mock).mockReturnValueOnce([null, false, true]);
const wrapper: ShallowWrapper = shallow(<InternalCloudShellTerminal username="user" />);
expect(wrapper.find(StatusBox)).toHaveLength(1);
});

it('should display form if loaded and no workspace', () => {
(useK8sWatchResource as jest.Mock).mockReturnValueOnce([[], true]);
const wrapper = shallow(<InternalCloudShellTerminal username="user" />);
const wrapper: ShallowWrapper = shallow(<InternalCloudShellTerminal username="user" />);
expect(wrapper.find(CloudShellSetup)).toHaveLength(1);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as React from 'react';
import { shallow, ShallowWrapper } from 'enzyme';
import { LoadingBox } from '@console/internal/components/utils/status-box';
import TerminalLoadingBox from '../TerminalLoadingBox';

describe('TerminalLoadingBox', () => {
it('should render cloudshellterminal', () => {
const terminalLoadingWrapper: ShallowWrapper = shallow(<TerminalLoadingBox />);
const loadingBox = terminalLoadingWrapper.find(LoadingBox);
expect(loadingBox.exists()).toBe(true);
expect(loadingBox.prop('message')).toEqual(
'Connecting to your OpenShift command line terminal ...',
);
});
it('should render cloudshellterminal', () => {
const terminalLoadingWrapper: ShallowWrapper = shallow(<TerminalLoadingBox message="test" />);
const loadingBox = terminalLoadingWrapper.find(LoadingBox);
expect(loadingBox.exists()).toBe(true);
expect(loadingBox.prop('message')).toEqual('test');
});
});

0 comments on commit b6de504

Please sign in to comment.