-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
133895: ui: reroute v2 db page to legacy page when cluster is unfinalized r=xinhaoz a=xinhaoz The migrations that support the v2 db page runs on finalization. Rather than show a non-functional page in an unfinalized cluster state let's reroute to the legacy page. Epic: CRDB-37558 Fixes: #133843 Release note (ui change): The v2 db pages will only be available post ugprade finalization to 24.3. Prior to that we'll continue to show the legacy page when the cluster is in its unfinalized state. Co-authored-by: Xin Hao Zhang <[email protected]>
- Loading branch information
Showing
2 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
pkg/ui/workspaces/cluster-ui/src/databasesV2/index.spec.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,88 @@ | ||
// Copyright 2024 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the CockroachDB Software License | ||
// included in the /LICENSE file. | ||
|
||
import "@testing-library/jest-dom"; | ||
import { render, screen } from "@testing-library/react"; | ||
import React from "react"; | ||
import { MemoryRouter, Route, Switch } from "react-router-dom"; | ||
|
||
import * as dbApi from "src/api/databases/getDatabaseMetadataApi"; | ||
import { CockroachCloudContext } from "src/contexts"; | ||
|
||
import { DatabasesPageV2 } from "./"; | ||
|
||
jest.mock("src/api/fetchData", () => ({ | ||
fetchDataJSON: jest.fn().mockResolvedValue(null), | ||
fetchData: jest.fn().mockResolvedValue(null), | ||
})); | ||
|
||
const mockDatabaseMetadata = (errorStatus: number | null, data?: null | []) => { | ||
jest.spyOn(dbApi, "useDatabaseMetadata").mockReturnValue({ | ||
error: errorStatus ? { status: errorStatus } : null, | ||
refreshDatabases: jest.fn(), | ||
data: data | ||
? { | ||
results: data, | ||
pagination: { | ||
pageSize: 1, | ||
pageNum: 1, | ||
totalResults: 0, | ||
}, | ||
} | ||
: null, | ||
isLoading: false, | ||
}); | ||
}; | ||
|
||
describe("DatabasesPageV2 redirect", () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
const renderWithRouter = (initialEntries: string[], isCloud = false) => | ||
render( | ||
<CockroachCloudContext.Provider value={isCloud}> | ||
<MemoryRouter initialEntries={initialEntries}> | ||
<Switch> | ||
<Route path="/databases"> | ||
<DatabasesPageV2 /> | ||
</Route> | ||
<Route path="/legacy/databases"> | ||
<div>Legacy Databases Page</div> | ||
</Route> | ||
</Switch> | ||
</MemoryRouter> | ||
</CockroachCloudContext.Provider>, | ||
); | ||
|
||
it("redirects to /legacy/databases on 409 error", () => { | ||
mockDatabaseMetadata(409); | ||
|
||
renderWithRouter(["/databases"]); | ||
|
||
expect(screen.getByText("Legacy Databases Page")).toBeInTheDocument(); | ||
}); | ||
|
||
it.each([ | ||
{ error: 400, data: null }, | ||
{ error: 500, data: null }, | ||
{ error: null, data: [] }, | ||
])("does not redirect on other responses", ({ error, data }) => { | ||
mockDatabaseMetadata(error, data); | ||
|
||
renderWithRouter(["/databases"]); | ||
|
||
jest.clearAllMocks(); | ||
expect(screen.queryByText("Legacy Databases Page")).not.toBeInTheDocument(); | ||
}); | ||
|
||
it("does not redirect on 409 if on cloud", () => { | ||
mockDatabaseMetadata(409); | ||
|
||
renderWithRouter(["/databases"], true); | ||
|
||
expect(screen.queryByText("Legacy Databases Page")).not.toBeInTheDocument(); | ||
}); | ||
}); |
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