-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andrew Oseen
committed
Sep 26, 2023
1 parent
89bab66
commit 9335722
Showing
14 changed files
with
207 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,39 @@ | ||
import React from 'react'; | ||
import { Status } from 'shared/types'; | ||
import { renderWithProviders } from 'utils/tests'; | ||
import StatusBadge from './StatusBadge'; | ||
import StatusTag from './StatusTag'; | ||
|
||
describe('StatusTag Component', () => { | ||
const renderComponent = (status: Status, text?: string) => { | ||
return renderWithProviders(<StatusBadge status={status} text={text} />); | ||
const renderComponent = (status: Status) => { | ||
const result = renderWithProviders(<StatusTag status={status} />); | ||
return { | ||
...result, | ||
dot: result.container.querySelector('.ant-tag'), | ||
}; | ||
}; | ||
|
||
it('should render the Starting status', () => { | ||
const { container } = renderComponent(Status.Starting); | ||
const element = container.querySelector( | ||
'.ant-badge-status-dot.ant-badge-status-processing', | ||
); | ||
|
||
expect(element).not.toBeNull(); | ||
const { dot } = renderComponent(Status.Starting); | ||
expect(dot).toHaveClass('ant-tag-blue'); | ||
}); | ||
|
||
it('should render the Started status', () => { | ||
const { container } = renderComponent(Status.Started); | ||
const element = container.querySelector( | ||
'.ant-badge-status-dot.ant-badge-status-success', | ||
); | ||
|
||
expect(element).not.toBeNull(); | ||
const { dot } = renderComponent(Status.Started); | ||
expect(dot).toHaveClass('ant-tag-green'); | ||
}); | ||
|
||
it('should render the Stopping status', () => { | ||
const { container } = renderComponent(Status.Stopping); | ||
const element = container.querySelector( | ||
'.ant-badge-status-dot.ant-badge-status-processing', | ||
); | ||
|
||
expect(element).not.toBeNull(); | ||
const { dot } = renderComponent(Status.Stopping); | ||
expect(dot).toHaveClass('ant-tag-blue'); | ||
}); | ||
|
||
it('should render the Stopped status', () => { | ||
const { container } = renderComponent(Status.Stopped); | ||
const element = container.querySelector( | ||
'.ant-badge-status-dot.ant-badge-status-default', | ||
); | ||
|
||
expect(element).not.toBeNull(); | ||
const { dot } = renderComponent(Status.Stopped); | ||
expect(dot).toHaveClass('ant-tag-red'); | ||
}); | ||
|
||
it('should render the Error status', () => { | ||
const { container } = renderComponent(Status.Error); | ||
const element = container.querySelector( | ||
'.ant-badge-status-dot.ant-badge-status-error', | ||
); | ||
|
||
expect(element).not.toBeNull(); | ||
const { dot } = renderComponent(Status.Error); | ||
expect(dot).toHaveClass('ant-tag-red'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,44 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { Status } from 'shared/types'; | ||
import { getNetwork, injections, renderWithProviders } from 'utils/tests'; | ||
import StatusTag from './StatusTag'; | ||
|
||
const dockerServiceMock = injections.dockerService as jest.Mocked< | ||
typeof injections.dockerService | ||
>; | ||
import StatusBadge from './StatusBadge'; | ||
|
||
describe('StatusTag Component', () => { | ||
const renderComponent = (status: Status, externalNetworkName: string) => { | ||
const network = getNetwork(0, 'test network', status); | ||
network.externalNetworkName = externalNetworkName; | ||
const initialState = { | ||
network: { | ||
networks: [network], | ||
}, | ||
}; | ||
const result = renderWithProviders(<StatusTag networkId={0} />, { initialState }); | ||
const renderComponent = (status: Status, text?: string) => { | ||
const result = render(<StatusBadge status={status} text={text} />); | ||
return { | ||
...result, | ||
dot: result.container.querySelector('.ant-badge span:first-child'), | ||
}; | ||
}; | ||
|
||
it('should render the Error status', async () => { | ||
dockerServiceMock.getDockerExternalNetworks.mockResolvedValue([ | ||
'test-network-1', | ||
'test-network-2', | ||
]); | ||
const docker_network_name = 'test-network-1'; | ||
it('should render the text', () => { | ||
const { getByText } = renderComponent(Status.Starting, 'test text'); | ||
expect(getByText('test text')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render the Starting status', () => { | ||
const { dot } = renderComponent(Status.Starting); | ||
expect(dot).toHaveClass('ant-badge-status-processing'); | ||
}); | ||
|
||
it('should render the Started status', () => { | ||
const { dot } = renderComponent(Status.Started); | ||
expect(dot).toHaveClass('ant-badge-status-success'); | ||
}); | ||
|
||
it('should render the Stopping status', () => { | ||
const { dot } = renderComponent(Status.Stopping); | ||
expect(dot).toHaveClass('ant-badge-status-processing'); | ||
}); | ||
|
||
const { findByText } = renderComponent(Status.Started, docker_network_name); | ||
const textElement = await findByText(`External: ${docker_network_name}`); | ||
expect(textElement).toBeInTheDocument(); | ||
it('should render the Stopped status', () => { | ||
const { dot } = renderComponent(Status.Stopped); | ||
expect(dot).toHaveClass('ant-badge-status-default'); | ||
}); | ||
it('should render the Error status', async () => { | ||
dockerServiceMock.getDockerExternalNetworks.mockResolvedValue([ | ||
'test-network-1', | ||
'test-network-2', | ||
]); | ||
const docker_network_name = 'test-network-3'; | ||
|
||
const { findByText } = renderComponent(Status.Started, docker_network_name); | ||
const textElement = await findByText( | ||
`External Docker Network: ${docker_network_name} does not exist`, | ||
); | ||
expect(textElement).toBeInTheDocument(); | ||
it('should render the Error status', () => { | ||
const { dot } = renderComponent(Status.Error); | ||
expect(dot).toHaveClass('ant-badge-status-error'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,24 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { Row, Tag } from 'antd'; | ||
import { useTheme } from 'hooks/useTheme'; | ||
import { Tag } from 'antd'; | ||
import { Status } from 'shared/types'; | ||
import { useStoreActions, useStoreState } from 'store'; | ||
|
||
export interface StatusTagProps { | ||
networkId: number; | ||
status: Status; | ||
} | ||
|
||
const StatusTag: React.FC<StatusTagProps> = ({ networkId }) => { | ||
const StatusTag: React.FC<StatusTagProps> = ({ status }) => { | ||
const { t } = useTranslation(); | ||
|
||
const { networks } = useStoreState(s => s.network); | ||
const network = networks.find(n => n.id === networkId); | ||
const { getExternalDockerNetworks } = useStoreActions(s => s.network); | ||
const [dockerNetworks, setDockerNetworks] = useState<string[]>([]); | ||
|
||
const { statusTag } = useTheme(); | ||
|
||
const statusColors = { | ||
[Status.Starting]: 'blue', | ||
[Status.Started]: 'green', | ||
[Status.Stopping]: 'blue', | ||
[Status.Stopped]: statusTag.stopped, | ||
[Status.Stopped]: 'red', | ||
[Status.Error]: 'red', | ||
}; | ||
|
||
useEffect(() => { | ||
(async () => { | ||
const networks = await getExternalDockerNetworks(); | ||
setDockerNetworks(networks); | ||
})(); | ||
}, [network?.externalNetworkName]); | ||
|
||
const cmp = | ||
network?.externalNetworkName && | ||
dockerNetworks.includes(network?.externalNetworkName) ? ( | ||
<Tag color="blue">{`External: ${network.externalNetworkName}`}</Tag> | ||
) : ( | ||
<Tag color="error">{`External Docker Network: ${network?.externalNetworkName} does not exist`}</Tag> | ||
); | ||
|
||
return ( | ||
<Row> | ||
{network && ( | ||
<Tag color={statusColors[network.status]}> | ||
{t(`enums.status.${Status[network.status]}`)} | ||
</Tag> | ||
)} | ||
{cmp} | ||
</Row> | ||
); | ||
return <Tag color={statusColors[status]}>{t(`enums.status.${Status[status]}`)}</Tag>; | ||
}; | ||
|
||
export default StatusTag; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.