From ff3036b8af2e4a225e35f219f5698f297b62eacd Mon Sep 17 00:00:00 2001 From: Nemanja Glumac <31325167+nemanjaglumac@users.noreply.github.com> Date: Tue, 21 Jun 2022 18:49:40 +0200 Subject: [PATCH] [E2E] Remove `admin_setup` spec from smoke tests (#23458) * Remove redundant check * Delete data model tests from the admin setup spec * Refactor hide tables spec * Remove admin_setup spec * Add a dummy test so that CircleCI job doesn't fail --- .../admin/datamodel/hide_tables.cy.spec.js | 46 +- .../smoketest/admin_setup.cy.spec.js | 743 ------------------ .../scenarios/smoketest/hello.cy.spec.js | 5 + 3 files changed, 27 insertions(+), 767 deletions(-) delete mode 100644 frontend/test/metabase/scenarios/smoketest/admin_setup.cy.spec.js create mode 100644 frontend/test/metabase/scenarios/smoketest/hello.cy.spec.js diff --git a/frontend/test/metabase/scenarios/admin/datamodel/hide_tables.cy.spec.js b/frontend/test/metabase/scenarios/admin/datamodel/hide_tables.cy.spec.js index a419396decc..6ee3d0f6d82 100644 --- a/frontend/test/metabase/scenarios/admin/datamodel/hide_tables.cy.spec.js +++ b/frontend/test/metabase/scenarios/admin/datamodel/hide_tables.cy.spec.js @@ -1,47 +1,45 @@ import { restore, startNewQuestion } from "__support__/e2e/cypress"; -const ORDERS_URL = "/admin/datamodel/database/1/table/2"; +import { SAMPLE_DB_ID } from "__support__/e2e/cypress_data"; +import { SAMPLE_DATABASE } from "__support__/e2e/cypress_sample_database"; -describe("scenarios > admin > datamodel > hidden tables (metabase#9759)", () => { - beforeEach(restore); +const { ORDERS_ID } = SAMPLE_DATABASE; - it("can hide a table and not show up in 'Our Data'", () => { - cy.server(); - cy.route("PUT", "/api/table/*").as("tableUpdate"); +describe("scenarios > admin > datamodel > hidden tables (metabase#9759)", () => { + beforeEach(() => { + restore(); + cy.signInAsAdmin(); // Toggle the table to be hidden as admin user - cy.signInAsAdmin(); - cy.visit(ORDERS_URL); - cy.contains(/^Hidden$/).click(); - cy.wait("@tableUpdate"); + hideTable(ORDERS_ID); + }); + it("hidden table should not show up in various places in UI", () => { // Visit the main page, we shouldn't be able to see the table cy.visit("/browse/1"); cy.contains("Products"); cy.contains("Orders").should("not.exist"); - // It shouldn't show up as a normal user either + // It shouldn't show up for a normal user either cy.signInAsNormalUser(); cy.visit("/browse/1"); cy.contains("Products"); cy.contains("Orders").should("not.exist"); - }); - - it("can hide a table and not show up in 'New Question' for a user", () => { - cy.server(); - cy.route("PUT", "/api/table/*").as("tableUpdate"); - // Toggle the table to be hidden as admin user - cy.signInAsAdmin(); - cy.visit(ORDERS_URL); - cy.contains(/^Hidden$/).click(); - cy.wait("@tableUpdate"); - - // It shouldn't show up as a normal user either - cy.signInAsNormalUser(); + // It shouldn't show in a new question data picker startNewQuestion(); cy.contains("Sample Database").click(); cy.contains("Products"); cy.contains("Orders").should("not.exist"); }); }); + +function hideTable(table) { + const TABLE_URL = `/admin/datamodel/database/${SAMPLE_DB_ID}/table/${table}`; + + cy.intercept("PUT", `/api/table/${table}`).as("tableUpdate"); + + cy.visit(TABLE_URL); + cy.contains(/^Hidden$/).click(); + cy.wait("@tableUpdate"); +} diff --git a/frontend/test/metabase/scenarios/smoketest/admin_setup.cy.spec.js b/frontend/test/metabase/scenarios/smoketest/admin_setup.cy.spec.js deleted file mode 100644 index 772e79101b2..00000000000 --- a/frontend/test/metabase/scenarios/smoketest/admin_setup.cy.spec.js +++ /dev/null @@ -1,743 +0,0 @@ -import { - browse, - popover, - restore, - openPeopleTable, - visualize, - navigationSidebar, - startNewQuestion, - visitQuestion, -} from "__support__/e2e/cypress"; -import { USERS } from "__support__/e2e/cypress_data"; -import { questionInfoButton } from "../../../__support__/e2e/helpers/e2e-ui-elements-helpers"; - -const { admin, normal } = USERS; - -describe("smoketest > admin_setup", () => { - before(restore); - - describe("data model changes by admin reflected with user", () => { - beforeEach(() => { - cy.signOut(); - cy.signInAsAdmin(); - }); - - it("should check table and question names as user", () => { - // Log out as admin and sign in as user - cy.signOut(); - cy.signInAsNormalUser(); - cy.visit("/"); - - // Check names - cy.wait(3000).contains("People"); - cy.contains("Orders"); - cy.contains("Test Table").should("not.exist"); - - cy.findByText("Our analytics").click(); - - cy.get("h1").contains("Our analytics"); - cy.findByText("A look at your").should("not.exist"); - - cy.findByText("Orders, Count"); - cy.findByText("Orders, Count, Grouped by Created At (year)"); - cy.findByText("Test Q Name Change").should("not.exist"); - }); - - it("should rename a question and description as admin", () => { - cy.intercept("PUT", "/api/card/3").as("updateCard"); - cy.visit("/"); - - cy.findByText("Our analytics").click(); - - navigationSidebar().within(() => { - cy.icon("ellipsis").click(); - }); - cy.findByText("Other users' personal collections"); - - cy.findByText("Orders, Count, Grouped by Created At (year)").click(); - - cy.findByText("Settings"); - - cy.findByTestId("saved-question-header-title") - .clear() - .type("Test Question") - .blur(); - cy.wait("@updateCard"); - - questionInfoButton().click(); - cy.findByPlaceholderText("Description") - .clear() - .type("Testing question description") - .blur(); - cy.wait("@updateCard"); - }); - - it("should rename a table and add a description as admin", () => { - cy.visit("/"); - cy.icon("gear") - .first() - .click(); - cy.findByText("Admin settings").click(); - - cy.findByText("Getting set up"); - cy.findByText(admin.first_name).should("not.exist"); - - cy.findByText("Data Model").click(); - cy.findByText("Orders").click(); - cy.findByTestId("table-name") - .click() - .type("abc", { delay: 100 }) - .clear() - .type("Test Table"); - - cy.get( - "[value='Confirmed Sample Company orders for a product, from a user.']", - ) - .clear() - .type("Testing table description"); - }); - - it("should change a column name, visibility, and formatting as admin", () => { - cy.visit("/admin/datamodel/database/1/table/2"); - - // Changing column name from Discount to Sale - - cy.wait(1000) - .get("[value='Discount amount.'") - .parent() - .parent() - .within(() => { - cy.get("input") - .first() - .wait(1) - .clear() - .wait(1) - .type("Sale"); - }); - - // Changing visibility of Created At column - - cy.wait(2000) - .get("[value='The date and time an order was submitted.']") - .parent() - .parent() - .within(() => { - cy.findByText("Everywhere").click(); - }); - cy.get(".ReactVirtualized__Grid__innerScrollContainer") - .findAllByText("Do not include") - .click(); // ({ force: true }); - - // Changing column formatting to display USD instead of $ - - cy.get("[value='The total billed amount.']") - .parent() - .parent() - .within(() => { - cy.icon("gear").click(); - }); - - cy.findByText("Total – Field Settings"); - cy.findByText("Columns").should("not.exist"); - - cy.findByText("Formatting").click(); - - cy.findByText("Show a mini bar chart"); - cy.findByText("Everywhere").should("not.exist"); - - cy.findByText("Normal").click(); - cy.findByText("Currency").click({ force: true }); - cy.findByText("Code (USD)") - .parent() - .click(); - cy.findByText("In every table cell").click(); - - cy.findByText("Saved"); - }); - - it("should reflect changes to column name, visibility, and formatting in the notebook editor for admin", () => { - // Navigate - cy.findByText("Exit admin").click({ force: true }); - - // Checking table name - - cy.contains("Test Table"); - - // Navigating to Test Table table - - browse().click(); - cy.findByTextEnsureVisible("Sample Database").click(); - - cy.get("main").within(() => { - cy.icon("database").should("not.exist"); - }); - - cy.findByText("Test Table").click(); - - // Checking three things in table display - - cy.wait(1) - .findByText("Discount") - .should("not.exist"); - cy.findByTextEnsureVisible("Sale ($)"); - - cy.findByText("Created At").should("not.exist"); - - cy.findByText("Total ($)").should("not.exist"); - cy.contains("USD"); - - // Check column name and visibility in notebook editor - - cy.icon("notebook").click({ force: true }); - - cy.wait(1000) - .findByText("Orders") - .should("not.exist"); - cy.findByText("Custom column"); - - cy.findByText("Filter").click(); - cy.findByTextEnsureVisible("Sale ($)"); - cy.findByText("Discount").should("not.exist"); - - cy.findByText("Created At").should("not.exist"); - }); - - it("should configure a foreign key to show the name as admin", () => { - cy.visit("/admin/datamodel/database/1/table/2"); - - // Configure Key - - cy.findByText("Metrics"); - cy.get("[value='Product ID'") - .parent() - .parent() - .within(() => { - cy.icon("gear").click(); - }); - cy.findByText("Plain input box").click(); - cy.findByText("Search box").click(); - cy.findByText("Use original value").click(); - cy.findByText("Use foreign key").click(); - cy.findByText("Title").click(); - - cy.findByText( - "You might want to update the field name to make sure it still makes sense based on your remapping choices.", - ); - - // Check key config in table display - - cy.visit("/browse/1"); - cy.findByText("Test Table").click(); - - cy.findByTextEnsureVisible("Product ID"); - cy.findAllByText("Awesome Concrete Shoes"); - cy.findAllByText("Mediocre Wooden Bench"); - cy.get(".Table-ID") - .eq("1") - .contains("14") - .should("not.exist"); - - // Check key config in notebook editor (pulls up title with ID #, not from actual title) - - cy.icon("notebook").click({ force: true }); - cy.wait(3000) - .findByText("Filter") - .click(); - cy.findAllByText("Product ID") - .last() - .click({ force: true }); - cy.get("input") - .last() - .type("Awesome Concrete"); - cy.wait(1000) - .findAllByText("Awesome Concrete Shoes") - .last() - .click(); - cy.findByText("Add filter").click(); - - visualize(); - - cy.findAllByText("Awesome Concrete Shoes"); - cy.findByText("Mediocre Wooden Bench").should("not.exist"); - }); - - it("should hide a table as admin", () => { - cy.visit("/admin/datamodel/database/1/"); - - // Hide table - cy.findByText("Reviews") - .find(".Icon-eye_crossed_out") - .click({ force: true }); - - cy.findByTextEnsureVisible("1 Hidden Table"); - - // Check table hidden while browsing data - - cy.visit("/browse/1"); - - cy.findByTextEnsureVisible("Learn about our data"); - cy.findByTextEnsureVisible("People"); - cy.findByText("Reviews").should("not.exist"); - - // Check table hidden in notebook editor - - openPeopleTable({ mode: "notebook" }); - - cy.findByText("Join data").click(); - - popover() - .should("contain", "People") - .and("not.contain", "Reviews"); - }); - - it("should see changes to visibility, formatting, and foreign key mapping as user", () => { - cy.signOut(); - cy.signInAsNormalUser(); - cy.visit("/"); - - // Check table names and visibility - - cy.findByText("Here are some popular items"); - cy.findByText("Test Table"); - cy.findByText("Reviews").should("not.exist"); - - // Check question names and descriptions - - cy.findByText("Our analytics").click(); - - cy.findByTextEnsureVisible("Orders, Count"); - cy.findByText("Orders, Count, Grouped by Created At (year)").should( - "not.exist", - ); - - cy.findByText("Test Question").click(); - - questionInfoButton().click(); - cy.findByDisplayValue("Test Question"); - cy.findByDisplayValue("Testing question description"); - questionInfoButton().click(); - - // Check column names and visiblity - - browse().click(); - cy.findByTextEnsureVisible("Sample Database").click(); - cy.findByTextEnsureVisible("Test Table").click(); - - cy.findByTextEnsureVisible("Visualization"); - cy.findByText("Discount").should("not.exist"); - cy.findByTextEnsureVisible("Sale ($)"); - cy.findByText("Created At").should("not.exist"); - - // Check column formatting - - cy.contains("USD"); - - // Check column foreign key mapping - - cy.findAllByText("Awesome Concrete Shoes"); - cy.findByText("Mediocre Wooden Bench"); - cy.get(".Table-ID") - .eq("1") - .contains("14") - .should("not.exist"); - }); - }); - - describe("permission changes reflected", () => { - beforeEach(cy.signInAsNormalUser); - - it("should check current permissions as users", () => { - // Access to all tables as user - cy.visit("/"); - - cy.contains("Test Table"); - cy.findByText("Reviews").should("not.exist"); - - // Access to SQl queries as user - - cy.findByText("New").click(); - cy.findByText("SQL query"); - - // Cannot see Review table as no collection user - cy.signOut(); - cy.signIn("nocollection"); - cy.visit("/"); - - cy.wait(2000).findByText("Here are some popular tables"); - cy.contains("Test Table"); - cy.contains("Reviews").should("not.exist"); - - // Cannot view our analytics as no collection user - - cy.findByText("Our analytics").click(); - cy.findByText("Orders").should("not.exist"); - }); - - it("should modify user permissions for data access and SQL queries, both on a database/schema level as well as at a table level as admin", () => { - cy.signOut(); - cy.signInAsAdmin(); - - cy.request("POST", "/api/permissions/group", { - name: "Marketing", - }); - - cy.visit("/"); - - cy.icon("gear").click(); - cy.findByText("Admin settings").click(); - cy.findByText("Permissions").click(); - - // Data access permissions (database/schema) - - // SQL queries permissions (database/schema) - - // Data access permissions (table) - - cy.findByText("All Users").click(); - - cy.findByTextEnsureVisible("Sample Database").click(); - - cy.findByText("Products"); - - // Turn on data access for all users to Test Table - cy.icon("eye") - .eq(2) - .click(); - - cy.findAllByRole("option") - .contains("Unrestricted") - .click(); - - cy.findByText("Change access to this database to limited?"); - - cy.findByText("Change").click(); - - cy.findByText("Marketing").click(); - - cy.findByTextEnsureVisible("Sample Database").click(); - - // Turn on data access for Marketing users to Products - cy.icon("eye") - .eq(1) - .click(); - cy.findAllByRole("option") - .contains("Unrestricted") - .click(); - - cy.findByText("Are you sure you want to do this?"); - - cy.findByText("Change").click(); - - cy.icon("warning"); - - cy.findByText("Save changes").click(); - - cy.contains( - "All Users will be given access to 1 table in Sample Database.", - ); - cy.findByText("Are you sure you want to do this?"); - - cy.findByText("Yes").click(); - - // SQL queries permissions (table) - - cy.findByText("Data").click(); - - cy.findByText("data").click(); - cy.icon("check") - .eq(1) - .click(); - - popover().within(() => { - cy.findByText("No").click(); - }); - - cy.findByText("Save changes").click(); - - cy.contains( - "data will no longer be able to read or write native queries for Sample Database.", - ); - cy.findByText("Yes").click(); - }); - - it.skip("should add sub-collection and change its permissions as admin", () => { - const subCollectionName = "test sub-collection"; - - cy.signOut(); - cy.signInAsAdmin(); - - cy.visit("/collection/root"); - - cy.findByText("Our analytics"); - - cy.findByText("New collection").click(); - - cy.get(".Modal").within(() => { - cy.findByLabelText("Name").type(subCollectionName); - cy.findByLabelText("Description") - .wait(1) - .type(`Very nice description for ${subCollectionName}`); - - cy.icon("chevrondown").click(); - }); - - popover().within(() => { - cy.findAllByText("Our analytics") - .last() - .click(); - }); - cy.findByText("Create").click(); - - // Changes permissions of sub-collection - cy.findByText(subCollectionName).click(); - - cy.findByText("This collection is empty, like a blank canvas"); - - cy.icon("lock").click(); - - cy.findByText(`Permissions for ${subCollectionName}`); - - // Collection can no longer access sub-collection - cy.wait(1) - .get(".Icon-check") - .last() - .click(); - cy.findByText("Revoke access").click(); - - // Marketing now has access to sub-collection - cy.icon("close") - .last() - .click(); - cy.findByText("Curate collection").click(); - - cy.findByText("Save").click(); - - cy.findByText("This collection is empty, like a blank canvas"); - }); - - it.skip("should modify Collection permissions for top-level collections and sub-collections as admin", () => { - cy.signOut(); - cy.signInAsAdmin(); - cy.visit("/admin/permissions/databases"); - - // Modify permissions for top-level collection - - cy.findByText("Collection").click(); - cy.icon("close") - .eq(1) - .click(); - cy.findByText("View collection").click(); - cy.findByText("Save changes").click(); - - cy.findByText("Save permissions?"); - - cy.findByText("Yes").click(); - - cy.findByText("View sub-collections").click(); - - // Give collection full access to sub-collection - cy.icon("close") - .last() - .click(); - cy.findByText("Curate collection").click(); - // Revoke Marketing access to sub-collection - cy.icon("check") - .last() - .click(); - cy.findByText("Revoke access").click(); - // Revoke data access to sub-collection - cy.icon("eye").click(); - cy.findByText("Revoke access").click(); - cy.findByText("Save changes").click(); - - cy.findByText("Save permissions?"); - - cy.findByText("Yes").click(); - cy.findByText("Collection").click(); - - cy.icon("eye"); - }); - - it("should be unable to access tables or questions that have been restricted as user", () => { - cy.visit("/"); - - // Normal user can still see everything - - cy.wait(2000).contains("Test Table"); - - // Normal user cannot make an SQL query - - startNewQuestion(); - - cy.signOut(); - cy.signIn("nocollection"); - cy.visit("/"); - - // No collection user sees Test Table and People table - - cy.contains("Test Table"); - cy.contains("Reviews").should("not.exist"); - }); - - it.skip("should be unable to change questions in Our analytics as no collection user", () => { - cy.findByText("Our analytics").click(); - - cy.findByText("Everything"); - cy.findByText("Orders, Count"); - cy.findByText( - 'Access dashboards, questions, and collections in "Our analytics"', - ).should("not.exist"); - - cy.findByText("Orders").click(); - cy.findByText("Summarize").click(); - cy.wait(1000) - .findAllByText("Quantity") - .eq(1) - .click(); - cy.findAllByText("Done").click(); - - cy.findByText("Product ID").should("not.exist"); - cy.wait(1000).findByText("Quantity"); - - cy.findAllByText("Save") - .last() - .click(); - cy.findByText('Replace original question, "Orders"').click(); - cy.findAllByText("Save") - .last() - .click(); - // *** There should be an error message here saying I'm not allowed to make any changes - - // Normal user should not see changes that no collection user made - // *** Problem: Normal user still sees these changes - - cy.signOut(); - cy.signInAsNormalUser(); - visitQuestion(1); - - // cy.findByText("Product ID"); - // cy.findByText("Quantity").should("not.exist"); - }); - - it.skip("should add a sub collection as a user", () => { - cy.visit("/collection/root"); - - cy.wait(3000) - .findByText("New collection") - .click(); - - cy.findByLabelText("Name").type("test user added sub-collection"); - cy.findByLabelText("Description").type( - "very descriptive of test user added sub-collection", - ); - cy.icon("chevrondown").click(); - cy.findAllByText("Our analytics") - .last() - .click(); - - cy.findByText("Create").click(); - - cy.icon("all"); - }); - - it.skip("should view collections I have access to, but not ones that I don't (even with URL) as user", () => { - // Check access as normal user - - cy.visit("/collection/root"); - - cy.findByText("My personal collection"); - cy.findByText("test sub-collection").click(); - - cy.wait(3000).findByText("This collection is empty, like a blank canvas"); - cy.findByText("Sorry, you don’t have permission to see that.").should( - "not.exist", - ); - - // Check editing abiltiy as no collection user (resetting to what we made it before) - - cy.icon("pencil"); - - startNewQuestion(); - cy.findByTextEnsureVisible("Sample Database").click(); - cy.findByTextEnsureVisible("People").click(); - cy.findByText("Save").click(); - cy.findByLabelText("Name") - .clear() - .wait(1) - .type(" sub-collection question "); - cy.findByText("Robert Tableton's Personal Collection").click(); - - cy.findByText("My personal collection"); - - cy.findByText("test sub-collection").click(); - cy.findAllByText("Save") - .last() - .click(); - cy.findByText("Not now").click(); - - cy.contains("test sub-collection").click(); - - cy.findByText("Sorry, you don’t have permission to see that.").should( - "not.exist", - ); - cy.contains("sub-collection question"); - - // Check access as no collection user - - cy.signIn("nocollection"); - cy.visit("/"); - - cy.findByText("test sub-collection").should("not.exist"); - - cy.visit("/collection/6"); - - cy.findByText("Sorry, you don’t have permission to see that."); - cy.findByText("This collection is empty, like a blank canvas").should( - "not.exist", - ); - }); - - it.skip("should be unable to access question with URL (if access not permitted)", () => { - // This test will fail whenever the previous test fails - cy.signIn("nocollection"); - - visitQuestion(4); - cy.contains("sub-collection question").should("not.exist"); - cy.findByText("Sorry, you don’t have permission to see that."); - }); - - it("user should not be able to login after admin deactivated them", () => { - const FULL_NAME = normal.first_name + " " + normal.last_name; - - cy.signOut(); - cy.signInAsAdmin(); - - cy.visit("/admin/settings/setup"); - cy.findByText("People").click(); - - openEllipsisMenuForUser(FULL_NAME); - cy.findByText("Deactivate user").click(); - - cy.findByText(`${FULL_NAME} won't be able to log in anymore.`); - cy.button("Deactivate").click(); - cy.findByText(FULL_NAME).should("not.exist"); - - // User tries to log in - cy.signOut(); - cy.visit("/"); - cy.findByLabelText("Email address").type(normal.email); - cy.findByLabelText("Password").type(normal.password); - cy.button("Sign in").click(); - - cy.findByText("Failed"); - cy.contains("Your account is disabled."); - }); - }); -}); - -function openEllipsisMenuForUser(user) { - cy.findByText(user) - .closest("tr") - .find(".Icon-ellipsis") - .click(); -} diff --git a/frontend/test/metabase/scenarios/smoketest/hello.cy.spec.js b/frontend/test/metabase/scenarios/smoketest/hello.cy.spec.js new file mode 100644 index 00000000000..198966832be --- /dev/null +++ b/frontend/test/metabase/scenarios/smoketest/hello.cy.spec.js @@ -0,0 +1,5 @@ +describe("hello", () => { + it("says hi", () => { + cy.log("hi"); + }); +}); -- GitLab