Skip to content

Commit

Permalink
merge in iph changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rachellerathbone committed Dec 11, 2023
2 parents 8c31a81 + bc823f6 commit 9c39d43
Show file tree
Hide file tree
Showing 22 changed files with 651 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,22 @@ export const notConnectedSpinnerContainer = css`
width: 100%;
`;

// TODO - delete this temp class
export const notConnectedTempImgPlaceholder = css`
background-color: lightgrey;
border: 1px solid lightgrey;
border-radius: 3px;
height: 160px;
margin: auto;
width: 160px;
export const connectionPanelContainerContainer = css`
margin: ${token('space.600')} auto;
max-height: 400px;
min-height: 400px;
max-width: 420px;
position: relative;
text-align: center;
`;

export const notConnectedStateHeader = css`
export const connectionPanelContainerHeader = css`
font-size: 20px;
font-weight: 500;
margin: ${token('space.200')} auto;
`;

export const notConnectedStateParagraph = css`
export const connectionPanelContainerParagraph = css`
font-size: 14px;
line-height: 20px;
margin-bottom: ${token('space.400')};
Expand Down Expand Up @@ -233,13 +232,6 @@ export const setUpGuideOrderListItemHeader = css`
margin-bottom: ${token('space.200')};
`;

export const setUpGuideLink = css`
background-color: inherit;
border: none;
color: ${token('color.link')};
padding: ${token('space.0')}
`;

export const setUpGuideInfoPanel = css`
background-color: #F7F8F9;
display: flex;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import {
act,
fireEvent,
render,
screen,
Expand Down Expand Up @@ -105,6 +106,12 @@ const servers: JenkinsServer[] = [
lastUpdatedOn: new Date()
},
pipelines: []
},
{
name: 'server eight',
uuid: '56046af9-d0eb-4efb-8896-iwer23rjesu',
pluginConfig: undefined,
pipelines: []
}
];

Expand Down Expand Up @@ -133,37 +140,38 @@ describe('Connection Panel Suite', () => {
expect(result[0].connectedState).toEqual(ConnectedState.CONNECTED);
});

it('should correctly set state for two servers with different IPs', () => {
const twoServers: JenkinsServer[] = [servers[0], servers[1]];
const result = addConnectedState(twoServers);

expect(result[0].connectedState).toEqual(ConnectedState.CONNECTED);
expect(result[1].connectedState).toEqual(ConnectedState.PENDING);
});

it('should correctly set state for multiple servers with duplicate IPs', () => {
const multipleServers: JenkinsServer[] = [servers[0], servers[2], servers[3]];
const result = addConnectedState(multipleServers);
const multipleServers: JenkinsServer[] = [servers[0], servers[2], servers[3], servers[7]];
const results = addConnectedState(multipleServers);

expect(result[0].connectedState).toEqual(ConnectedState.CONNECTED);
expect(result[1].connectedState).toEqual(ConnectedState.CONNECTED);
expect(result[2].connectedState).toEqual(ConnectedState.DUPLICATE);
expect(results[0].connectedState).toEqual(ConnectedState.CONNECTED);
expect(results[1].connectedState).toEqual(ConnectedState.CONNECTED);
expect(results[2].connectedState).toEqual(ConnectedState.DUPLICATE);
expect(results[3].connectedState).toEqual(ConnectedState.PENDING);
});

it('should handle servers with no pluginConfig', () => {
const noPluginConfig: JenkinsServer[] = [servers[4]];
const result = addConnectedState(noPluginConfig);
it('should handle servers with missing data', () => {
const noPluginConfigAndNoPipelines: JenkinsServer[] = [servers[7]];
const noPluginConfigButHasPipelines: JenkinsServer[] = [servers[4]];
const hasPluginConfigButNoPipelines: JenkinsServer[] = [servers[6]];

const noPluginConfigAndNoPipelinesResult = addConnectedState(noPluginConfigAndNoPipelines);
const noPluginConfigButHasPipelinesResult = addConnectedState(noPluginConfigButHasPipelines);
const hasPluginConfigButNoPipelinesResult = addConnectedState(hasPluginConfigButNoPipelines);

expect(result[0].connectedState).toEqual(ConnectedState.PENDING);
expect(noPluginConfigButHasPipelinesResult[0].connectedState).toEqual(ConnectedState.CONNECTED);
expect(noPluginConfigAndNoPipelinesResult[0].connectedState).toEqual(ConnectedState.PENDING);
expect(hasPluginConfigButNoPipelinesResult[0].connectedState).toEqual(ConnectedState.CONNECTED);
});

it('should correctly set state for multiple servers with duplicate IPs and no pipelines', () => {
const duplicateServers: JenkinsServer[] = [servers[1], servers[5], servers[6]];
const result = addConnectedState(duplicateServers);

expect(result[0].connectedState).toEqual(ConnectedState.CONNECTED);
expect(result[1].connectedState).toEqual(ConnectedState.PENDING);
expect(result[1].connectedState).toEqual(ConnectedState.CONNECTED);
expect(result[2].connectedState).toEqual(ConnectedState.DUPLICATE);
expect(result[2].originalConnection).toEqual(servers[5].name);
});
});

Expand Down Expand Up @@ -241,14 +249,7 @@ describe('Connection Panel Suite', () => {
const server: JenkinsServer = {
name: 'my server',
connectedState: ConnectedState.PENDING,
pluginConfig: {
ipAddress: '10.0.0.1',
lastUpdatedOn: new Date(),
autoBuildRegex: '',
autoBuildEnabled: true,
autoDeploymentsEnabled: false,
autoDeploymentsRegex: ''
},
pluginConfig: undefined,
uuid: 'djsnfudin-jhsdwefwe-238hnfuwef',
pipelines: []
};
Expand All @@ -261,11 +262,11 @@ describe('Connection Panel Suite', () => {
);

const nameLabel = screen.getByText(server.name);
const ipAddressLabel = screen.getByText(`IP address: ${server.pluginConfig?.ipAddress}`);
const ipAddressLabel = screen.queryByText(`IP address: ${server.pluginConfig?.ipAddress}`);
const statusLabel = screen.getByTestId('status-label');

expect(nameLabel).toBeInTheDocument();
expect(ipAddressLabel).toBeInTheDocument();
expect(ipAddressLabel).not.toBeInTheDocument();
expect(statusLabel).toHaveStyle({ color: '#a54900', backgroundColor: '#fff7d6' });
expect(statusLabel).toHaveTextContent('PENDING');
});
Expand Down Expand Up @@ -299,6 +300,7 @@ describe('Connection Panel Suite', () => {
// TODO - add test for Rename - will be done when I build the new server name screen

// TODO - add test for Connection settings - will be done when I build the new set up Jenkins screen

test('should handle server disconnection and refreshing correctly', async () => {
jest.spyOn(getAllJenkinsServersModule, 'getAllJenkinsServers').mockResolvedValueOnce(servers);

Expand All @@ -325,6 +327,53 @@ describe('Connection Panel Suite', () => {
describe('Connection Panel Main', () => {
const setJenkinsServers = jest.fn();

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

render(<ConnectionPanel jenkinsServers={servers} setJenkinsServers={setJenkinsServers} />);

await waitFor(() => {
expect(screen.getByText('Connection pending')).toBeInTheDocument();
});
});

test('should render panel content for DUPLICATE server', async () => {
jest.spyOn(getAllJenkinsServersModule, 'getAllJenkinsServers').mockResolvedValueOnce([servers[5], servers[6]]);

render(<ConnectionPanel jenkinsServers={servers} setJenkinsServers={setJenkinsServers} />);

await waitFor(() => {
expect(screen.getByText('Duplicate server')).toBeInTheDocument();
});
});

test('should render panel content for CONNECTED server without pipeline data', async () => {
jest.spyOn(getAllJenkinsServersModule, 'getAllJenkinsServers').mockResolvedValueOnce([servers[1]]);

await act(async () => {
render(<ConnectionPanel jenkinsServers={servers} setJenkinsServers={setJenkinsServers} />);
await waitFor(() => {
expect(screen.getByText('No data received')).toBeInTheDocument();
expect(screen.queryByText('Pipeline')).not.toBeInTheDocument();
expect(screen.queryByText('Event')).not.toBeInTheDocument();
expect(screen.queryByText('Received')).not.toBeInTheDocument();
});
});
});

test('should render panel content for CONNECTED server with pipeline data', async () => {
jest.spyOn(getAllJenkinsServersModule, 'getAllJenkinsServers').mockResolvedValueOnce([servers[5]]);

render(<ConnectionPanel jenkinsServers={servers} setJenkinsServers={setJenkinsServers} />);

await waitFor(() => {
expect(screen.queryByText('No data received')).not.toBeInTheDocument();
expect(screen.getByText('Pipeline')).toBeInTheDocument();
expect(screen.getByText('Event')).toBeInTheDocument();
expect(screen.getByText('Received')).toBeInTheDocument();
});
});

test('should handle server deletion correctly for DUPLICATE SERVERS', async () => {
jest.spyOn(getAllJenkinsServersModule, 'getAllJenkinsServers').mockResolvedValueOnce(servers);

Expand Down Expand Up @@ -405,7 +454,6 @@ describe('Connection Panel Suite', () => {

await waitFor(() => {
expect(screen.getByText(server.name)).toBeInTheDocument();

fireEvent.click(screen.getByText('Set up guide'));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,32 @@ export const addConnectedState = (servers: JenkinsServer[]): JenkinsServer[] =>
return servers
.slice() // Create a shallow copy to avoid mutating the original array
.sort((a, b) => b.pipelines.length - a.pipelines.length)
.map((server: JenkinsServer) => {
.map((server: JenkinsServer, index, array) => {
const ipAddress = server.pluginConfig?.ipAddress;
let connectedState = ConnectedState.PENDING;
let originalConnection: string | undefined;

if (ipAddress && ipAddressSet.has(ipAddress)) {
connectedState = ConnectedState.DUPLICATE;
} else if (server.pipelines.length > 0 && ipAddress) {

// Find the original connection with the same IP address
const originalServer = array.find(
(s) => s !== server && s.pluginConfig?.ipAddress === ipAddress &&
s.connectedState !== ConnectedState.DUPLICATE
);

if (originalServer) {
originalConnection = originalServer.name;
}
} else if (server.pluginConfig || server.pipelines.length) {
connectedState = ConnectedState.CONNECTED;
ipAddressSet.add(ipAddress);
if (ipAddress) ipAddressSet.add(ipAddress);
}

return {
...server,
connectedState
connectedState,
originalConnection
};
});
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import React from 'react';
import { cx } from '@emotion/css';
import Button, { Appearance, ButtonGroup } from '@atlaskit/button';
import { ConnectedState } from '../StatusLabel/StatusLabel';
import {
connectionPanelContainerContainer,
connectionPanelContainerHeader,
connectionPanelContainerParagraph
} from './ConnectionPanel.styles';
import { ConnectionPendingIcon } from '../icons/ConnectionPendingIcon';
import { NoDataIcon } from '../icons/NoDataIcon';
import { DuplicateServerIcon } from '../icons/DuplicateServerIcon';

type NotConnectedStateProps = {
connectedState: ConnectedState;
contentHeader: string,
contentInstructionOne: string,
contentInstructionTwo?: string,
buttonAppearance: Appearance,
firstButtonLabel: string,
secondButtonLabel?: string,
buttonOneOnClick(data?: any): void,
buttonTwoOnClick?(): void,
testId?: string
};

const ConnectionPanelContent = ({
connectedState,
contentHeader,
contentInstructionOne,
contentInstructionTwo,
buttonAppearance,
firstButtonLabel,
secondButtonLabel,
buttonOneOnClick,
buttonTwoOnClick,
testId
}: NotConnectedStateProps): JSX.Element => {
let icon;

if (connectedState === ConnectedState.CONNECTED) {
icon = <NoDataIcon />;
} else if (connectedState === ConnectedState.PENDING) {
icon = <ConnectionPendingIcon />;
} else {
icon = <DuplicateServerIcon />;
}

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>
</div>
);
};

export { ConnectionPanelContent };
Loading

0 comments on commit 9c39d43

Please sign in to comment.