Files
redash/client/cypress/integration/alert/view_alert_spec.js
Omer Lachish de052ff02b Cypress touch-ups (#5109)
* allow non-sequential IDs for DataSources in Cypress tests

* refactor redash-api to a set of Cypress commands

* support mounting Redash endpoints in Cypress routes

* fix some parameter specs by waiting for schema to load

* extract baseUrl from cypress.json

* Restyled by prettier (#5110)

Co-authored-by: Restyled.io <commits@restyled.io>

Co-authored-by: restyled-io[bot] <32688539+restyled-io[bot]@users.noreply.github.com>
Co-authored-by: Restyled.io <commits@restyled.io>
2020-08-19 21:00:06 +03:00

116 lines
3.5 KiB
JavaScript

describe("View Alert", () => {
beforeEach(function() {
cy.login().then(() => {
cy.createQuery({ query: "select 1 as col_name" })
.then(({ id: queryId }) => cy.createAlert(queryId, { column: "col_name" }))
.then(({ id: alertId }) => {
this.alertId = alertId;
this.alertUrl = `/alerts/${alertId}`;
});
});
});
it("renders the page and takes a screenshot", function() {
cy.visit(this.alertUrl);
cy.getByTestId("Criteria").should("exist");
cy.percySnapshot("View Alert screen");
});
it("allows adding new destinations", function() {
cy.visit(this.alertUrl);
cy.getByTestId("AlertDestinations")
.contains("Test Email Destination")
.should("not.exist");
cy.server();
cy.route("GET", "**/api/destinations").as("Destinations");
cy.route("GET", "**/api/alerts/*/subscriptions").as("Subscriptions");
cy.visit(this.alertUrl);
cy.wait(["@Destinations", "@Subscriptions"]);
cy.getByTestId("ShowAddAlertSubDialog").click();
cy.contains("Test Email Destination").click();
cy.contains("Save").click();
cy.getByTestId("AlertDestinations")
.contains("Test Email Destination")
.should("exist");
});
describe("Alert Destination permissions", () => {
before(() => {
cy.login();
cy.createUser({
name: "Example User",
email: "user@redash.io",
password: "password",
});
});
it("hides remove button from non-author", function() {
cy.server();
cy.route("GET", "**/api/alerts/*/subscriptions").as("Subscriptions");
cy.logout()
.then(() => cy.login()) // as admin
.then(() => cy.addDestinationSubscription(this.alertId, "Test Email Destination"))
.then(() => {
cy.visit(this.alertUrl);
// verify remove button appears for author
cy.wait(["@Subscriptions"]);
cy.getByTestId("AlertDestinations")
.contains("Test Email Destination")
.parent()
.within(() => {
cy.get(".remove-button")
.as("RemoveButton")
.should("exist");
});
return cy.logout().then(() => cy.login("user@redash.io", "password"));
})
.then(() => {
cy.visit(this.alertUrl);
// verify remove button not shown for non-author
cy.wait(["@Subscriptions"]);
cy.get("@RemoveButton").should("not.exist");
});
});
it("shows remove button for non-author admin", function() {
cy.server();
cy.route("GET", "**/api/alerts/*/subscriptions").as("Subscriptions");
cy.logout()
.then(() => cy.login("user@redash.io", "password"))
.then(() => cy.addDestinationSubscription(this.alertId, "Test Email Destination"))
.then(() => {
cy.visit(this.alertUrl);
// verify remove button appears for author
cy.wait(["@Subscriptions"]);
cy.getByTestId("AlertDestinations")
.contains("Test Email Destination")
.parent()
.within(() => {
cy.get(".remove-button")
.as("RemoveButton")
.should("exist");
});
return cy.logout().then(() => cy.login()); // as admin
})
.then(() => {
cy.visit(this.alertUrl);
// verify remove button also appears for admin
cy.wait(["@Subscriptions"]);
cy.get("@RemoveButton").should("exist");
});
});
});
});