Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: project applications table (#6321)
- Loading branch information
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
frontend/src/component/project/ProjectApplications/ProjectApplications.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,80 @@ | ||
import { screen } from '@testing-library/react'; | ||
import { render } from 'utils/testRenderer'; | ||
import { testServerRoute, testServerSetup } from 'utils/testServer'; | ||
import { ProjectApplications } from './ProjectApplications'; | ||
import { ProjectApplicationSchema } from '../../../openapi'; | ||
import { Route, Routes } from 'react-router-dom'; | ||
import { SEARCH_INPUT } from 'utils/testIds'; | ||
|
||
const server = testServerSetup(); | ||
|
||
const setupApi = (applications: ProjectApplicationSchema[]) => { | ||
testServerRoute(server, '/api/admin/projects/default/applications', { | ||
applications, | ||
total: applications.length, | ||
}); | ||
testServerRoute(server, '/api/admin/ui-config', {}); | ||
}; | ||
|
||
test('Display applications list', async () => { | ||
setupApi([ | ||
{ | ||
name: 'app-one', | ||
environments: ['development'], | ||
instances: ['instance1'], | ||
sdks: [{ name: 'unleash-client-node', versions: ['5.5.0'] }], | ||
}, | ||
{ | ||
name: 'app-two', | ||
environments: ['development', 'production'], | ||
instances: ['instance1', 'instance2'], | ||
sdks: [ | ||
{ name: 'unleash-client-node', versions: ['5.5.0', '5.6.0'] }, | ||
{ name: 'unleash-client-java', versions: ['3.5.0'] }, | ||
], | ||
}, | ||
]); | ||
render( | ||
<Routes> | ||
<Route | ||
path={'/projects/:projectId/applications'} | ||
element={<ProjectApplications />} | ||
/> | ||
</Routes>, | ||
{ | ||
route: '/projects/default/applications?query=app', | ||
}, | ||
); | ||
|
||
await screen.findByText('-one'); | ||
await screen.findByText('1 environment'); | ||
await screen.findByText('1 instance'); | ||
await screen.findByText('1 sdk'); | ||
|
||
await screen.findByText('-two'); | ||
await screen.findByText('2 environments'); | ||
await screen.findByText('2 instances'); | ||
await screen.findByText('2 sdks'); | ||
|
||
// two highlights | ||
expect(screen.queryAllByText('app').length).toBe(2); | ||
|
||
expect(screen.getByTestId(SEARCH_INPUT)).toHaveValue('app'); | ||
}); | ||
|
||
test('Display no applications found', async () => { | ||
setupApi([]); | ||
render( | ||
<Routes> | ||
<Route | ||
path={'/projects/:projectId/applications'} | ||
element={<ProjectApplications />} | ||
/> | ||
</Routes>, | ||
{ | ||
route: '/projects/default/applications?query=', | ||
}, | ||
); | ||
|
||
await screen.findByText('No applications found matching your criteria.'); | ||
}); |