-
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.
Merge pull request #74530 from cockroachdb/blathers/backport-release-…
…21.2-74408 release-21.2: cluster-ui: enable terminate session / query buttons
- Loading branch information
Showing
14 changed files
with
268 additions
and
12 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
85 changes: 85 additions & 0 deletions
85
pkg/ui/workspaces/cluster-ui/src/sessions/sessionDetails.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,85 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
import React from "react"; | ||
import { createMemoryHistory } from "history"; | ||
import { MemoryRouter } from "react-router-dom"; | ||
import { render, screen } from "@testing-library/react"; | ||
|
||
import SessionDetails, { SessionDetailsProps } from "./sessionDetails"; | ||
import { activeSession } from "./sessionsPage.fixture"; | ||
|
||
describe("SessionDetails", () => { | ||
const irrelevantProps: SessionDetailsProps = { | ||
history: createMemoryHistory({ initialEntries: ["/sessions"] }), | ||
location: { | ||
pathname: "/sessions/blah", | ||
search: "", | ||
hash: "", | ||
state: null, | ||
}, | ||
match: { | ||
path: "/sessions/blah", | ||
url: "/sessions/blah", | ||
isExact: true, | ||
params: { session: "blah" }, | ||
}, | ||
nodeNames: {}, | ||
session: activeSession, | ||
sessionError: null, | ||
refreshSessions: () => {}, | ||
refreshNodes: () => {}, | ||
refreshNodesLiveness: () => {}, | ||
cancelSession: _ => {}, // eslint-disable-line @typescript-eslint/no-unused-vars | ||
cancelQuery: _ => {}, // eslint-disable-line @typescript-eslint/no-unused-vars | ||
}; | ||
|
||
const irrelevantUIConfig: Omit< | ||
SessionDetailsProps["uiConfig"], | ||
"showTerminateActions" | ||
> = { | ||
showGatewayNodeLink: true, | ||
}; | ||
|
||
it("shows the cancel buttons by default", () => { | ||
render( | ||
<MemoryRouter> | ||
<SessionDetails {...irrelevantProps} /> | ||
</MemoryRouter>, | ||
); | ||
expect(screen.queryByText("Cancel session")).not.toBeNull(); | ||
}); | ||
|
||
it("shows the cancel buttons when asked", () => { | ||
render( | ||
<MemoryRouter> | ||
<SessionDetails | ||
{...irrelevantProps} | ||
uiConfig={{ showTerminateActions: true, ...irrelevantUIConfig }} | ||
/> | ||
, | ||
</MemoryRouter>, | ||
); | ||
expect(screen.queryByText("Cancel session")).not.toBeNull(); | ||
}); | ||
|
||
it("hides the cancel buttons when asked", () => { | ||
render( | ||
<MemoryRouter> | ||
<SessionDetails | ||
{...irrelevantProps} | ||
uiConfig={{ showTerminateActions: false, ...irrelevantUIConfig }} | ||
/> | ||
, | ||
</MemoryRouter>, | ||
); | ||
expect(screen.queryByText("Cancel session")).toBeNull(); | ||
}); | ||
}); |
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
75 changes: 75 additions & 0 deletions
75
pkg/ui/workspaces/cluster-ui/src/sessions/sessionsPage.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,75 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
import React from "react"; | ||
import { createMemoryHistory } from "history"; | ||
import { MemoryRouter } from "react-router-dom"; | ||
import { render, screen } from "@testing-library/react"; | ||
|
||
import SessionsPage, { SessionsPageProps } from "./sessionsPage"; | ||
|
||
describe("SessionsPage", () => { | ||
const irrelevantProps: SessionsPageProps = { | ||
history: createMemoryHistory({ initialEntries: ["/sessions"] }), | ||
location: { pathname: "/sessions", search: "", hash: "", state: null }, | ||
match: { path: "/sessions", url: "/sessions", isExact: true, params: {} }, | ||
sessions: [], | ||
sessionsError: null, | ||
sortSetting: { ascending: false, columnTitle: "statementAge" }, | ||
refreshSessions: () => {}, | ||
cancelSession: _ => {}, // eslint-disable-line @typescript-eslint/no-unused-vars | ||
cancelQuery: _ => {}, // eslint-disable-line @typescript-eslint/no-unused-vars | ||
onSortingChange: () => {}, | ||
}; | ||
|
||
const baseColumnCount = 5; | ||
|
||
it("shows the extra actions column by default", () => { | ||
render( | ||
<MemoryRouter> | ||
<SessionsPage {...irrelevantProps} /> | ||
</MemoryRouter>, | ||
); | ||
|
||
expect(screen.getAllByRole("columnheader")).toHaveLength( | ||
baseColumnCount + 1, | ||
); | ||
}); | ||
|
||
it("shows the extra actions column when asked", () => { | ||
render( | ||
<MemoryRouter> | ||
<SessionsPage | ||
uiConfig={{ showTerminateActions: true }} | ||
{...irrelevantProps} | ||
/> | ||
, | ||
</MemoryRouter>, | ||
); | ||
|
||
expect(screen.getAllByRole("columnheader")).toHaveLength( | ||
baseColumnCount + 1, | ||
); | ||
}); | ||
|
||
it("hides the extra actions column when asked", () => { | ||
render( | ||
<MemoryRouter> | ||
<SessionsPage | ||
uiConfig={{ showTerminateActions: false }} | ||
{...irrelevantProps} | ||
/> | ||
, | ||
</MemoryRouter>, | ||
); | ||
|
||
expect(screen.getAllByRole("columnheader")).toHaveLength(baseColumnCount); | ||
}); | ||
}); |
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
69 changes: 69 additions & 0 deletions
69
pkg/ui/workspaces/cluster-ui/src/sessions/sessionsPageConnected.spec.ts
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,69 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
import assert from "assert"; | ||
import fetchMock from "jest-fetch-mock"; | ||
import { applyMiddleware, createStore, Store } from "redux"; | ||
import createSagaMiddleware from "redux-saga"; | ||
|
||
import { rootReducer, sagas } from "src/store"; | ||
import { | ||
actions, | ||
ICancelQueryRequest, | ||
ICancelSessionRequest, | ||
} from "src/store/terminateQuery"; | ||
|
||
class TestDriver { | ||
private readonly store: Store; | ||
|
||
constructor() { | ||
const sagaMiddleware = createSagaMiddleware(); | ||
this.store = createStore(rootReducer, {}, applyMiddleware(sagaMiddleware)); | ||
sagaMiddleware.run(sagas); | ||
} | ||
|
||
async cancelQuery(req: ICancelQueryRequest) { | ||
return this.store.dispatch(actions.terminateQuery(req)); | ||
} | ||
|
||
async cancelSession(req: ICancelSessionRequest) { | ||
return this.store.dispatch(actions.terminateSession(req)); | ||
} | ||
} | ||
|
||
describe("SessionsPage Connections", () => { | ||
beforeAll(fetchMock.enableMocks); | ||
afterEach(fetchMock.resetMocks); | ||
afterAll(fetchMock.disableMocks); | ||
|
||
describe("cancelQuery", () => { | ||
it("fires off an HTTP request", async () => { | ||
const driver = new TestDriver(); | ||
assert.deepStrictEqual(fetchMock.mock.calls.length, 0); | ||
await driver.cancelQuery({ node_id: "1" }); | ||
assert.deepStrictEqual( | ||
fetchMock.mock.calls[0][0], | ||
"/_status/cancel_query/1", | ||
); | ||
}); | ||
}); | ||
|
||
describe("cancelSession", () => { | ||
it("fires off an HTTP request", async () => { | ||
const driver = new TestDriver(); | ||
assert.deepStrictEqual(fetchMock.mock.calls.length, 0); | ||
await driver.cancelSession({ node_id: "1" }); | ||
assert.deepStrictEqual( | ||
fetchMock.mock.calls[0][0], | ||
"/_status/cancel_session/1", | ||
); | ||
}); | ||
}); | ||
}); |
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.