-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[v16] Add Cluster Management page (#50213)
* Add Cluster Management page (#47899) * (wip) manage clusters page * Route for non-root cluster * Minor adjustments * Missing license header * UI improvements * Add `isCloud` to cluster info * Initial loading state * Storybook, tests * Lint fix, godoc, etc * Unexport getClusterInfo response * rename `c` to clusterDetails * Inline `IsCloud` * Import order and useAsync * Remove unnecessary godoc * Apply suggestions from code review: add blank line Co-authored-by: Sakshyam Shah <[email protected]> * address code review comments: import order, JS docs * Use msw for testing * Assert error message before asserting that the version is not shown --------- Co-authored-by: Sakshyam Shah <[email protected]> * adapt to v16 --------- Co-authored-by: Sakshyam Shah <[email protected]>
- Loading branch information
1 parent
04d1a52
commit cc15bef
Showing
14 changed files
with
526 additions
and
4 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
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
73 changes: 73 additions & 0 deletions
73
web/packages/teleport/src/Clusters/ManageCluster/ManageCluster.story.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,73 @@ | ||
/** | ||
* Teleport | ||
* Copyright (C) 2024 Gravitational, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { MemoryRouter } from 'react-router'; | ||
|
||
import { createTeleportContext } from 'teleport/mocks/contexts'; | ||
import { ContextProvider } from 'teleport/index'; | ||
import { ContentMinWidth } from 'teleport/Main/Main'; | ||
import { Route } from 'teleport/components/Router'; | ||
|
||
import { clusterInfoFixture } from '../fixtures'; | ||
|
||
import { ManageCluster } from './ManageCluster'; | ||
|
||
export default { | ||
title: 'Teleport/Clusters/ManageCluster', | ||
}; | ||
|
||
function render(fetchClusterDetails: (clusterId: string) => Promise<any>) { | ||
const ctx = createTeleportContext(); | ||
|
||
ctx.clusterService.fetchClusterDetails = fetchClusterDetails; | ||
return ( | ||
<MemoryRouter initialEntries={['/clusters/test-cluster']}> | ||
<Route path="/clusters/:clusterId"> | ||
<ContentMinWidth> | ||
<ContextProvider ctx={ctx}> | ||
<ManageCluster /> | ||
</ContextProvider> | ||
</ContentMinWidth> | ||
</Route> | ||
</MemoryRouter> | ||
); | ||
} | ||
|
||
export function Loading() { | ||
const fetchClusterDetails = () => { | ||
// promise never resolves to simulate loading state | ||
return new Promise(() => {}); | ||
}; | ||
return render(fetchClusterDetails); | ||
} | ||
|
||
export function Failed() { | ||
const fetchClusterDetails = () => | ||
Promise.reject(new Error('Failed to load cluster details')); | ||
return render(fetchClusterDetails); | ||
} | ||
|
||
export function Success() { | ||
const fetchClusterDetails = () => { | ||
return new Promise(resolve => { | ||
resolve(clusterInfoFixture); | ||
}); | ||
}; | ||
return render(fetchClusterDetails); | ||
} |
108 changes: 108 additions & 0 deletions
108
web/packages/teleport/src/Clusters/ManageCluster/ManageCluster.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,108 @@ | ||
/** | ||
* Teleport | ||
* Copyright (C) 2024 Gravitational, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { MemoryRouter, Route } from 'react-router-dom'; | ||
import { setupServer } from 'msw/node'; | ||
import { rest } from 'msw'; | ||
|
||
import { render, waitFor, screen } from 'design/utils/testing'; | ||
|
||
import { ContextProvider } from 'teleport/index'; | ||
import { createTeleportContext } from 'teleport/mocks/contexts'; | ||
import { ContentMinWidth } from 'teleport/Main/Main'; | ||
import cfg from 'teleport/config'; | ||
|
||
import { clusterInfoFixture } from '../fixtures'; | ||
|
||
import { ManageCluster } from './ManageCluster'; | ||
|
||
function renderElement(element, ctx) { | ||
return render( | ||
<MemoryRouter initialEntries={[`/clusters/cluster-id`]}> | ||
<Route path="/clusters/:clusterId"> | ||
<ContentMinWidth> | ||
<ContextProvider ctx={ctx}>{element}</ContextProvider> | ||
</ContentMinWidth> | ||
</Route> | ||
</MemoryRouter> | ||
); | ||
} | ||
|
||
describe('test ManageCluster component', () => { | ||
const server = setupServer( | ||
rest.get(cfg.getClusterInfoPath('cluster-id'), (req, res, ctx) => { | ||
return res( | ||
ctx.json({ | ||
name: 'cluster-id', | ||
lastConnected: new Date(), | ||
status: 'active', | ||
publicURL: 'cluster-id.teleport.com', | ||
authVersion: 'v17.0.0', | ||
proxyVersion: 'v17.0.0', | ||
isCloud: false, | ||
licenseExpiry: new Date(), | ||
}) | ||
); | ||
}) | ||
); | ||
|
||
beforeAll(() => server.listen()); | ||
afterEach(() => server.resetHandlers()); | ||
afterAll(() => server.close()); | ||
|
||
test('fetches cluster information on load', async () => { | ||
const ctx = createTeleportContext(); | ||
|
||
renderElement(<ManageCluster />, ctx); | ||
await waitFor(() => { | ||
expect(screen.getByText('v17.0.0')).toBeInTheDocument(); | ||
}); | ||
|
||
expect(screen.getByText('cluster-id')).toBeInTheDocument(); | ||
expect(screen.getByText('cluster-id.teleport.com')).toBeInTheDocument(); | ||
}); | ||
|
||
test('shows error when load fails', async () => { | ||
server.use( | ||
rest.get(cfg.getClusterInfoPath('cluster-id'), (req, res, ctx) => { | ||
return res( | ||
ctx.status(400), | ||
ctx.json({ | ||
message: 'Failed to load cluster information', | ||
}) | ||
); | ||
}) | ||
); | ||
|
||
const ctx = createTeleportContext(); | ||
|
||
renderElement(<ManageCluster />, ctx); | ||
await waitFor(() => { | ||
expect( | ||
screen.getByText('Failed to load cluster information') | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
await waitFor(() => { | ||
expect( | ||
screen.queryByText(clusterInfoFixture.authVersion) | ||
).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.