Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arc-2738 refresh functionality #218

Merged
merged 13 commits into from
Dec 12, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,13 @@ export const setUpGuideUpdateAvailableContainer = css`
width: 55%;
`;

export const setUpGuideUpdateAvailableLoadingContainer = css`
margin-top: ${token('space.1000')};
padding: ${token('space.1000')};
min-height: 180px;
text-align: center;
`;

export const setUpGuideUpdateAvailableIconContainer = css`
margin: ${token('space.0')} auto;
text-align: center;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import React from 'react';
import {
act,
fireEvent,
render,
screen,
waitFor
act, fireEvent, render, screen, waitFor
} from '@testing-library/react';
import { ConnectionPanelTop } from './ConnectionPanelTop';
import { ConnectedState } from '../StatusLabel/StatusLabel';
import { addConnectedState, ConnectionPanel } from './ConnectionPanel';
import { EventType, JenkinsServer } from '../../../../src/common/types';
import * as getAllJenkinsServersModule from '../../api/getAllJenkinsServers';
import { ConnectionPanelMain } from './ConnectionPanelMain';

const servers: JenkinsServer[] = [
{
Expand Down Expand Up @@ -324,7 +321,7 @@ describe('Connection Panel Suite', () => {
});
});

describe('Connection Panel Main', () => {
describe('ConnectionPanel', () => {
test('should render panel content for PENDING server', async () => {
jest.spyOn(getAllJenkinsServersModule, 'getAllJenkinsServers').mockResolvedValueOnce([servers[7]]);

Expand All @@ -338,7 +335,7 @@ describe('Connection Panel Suite', () => {
test('should render panel content for DUPLICATE server', async () => {
jest.spyOn(getAllJenkinsServersModule, 'getAllJenkinsServers').mockResolvedValueOnce([servers[5], servers[6]]);

render(<ConnectionPanel />);
render(<ConnectionPanel/>);

await waitFor(() => {
expect(screen.getByText('Duplicate server')).toBeInTheDocument();
Expand All @@ -348,8 +345,9 @@ describe('Connection Panel Suite', () => {
test('should render panel content for CONNECTED server without pipeline data', async () => {
jest.spyOn(getAllJenkinsServersModule, 'getAllJenkinsServers').mockResolvedValueOnce([servers[1]]);

render(<ConnectionPanel />);

await act(async () => {
render(<ConnectionPanel />);
await waitFor(() => {
expect(screen.getByText('No data received')).toBeInTheDocument();
expect(screen.queryByText('Pipeline')).not.toBeInTheDocument();
Expand Down Expand Up @@ -461,6 +459,56 @@ describe('Connection Panel Suite', () => {
expect(updateAvailableText).toBeInTheDocument();
});
});

test('should handle refreshing the panel for a server CONNECTED with pipeline data but no plugin config', async () => {
jest.spyOn(getAllJenkinsServersModule, 'getAllJenkinsServers').mockResolvedValueOnce([servers[4]]);

const { rerender } = render(<ConnectionPanel />);

await waitFor(() => {
expect(screen.getByText('CONNECTED')).toBeInTheDocument();
expect(screen.getByText('Pipeline')).toBeInTheDocument();
expect(screen.getByText('Event')).toBeInTheDocument();
expect(screen.getByText('Received')).toBeInTheDocument();
expect(screen.queryByText('Refresh')).not.toBeInTheDocument();
expect(screen.queryByText('To receive build and deployment data from this server:')).not.toBeInTheDocument();
});

await waitFor(() => {
fireEvent.click(screen.getByText('Set up guide'));
});

await waitFor(() => {
expect(screen.getByText('Refresh')).toBeInTheDocument();
expect(screen.queryByText('To receive build and deployment data from this server:')).not.toBeInTheDocument();

const updatedServerData = {
...servers[1],
pluginConfig: {
ipAddress: '10.10.10.12',
lastUpdatedOn: new Date()
}
};

jest.spyOn(getAllJenkinsServersModule, 'getAllJenkinsServers').mockResolvedValueOnce([updatedServerData]);

// Rerender the component with the updated data
rerender(<ConnectionPanelMain
connectedState={ConnectedState.CONNECTED}
jenkinsServer={updatedServerData}
refreshServers={jest.fn()}
/>);
});

await waitFor(() => {
fireEvent.click(screen.getByText('Set up guide'));
});

await waitFor(() => {
fireEvent.click(screen.getByText('Refresh'));
expect(screen.getByText('To receive build and deployment data from this server:')).toBeInTheDocument();
});
});
});
});
});
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React from 'react';
import { cx } from '@emotion/css';
import Button, { Appearance, ButtonGroup } from '@atlaskit/button';
import Spinner from '@atlaskit/spinner';
import { ConnectedState } from '../StatusLabel/StatusLabel';
import {
connectionPanelContainerContainer,
connectionPanelContainerHeader,
connectionPanelContainerParagraph
connectionPanelContainerParagraph,
notConnectedSpinnerContainer
} from './ConnectionPanel.styles';
import { ConnectionPendingIcon } from '../icons/ConnectionPendingIcon';
import { NoDataIcon } from '../icons/NoDataIcon';
Expand All @@ -21,7 +23,8 @@ type NotConnectedStateProps = {
secondButtonLabel?: string,
buttonOneOnClick(data?: any): void,
buttonTwoOnClick?(): void,
testId?: string
testId?: string,
isLoading: boolean
};

const ConnectionPanelContent = ({
Expand All @@ -34,7 +37,8 @@ const ConnectionPanelContent = ({
secondButtonLabel,
buttonOneOnClick,
buttonTwoOnClick,
testId
testId,
isLoading
}: NotConnectedStateProps): JSX.Element => {
let icon;

Expand All @@ -48,24 +52,32 @@ const ConnectionPanelContent = ({

return (
<div className={cx(connectionPanelContainerContainer)}>
{icon}
<h3 className={cx(connectionPanelContainerHeader)}>{contentHeader}</h3>
<p className={cx(connectionPanelContainerParagraph)}>{contentInstructionOne}</p>
<p className={cx(connectionPanelContainerParagraph)}>{contentInstructionTwo}</p>
<ButtonGroup>
<Button
appearance={buttonAppearance}
onClick={buttonOneOnClick}
testId={testId}
>
{firstButtonLabel}
</Button>
{
secondButtonLabel
? <Button onClick={buttonTwoOnClick}>{secondButtonLabel}</Button>
: <></>
}
</ButtonGroup>
{
isLoading
? <div className={cx(notConnectedSpinnerContainer)}>
<Spinner size='large' />
</div>
: <>
{icon}
<h3 className={cx(connectionPanelContainerHeader)}>{contentHeader}</h3>
<p className={cx(connectionPanelContainerParagraph)}>{contentInstructionOne}</p>
<p className={cx(connectionPanelContainerParagraph)}>{contentInstructionTwo}</p>
<ButtonGroup>
<Button
appearance={buttonAppearance}
onClick={buttonOneOnClick}
testId={testId}
>
{firstButtonLabel}
</Button>
{
secondButtonLabel
? <Button onClick={buttonTwoOnClick}>{secondButtonLabel}</Button>
: <></>
}
</ButtonGroup>
</>
}
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import React, { ReactNode, useState } from 'react';
import { cx } from '@emotion/css';
import Tabs, { Tab, TabList, TabPanel } from '@atlaskit/tabs';
import Spinner from '@atlaskit/spinner';
import {
connectionPanelMainContainer,
connectionPanelMainConnectedTabs,
connectionPanelMainNotConnectedTabs,
setUpGuideContainer,
setUpGuideUpdateAvailableContainer, connectionPanelMainConnectedPendingSetUp
setUpGuideUpdateAvailableContainer,
connectionPanelMainConnectedPendingSetUp,
setUpGuideUpdateAvailableLoadingContainer
} from './ConnectionPanel.styles';
import { ConnectedState } from '../StatusLabel/StatusLabel';
import { NotConnectedState } from './NotConnectedState';
import { JenkinsServer } from '../../../../src/common/types';
import { ConnectedJenkinsServers } from './ConnectedJenkinsServers';
import { SetUpGuide, UpdateAvailable } from './SetUpGuide';
import { ConnectionPanelContent } from './ConnectionPanelContent';
import { getJenkinsServerWithSecret } from '../../api/getJenkinsServerWithSecret';

type PanelProps = {
children: ReactNode,
Expand Down Expand Up @@ -54,6 +58,8 @@ const ConnectionPanelMain = ({
refreshServers
}: ConnectionPanelMainProps): JSX.Element => {
const [selectedTabIndex, setSelectedTabIndex] = useState(0);
const [isLoading, setIsLoading] = useState(false);
const [updatedServer, setUpdatedServer] = useState<JenkinsServer>();

const handleClickSetupGuide = () => {
setSelectedTabIndex(1);
Expand All @@ -63,10 +69,47 @@ const ConnectionPanelMain = ({
setSelectedTabIndex(index);
};

const handleRefreshPanel = () => {
// TODO - ARC-2738 refresh functionality
const handleRefreshPanel = async () => {
setIsLoading(true);
try {
const server = await getJenkinsServerWithSecret(jenkinsServer.uuid);
setUpdatedServer(server);
} catch (e) {
console.error('No Jenkins server found.');
}

setIsLoading(false);
};

let setUpGuideUpdateAvailableContent;

if (isLoading) {
setUpGuideUpdateAvailableContent = (
<Panel data-testid="updateAvailable">
<div className={cx(setUpGuideUpdateAvailableLoadingContainer)}>
<Spinner size='large' />
</div>
</Panel>
);
} else if (jenkinsServer.pluginConfig || updatedServer?.pluginConfig) {
setUpGuideUpdateAvailableContent = (
<Panel data-testid="setUpGuidePanel">
<SetUpGuide pluginConfig={jenkinsServer.pluginConfig} />
</Panel>
);
} else {
setUpGuideUpdateAvailableContent = (
<Panel data-testid="updateAvailable">
<div className={cx(setUpGuideUpdateAvailableContainer)}>
<UpdateAvailable
handleRefreshPanel={handleRefreshPanel}
jenkinsServer={jenkinsServer}
/>
</div>
</Panel>
);
}

return (
<div className={cx(connectionPanelMainContainer)}>
{
Expand All @@ -76,6 +119,8 @@ const ConnectionPanelMain = ({
jenkinsServer={jenkinsServer}
refreshServers={refreshServers}
handleRefreshPanel={handleRefreshPanel}
isLoading={isLoading}
setIsLoading={setIsLoading}
/>
: <Tabs id="connection-panel-tabs" selected={selectedTabIndex} onChange={handleTabSelect}>
<TabList>
Expand Down Expand Up @@ -108,6 +153,7 @@ const ConnectionPanelMain = ({
secondButtonLabel="Refresh"
buttonOneOnClick={handleClickSetupGuide}
buttonTwoOnClick={handleRefreshPanel}
isLoading={isLoading}
/>
}
</Panel>
Expand All @@ -117,23 +163,13 @@ const ConnectionPanelMain = ({
jenkinsServer={jenkinsServer}
refreshServers={refreshServers}
handleRefreshPanel={handleRefreshPanel}
isLoading={isLoading}
setIsLoading={setIsLoading}
/>
</Panel>
}
</TabPanel>
<TabPanel>
{
jenkinsServer.pluginConfig
? <Panel data-testid="setUpGuidePanel">
<SetUpGuide pluginConfig={jenkinsServer.pluginConfig}/>
</Panel>
: <Panel data-testid="updateAvailable">
<div className={cx(setUpGuideUpdateAvailableContainer)}>
<UpdateAvailable />
</div>
</Panel>
}
</TabPanel>
<TabPanel>{setUpGuideUpdateAvailableContent}</TabPanel>
</Tabs>
}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ describe('NotConnectedState', () => {

const refreshServers = jest.fn();
const handleRefreshPanel = jest.fn();
const setIsLoading = jest.fn();

test('renders with connected state DUPLICATE', () => {
render(<NotConnectedState
connectedState={ConnectedState.DUPLICATE}
jenkinsServer={mockServer}
refreshServers={refreshServers}
handleRefreshPanel={handleRefreshPanel}
isLoading={false}
setIsLoading={setIsLoading}
/>);
expect(screen.getByText('Duplicate server')).toBeInTheDocument();
expect(screen.getByText('Delete')).toBeInTheDocument();
Expand All @@ -40,6 +43,8 @@ describe('NotConnectedState', () => {
jenkinsServer={mockServer}
refreshServers={refreshServers}
handleRefreshPanel={handleRefreshPanel}
isLoading={false}
setIsLoading={setIsLoading}
/>);
expect(screen.getByText('Connection pending')).toBeInTheDocument();
expect(screen.getByText('Refresh')).toBeInTheDocument();
Expand All @@ -53,6 +58,8 @@ describe('NotConnectedState', () => {
jenkinsServer={mockServer}
refreshServers={refreshServers}
handleRefreshPanel={handleRefreshPanel}
isLoading={false}
setIsLoading={setIsLoading}
/>);

fireEvent.click(screen.getByText('Delete'));
Expand Down
Loading