forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ui/e2e: add e2e testing for statement bundles
This commit adds some e2e cypress tests for statement bundle features in DB Console: * add tests for requesting, cancelling and viewing bundles for privileged (VIEWACTIVITY, ADMIN) and non-privileged users * reformat cypress login command to use a new `users` fixture that defines users by sql privilege * add cypress command getUserWithExactPrivileges which retrieves users from the fixture with the provided privileges Release note: None Part of: cockroachdb#121301
- Loading branch information
Showing
6 changed files
with
166 additions
and
6 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
91 changes: 91 additions & 0 deletions
91
pkg/ui/workspaces/e2e-tests/cypress/e2e/statementBundles/statementBundles.cy.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,91 @@ | ||
// Copyright 2024 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 { SQLPrivilege } from "../../support/types"; | ||
|
||
// TODO (xinhaoz): This test currently only works when running pnpm run cy:run | ||
// directly against a local cluster set up with sql activity in the last hour | ||
// and the expected cypress users in fixtures. We need to automate this server | ||
// setup for e2e testing. | ||
describe("statement bundles", () => { | ||
const runTestsForPrivilegedUser = (privilege: SQLPrivilege) => { | ||
describe(`${privilege} user`, () => { | ||
beforeEach(() => { | ||
cy.getUserWithExactPrivileges([privilege]).then((user) => { | ||
cy.login(user.username, user.password); | ||
}); | ||
}); | ||
|
||
it("can request statement bundles", () => { | ||
cy.visit("#/sql-activity"); | ||
cy.contains("button", "Apply").click(); | ||
// Open modal. | ||
cy.contains("button", "Activate").click(); | ||
// Wait for modal. | ||
cy.findByText(/activate statement diagnostics/i).should("be.visible"); | ||
// Click the Activate button within the modal | ||
cy.get(`[role="dialog"]`) // Adjust this selector to match your modal's structure | ||
.contains("button", "Activate") | ||
.click(); | ||
cy.findByText(/statement diagnostics were successfully activated/i); | ||
}); | ||
|
||
it("can view statement bundles", () => { | ||
cy.visit("#/reports/statements/diagnosticshistory"); | ||
cy.get("table tbody tr").should("have.length.at.least", 1); | ||
}); | ||
|
||
it("can cancel statement bundles", () => { | ||
cy.visit("#/reports/statements/diagnosticshistory"); | ||
cy.get("table tbody tr").should("have.length.at.least", 1); | ||
cy.contains("button", "Cancel").click(); | ||
cy.findByText(/statement diagnostics were successfully cancelled/i); | ||
}); | ||
}); | ||
}; | ||
|
||
const runTestsForNonPrivilegedUser = (privilege?: SQLPrivilege) => { | ||
beforeEach(() => { | ||
cy.getUserWithExactPrivileges(privilege ? [privilege] : []).then( | ||
(user) => { | ||
cy.login(user.username, user.password); | ||
}, | ||
); | ||
}); | ||
|
||
it("cannot request statement bundles", () => { | ||
cy.visit("#/sql-activity"); | ||
cy.contains("button", "Apply").click(); | ||
// Should not see an Activate button. | ||
cy.contains("button", "Activate").should("not.exist"); | ||
}); | ||
|
||
it("cannot view statement bundles", () => { | ||
cy.visit("#/reports/statements/diagnosticshistory"); | ||
cy.findByText(/no statement diagnostics to show/i); | ||
}); | ||
}; | ||
|
||
describe("view activity user", () => { | ||
runTestsForPrivilegedUser(SQLPrivilege.VIEWACTIVITY); | ||
}); | ||
|
||
describe("admin user", () => { | ||
runTestsForPrivilegedUser(SQLPrivilege.ADMIN); | ||
}); | ||
|
||
describe("non-privileged VIEWACTIVITYREDACTED user", () => { | ||
runTestsForNonPrivilegedUser(SQLPrivilege.VIEWACTIVITYREDACTED); | ||
}); | ||
|
||
describe("non-privileged user", () => { | ||
runTestsForNonPrivilegedUser(); | ||
}); | ||
}); |
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,28 @@ | ||
[ | ||
{ | ||
"username": "cypress", | ||
"password": "tests", | ||
"sqlPrivileges": [ | ||
"ADMIN" | ||
] | ||
}, | ||
{ | ||
"username": "va_user", | ||
"password": "cypress", | ||
"sqlPrivileges": [ | ||
"VIEWACTIVITY" | ||
] | ||
}, | ||
{ | ||
"username": "va_redacted_user", | ||
"password": "cypress", | ||
"sqlPrivileges": [ | ||
"VIEWACTIVITYREDACTED" | ||
] | ||
}, | ||
{ | ||
"username": "no_privs_user", | ||
"password": "cypress", | ||
"sqlPrivileges": [] | ||
} | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2024 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. | ||
|
||
export enum SQLPrivilege { | ||
ADMIN = "ADMIN", | ||
VIEWACTIVITY = "VIEWACTIVITY", | ||
VIEWACTIVITYREDACTED = "VIEWACTIVITYREDACTED", | ||
NONE = "NONE", | ||
} | ||
|
||
export type User = { | ||
username: string; | ||
password: string; | ||
sqlPrivileges: SQLPrivilege[]; | ||
}; |