Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: connected instances extract hook refactoring (#6353)
- Loading branch information
Showing
2 changed files
with
147 additions
and
32 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
frontend/src/component/application/ConnectedInstances/ConnectedInstances.test.tsx
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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { screen } from '@testing-library/react'; | ||
import { render } from 'utils/testRenderer'; | ||
import { testServerRoute, testServerSetup } from 'utils/testServer'; | ||
import { Route, Routes } from 'react-router-dom'; | ||
import { ConnectedInstances } from './ConnectedInstances'; | ||
import { ApplicationEnvironmentInstancesSchemaInstancesItem } from '../../../openapi'; | ||
|
||
const server = testServerSetup(); | ||
|
||
const setupApi = ( | ||
instances: ApplicationEnvironmentInstancesSchemaInstancesItem[], | ||
) => { | ||
testServerRoute(server, '/api/admin/metrics/applications/my-app/overview', { | ||
environments: [{ name: 'development' }, { name: 'production' }], | ||
}); | ||
testServerRoute(server, '/api/admin/ui-config', {}); | ||
testServerRoute(server, '/api/admin/metrics/instances/my-app/development', { | ||
instances, | ||
}); | ||
testServerRoute(server, '/api/admin/metrics/instances/my-app/production', { | ||
instances: [ | ||
{ | ||
instanceId: 'shouldNotShowUp', | ||
clientIp: 'irrelevant', | ||
lastSeen: '2024-02-26T14:00:59.980Z', | ||
sdkVersion: 'irrelevant', | ||
}, | ||
], | ||
}); | ||
}; | ||
|
||
test('Display connected instances', async () => { | ||
setupApi([ | ||
{ | ||
instanceId: 'devInstance1', | ||
clientIp: '192.168.0.1', | ||
lastSeen: '2024-02-26T15:00:59.980Z', | ||
sdkVersion: 'unleash-client-node:5.5.0', | ||
}, | ||
{ | ||
instanceId: 'devInstance2', | ||
clientIp: '192.168.0.2', | ||
lastSeen: '2024-02-26T14:00:59.980Z', | ||
sdkVersion: 'unleash-client-node:5.5.1', | ||
}, | ||
]); | ||
render( | ||
<Routes> | ||
<Route | ||
path={'/applications/:name/instances'} | ||
element={<ConnectedInstances />} | ||
/> | ||
</Routes>, | ||
{ | ||
route: '/applications/my-app/instances', | ||
}, | ||
); | ||
|
||
await screen.findByText('development'); | ||
await screen.findByText('production'); | ||
await screen.findByText('devInstance1'); | ||
await screen.findByText('devInstance2'); | ||
await screen.findByText('192.168.0.1'); | ||
await screen.findByText('192.168.0.2'); | ||
await screen.findByText('unleash-client-node:5.5.0'); | ||
await screen.findByText('unleash-client-node:5.5.1'); | ||
|
||
expect(screen.queryByText('prodInstance')).not.toBeInTheDocument(); | ||
|
||
// check order | ||
const [, row1, row2] = screen.getAllByRole('row'); | ||
expect(row1.textContent?.includes('devInstance1')).toBe(true); | ||
expect(row2.textContent?.includes('devInstance2')).toBe(true); | ||
}); | ||
|
||
test('Display no connected instances', async () => { | ||
setupApi([]); | ||
render( | ||
<Routes> | ||
<Route | ||
path={'/applications/:name/instances'} | ||
element={<ConnectedInstances />} | ||
/> | ||
</Routes>, | ||
{ | ||
route: '/applications/my-app/instances', | ||
}, | ||
); | ||
|
||
await screen.findByText('development'); | ||
await screen.findByText('production'); | ||
await screen.findByText( | ||
"There's no data for any connected instances to display. Have you configured your clients correctly?", | ||
); | ||
}); |
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