Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Consolidate collections e2e tests (#83325)

Nemanja Glumace40d36c2b50a
diff --git a/e2e/support/helpers/e2e-collection-helpers.ts b/e2e/support/helpers/e2e-collection-helpers.ts
index 91054212285..bc8a1f2ebb7 100644
--- a/e2e/support/helpers/e2e-collection-helpers.ts
+++ b/e2e/support/helpers/e2e-collection-helpers.ts
@@ -22,6 +22,15 @@ export function openCollectionMenu() {
getCollectionActions().icon("ellipsis").click();
}
+export function displaySidebarChildOf(collectionName: string) {
+ navigationSidebar()
+ .findByText(collectionName)
+ .parentsUntil("[data-testid=sidebar-collection-link-root]")
+ .find(".Icon-chevronright")
+ .eq(0) // there may be more nested icons, but we need the top level one
+ .click();
+}
+
export function getSidebarSectionTitle(name: string | RegExp) {
return cy.findAllByRole("heading", { name });
}
diff --git a/e2e/support/helpers/e2e-upload-helpers.js b/e2e/support/helpers/e2e-upload-helpers.js
index 31172005245..98188736ddc 100644
--- a/e2e/support/helpers/e2e-upload-helpers.js
+++ b/e2e/support/helpers/e2e-upload-helpers.js
@@ -32,6 +32,7 @@ export const INVALID_CSV_FILES = [
{
valid: false,
fileName: "invalid.csv",
+ tableName: "invalid",
},
];
diff --git a/e2e/test/scenarios/collections/cleanup.cy.spec.js b/e2e/test/scenarios/collections/cleanup.cy.spec.js
index 1a334f82027..0232ef980ae 100644
--- a/e2e/test/scenarios/collections/cleanup.cy.spec.js
+++ b/e2e/test/scenarios/collections/cleanup.cy.spec.js
@@ -41,8 +41,21 @@ describe("scenarios > collections > clean up", () => {
cy.findByText("Usage analytics").click();
cy.findByText("Custom reports").click();
});
+ cy.location("pathname")
+ .should("match", /^\/collection\/\d+-custom-reports/)
+ .then((pathname) => {
+ const customReportsId = parseInt(pathname.split("/")[2], 10);
+ H.createQuestion({
+ name: "Custom report question",
+ query: { "source-table": STATIC_ORDERS_ID },
+ collection_id: customReportsId,
+ });
+ H.visitCollection(customReportsId);
+ });
+ H.main().findByText("Custom report question").should("be.visible");
collectionMenu().click();
H.popover().within(() => {
+ cy.findByText("Edit permissions").should("be.visible");
cy.findByText("Clear out unused items").should("not.exist");
});
@@ -55,7 +68,7 @@ describe("scenarios > collections > clean up", () => {
cy.findByText("Clear out unused items").should("exist");
});
- cy.log("should not show in custom analytics collections");
+ cy.log("should not show collection actions in a trashed collection");
H.popover().within(() => {
cy.findByText("Move to trash").click();
});
@@ -67,15 +80,22 @@ describe("scenarios > collections > clean up", () => {
cy.log("should not show in empty collections");
H.createCollection({ name: "Empty" }).then(({ body: { id } }) => {
+ cy.intercept({
+ method: "GET",
+ pathname: `/api/collection/${id}/items`,
+ query: { limit: "0" },
+ }).as("emptyCollectionItemCount");
H.visitCollection(id);
+ cy.wait("@emptyCollectionItemCount");
collectionMenu().click();
H.popover().within(() => {
+ cy.findByText("Edit permissions").should("be.visible");
cy.findByText("Clear out unused items").should("not.exist");
});
});
cy.log(
- "should not recommend the option when there are stale items int he collection",
+ "should recommend the option when there are stale items in the collection",
);
H.createCollection({ name: "collection with stale items" }).then(
({ body: { id } }) => {
@@ -90,7 +110,6 @@ describe("scenarios > collections > clean up", () => {
.format("YYYY-MM-DD"),
);
- // assert we don't show clean up option
H.visitCollection(id);
collectionMenu().click();
H.popover().within(() => {
@@ -121,12 +140,15 @@ describe("scenarios > collections > clean up", () => {
req.on("response", (res) => {
res.send(assocIn(res.body, ["is_sample"], true));
});
- });
+ }).as("sampleCollection");
// assert we don't show clean up option
H.visitCollection(id);
+ cy.wait("@sampleCollection");
+ H.main().findByText("Bulk question 1").should("be.visible");
collectionMenu().click();
H.popover().within(() => {
+ cy.findByText("Edit permissions").should("be.visible");
cy.findByText("Clear out unused items").should("not.exist");
});
});
@@ -134,9 +156,12 @@ describe("scenarios > collections > clean up", () => {
);
});
- it("should not show to users who do not have write permissions to a collection", () => {
+ it("should not show the collection menu to users without write permissions to a collection", () => {
+ cy.signInAsAdmin();
+ H.activateToken("pro-self-hosted");
cy.signIn("readonly");
H.visitCollection(FIRST_COLLECTION_ID);
+ H.getCollectionActions().should("be.visible");
collectionMenu().should("not.exist");
});
});
@@ -301,12 +326,9 @@ describe("scenarios > collections > clean up", () => {
selectAllItems();
moveToTrash();
- cy.log(
- "should not longer show alert if user has used the clean up feature",
- );
closeCleanUpModal();
- // Ensure that stale items in Our Analytics are maked with a null collection id
+ // Ensure that stale items in Our Analytics are marked with a null collection id
H.expectUnstructuredSnowplowEvent(
(event) =>
event &&
@@ -315,46 +337,27 @@ describe("scenarios > collections > clean up", () => {
event.total_items_archived === 1 &&
typeof event.cutoff_date === "string",
);
- });
- });
-
- it("show empty and error states correctly", () => {
- cy.log("should handle empty state");
- cy.intercept("GET", "/api/ee/stale/**?**").as("stale-items");
-
- // visit collection w/ items but no stale items
- H.createCollection({ name: "Not empty w/ not stale items" })
- .then(({ body: { id } }) => id)
- .as("collectionId");
- cy.get("@collectionId").then((id) => {
- return bulkCreateQuestions(2, { collection_id: id }).then(() => {
- H.visitCollection(id);
+ cy.log("should handle empty state in a collection w/ no stale items");
+ H.main().within(() => {
+ cy.findByText("Type").should("be.visible");
+ cy.findByText("Name").should("be.visible");
+ });
+ cy.intercept("GET", "/api/ee/stale/**?**").as("stale-items");
+ selectCleanThingsUpCollectionAction();
+ cy.wait("@stale-items");
+ cleanUpModal().within(() => {
+ emptyState().should("exist");
});
- });
-
- cy.log("should render a table w/ contents");
- H.main().within(() => {
- cy.findByText("Type");
- cy.findByText("Name");
- });
-
- selectCleanThingsUpCollectionAction();
-
- cy.wait("@stale-items");
- cleanUpModal().within(() => {
- emptyState().should("exist");
+ cy.log("should handle error state");
+ cy.intercept("GET", "/api/ee/stale/**?**", {
+ statusCode: 500,
+ }).as("stale-items");
+ setDateFilter("1 year");
+ cy.wait("@stale-items");
+ errorState().should("exist");
});
-
- cy.log("should handle error state");
- cy.intercept("GET", "/api/ee/stale/**?**", {
- statusCode: 500,
- }).as("stale-items");
-
- setDateFilter("1 year");
- cy.wait("@stale-items");
- errorState().should("exist");
});
});
});
diff --git a/e2e/test/scenarios/collections/collection-picker-tenants.cy.spec.ts b/e2e/test/scenarios/collections/collection-picker-tenants.cy.spec.ts
index 9a8cd89a22f..74a6a135d69 100644
--- a/e2e/test/scenarios/collections/collection-picker-tenants.cy.spec.ts
+++ b/e2e/test/scenarios/collections/collection-picker-tenants.cy.spec.ts
@@ -14,7 +14,7 @@ function createSharedCollection(name: string, parentId?: number) {
});
}
-describe("scenarios > collections > collection picker with tenants", () => {
+describe("scenarios > collections > official and collection type controls in shared collections", () => {
beforeEach(() => {
H.restore();
cy.signInAsAdmin();
@@ -39,6 +39,9 @@ describe("scenarios > collections > collection picker with tenants", () => {
H.openCollectionMenu();
H.popover().within(() => {
+ cy.findByText("Move").should("be.visible");
+ cy.findByText("Move to trash").should("be.visible");
+
cy.log("Should not have 'Make collection official' option");
cy.findByText("Make collection official").should("not.exist");
cy.findByText("Remove Official badge").should("not.exist");
@@ -53,17 +56,17 @@ describe("scenarios > collections > collection picker with tenants", () => {
.click();
cy.findByTestId("new-collection-modal").within(() => {
- cy.log("Should not see 'Collection type' picker");
- cy.findByText(/Collection type/i).should("not.exist");
- cy.findByText("Regular").should("not.exist");
- cy.findByText("Official").should("not.exist");
-
cy.log("Verify we're creating inside the shared collection");
cy.findByTestId("collection-picker-button").should(
"contain",
"Test Shared Collection",
);
+ cy.log("Should not see 'Collection type' picker");
+ cy.findByText(/Collection type/i).should("not.exist");
+ cy.findByText("Regular").should("not.exist");
+ cy.findByText("Official").should("not.exist");
+
cy.log("Edge case: Change target collection to a normal collection");
cy.findByTestId("collection-picker-button").click();
});
@@ -89,14 +92,8 @@ describe("scenarios > collections > collection picker with tenants", () => {
cy.log("Close modal without creating");
cy.findByLabelText("Close").click();
});
- });
- });
- it("should block official collections in sub-collections of shared collections", () => {
- createSharedCollection("Shared Parent Collection").then((response) => {
- const sharedParentId = response.body.id;
-
- createSharedCollection("Shared Sub Collection", sharedParentId).then(
+ createSharedCollection("Shared Sub Collection", sharedCollectionId).then(
(subResponse) => {
const sharedSubCollectionId = subResponse.body.id;
@@ -113,6 +110,9 @@ describe("scenarios > collections > collection picker with tenants", () => {
H.openCollectionMenu();
H.popover().within(() => {
+ cy.findByText("Move").should("be.visible");
+ cy.findByText("Move to trash").should("be.visible");
+
cy.log("Should not have 'Make collection official' option");
cy.findByText("Make collection official").should("not.exist");
cy.findByText("Remove Official badge").should("not.exist");
@@ -127,6 +127,12 @@ describe("scenarios > collections > collection picker with tenants", () => {
.click();
cy.findByTestId("new-collection-modal").within(() => {
+ cy.log("Verify we're creating inside the shared sub-collection");
+ cy.findByTestId("collection-picker-button").should(
+ "contain",
+ "Shared Sub Collection",
+ );
+
cy.log("Should not see 'Collection type' picker");
cy.findByText(/Collection type/i).should("not.exist");
cy.findByText("Regular").should("not.exist");
@@ -166,47 +172,4 @@ describe("scenarios > collections > collection picker with tenants", () => {
cy.findByText("Official").should("not.exist");
});
});
-
- it("should show collection type picker when switching from shared to normal collection in create modal", () => {
- createSharedCollection("Shared Collection for Switching").then(
- (response) => {
- const sharedCollectionId = response.body.id;
-
- cy.log("Navigate inside shared collection");
- H.visitCollection(sharedCollectionId);
-
- cy.log("Start creating a sub-collection");
- cy.findByTestId("collection-menu")
- .findByLabelText("Create a new collection")
- .click();
-
- cy.findByTestId("new-collection-modal").within(() => {
- cy.log("Should not see collection type picker initially");
- cy.findByText(/Collection type/i).should("not.exist");
-
- cy.log("Click collection picker to change target");
- cy.findByTestId("collection-picker-button").click();
- });
-
- H.entityPickerModal().within(() => {
- cy.log("Select 'Our analytics' (normal collection)");
- cy.findByText("Our analytics").click();
- cy.button("Select").click();
- });
-
- cy.findByTestId("new-collection-modal").within(() => {
- cy.log("Wait for collection picker to update to 'Our analytics'");
- cy.findByTestId("collection-picker-button").should(
- "contain",
- "Our analytics",
- );
-
- cy.log("Should now see collection type picker");
- cy.findByText(/Collection type/i).should("exist");
- cy.findByText("Regular").should("exist");
- cy.findByText("Official").should("exist");
- });
- },
- );
- });
});
diff --git a/e2e/test/scenarios/collections/collection-pinned-overview.cy.spec.js b/e2e/test/scenarios/collections/collection-pinned-overview.cy.spec.js
index 82fbfe9c0ba..38c6b0bf5ac 100644
--- a/e2e/test/scenarios/collections/collection-pinned-overview.cy.spec.js
+++ b/e2e/test/scenarios/collections/collection-pinned-overview.cy.spec.js
@@ -53,13 +53,25 @@ describe("scenarios > collection pinned items overview", () => {
H.restore();
cy.signInAsAdmin();
- cy.intercept("POST", "/api/card/**/query").as("getCardQuery");
cy.intercept("GET", "/api/**/items?pinned-state*").as("getPinnedItems");
cy.intercept("GET", "/api/**/items?models*").as("getCollectionItems");
});
- it("should be able to pin a dashboard and keep it in the contents list", () => {
+ it("should be able to pin a question without rendering its visualization, a dashboard while keeping it in the contents list, and a model", () => {
+ cy.intercept("POST", "/api/card/**/query").as("getCardQuery");
openRootCollection();
+
+ cy.log("pin a question without rendering its visualization");
+ H.openUnpinnedItemMenu(QUESTION_NAME);
+ H.popover().findByText("Pin this").click();
+ cy.wait(["@getPinnedItems", "@getCollectionItems"]);
+
+ H.getPinnedSection().within(() => {
+ cy.findByText("A question").should("be.visible");
+ cy.get("@getCardQuery.all").should("have.length", 0);
+ });
+
+ cy.log("pin a dashboard and keep it in the contents list");
H.openUnpinnedItemMenu(DASHBOARD_NAME);
H.popover().findByText("Pin this").click();
cy.wait(["@getPinnedItems", "@getCollectionItems"]);
@@ -74,39 +86,15 @@ describe("scenarios > collection pinned items overview", () => {
cy.findByText(DASHBOARD_NAME).click();
cy.url().should("include", `/dashboard/${ORDERS_DASHBOARD_ID}`);
});
- });
- it("should be able to pin a question without rendering its visualization", () => {
openRootCollection();
- H.openUnpinnedItemMenu(QUESTION_NAME);
- H.popover().findByText("Pin this").click();
- cy.wait("@getPinnedItems");
-
H.getPinnedSection().within(() => {
- cy.findByText("A question").should("be.visible");
cy.findByText(QUESTION_NAME).click();
cy.url().should("include", `/question/${ORDERS_COUNT_QUESTION_ID}`);
});
- cy.get("@getCardQuery.all").should("have.length", 0);
- });
-
- it("should be able to pin a pivot table", () => {
- H.createQuestion(PIVOT_QUESTION_DETAILS).then(({ body: { id } }) => {
- cy.request("PUT", `/api/card/${id}`, { collection_position: 1 });
- });
-
- openRootCollection();
-
- H.getPinnedSection().within(() => {
- cy.findByText(PIVOT_QUESTION_DETAILS.name).should("be.visible");
- cy.findByText("A question").should("be.visible");
- });
- });
-
- it("should be able to pin a model", () => {
+ cy.log("pin a model");
cy.request("PUT", `/api/card/${ORDERS_QUESTION_ID}`, { type: "model" });
-
openRootCollection();
H.openUnpinnedItemMenu(MODEL_NAME);
H.popover().findByText("Pin this").click();
@@ -120,45 +108,37 @@ describe("scenarios > collection pinned items overview", () => {
});
});
- it("should be able to unpin a pinned dashboard", () => {
+ it("should be able to move, duplicate and unpin a pinned dashboard", () => {
cy.request("PUT", `/api/dashboard/${ORDERS_DASHBOARD_ID}`, {
collection_position: 1,
});
openRootCollection();
- H.openPinnedItemMenu(DASHBOARD_NAME);
- H.popover().findByText("Unpin").click();
- cy.wait("@getPinnedItems");
-
- H.getPinnedSection().should("not.exist");
- });
- it("should be able to move a pinned dashboard", () => {
- cy.request("PUT", `/api/dashboard/${ORDERS_DASHBOARD_ID}`, {
- collection_position: 1,
- });
-
- openRootCollection();
+ cy.log("should be able to move a pinned dashboard");
H.openPinnedItemMenu(DASHBOARD_NAME);
H.popover().findByText("Move").click();
+ H.entityPickerModal()
+ .findByText(`Move "${DASHBOARD_NAME}"?`)
+ .should("be.visible");
+ H.entityPickerModal().button("Cancel").click();
+ H.entityPickerModal().should("not.exist");
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText(`Move "${DASHBOARD_NAME}"?`).should("be.visible");
- });
-
- it("should be able to duplicate a pinned dashboard", () => {
- cy.request("PUT", `/api/dashboard/${ORDERS_DASHBOARD_ID}`, {
- collection_position: 1,
- });
-
- openRootCollection();
+ cy.log("should be able to duplicate a pinned dashboard");
H.openPinnedItemMenu(DASHBOARD_NAME);
H.popover().findByText("Duplicate").click();
+ H.modal()
+ .findByText(`Duplicate "${DASHBOARD_NAME}" and its questions`)
+ .should("be.visible");
+ H.modal().button("Cancel").click();
+ H.modal().should("not.exist");
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText(`Duplicate "${DASHBOARD_NAME}" and its questions`).should(
- "be.visible",
- );
+ cy.log("should be able to unpin a pinned dashboard");
+ H.openPinnedItemMenu(DASHBOARD_NAME);
+ H.popover().findByText("Unpin").click();
+ cy.wait("@getPinnedItems");
+
+ H.getPinnedSection().should("not.exist");
});
it("should be able to archive a pinned dashboard", () => {
@@ -176,22 +156,6 @@ describe("scenarios > collection pinned items overview", () => {
cy.findByText(DASHBOARD_NAME).should("not.exist");
});
- it("should render pinned native questions as static cards", () => {
- H.createNativeQuestion(SQL_QUESTION_DETAILS_REQUIRED_PARAMETER).then(
- ({ body: { id } }) => {
- cy.request("PUT", `/api/card/${id}`, { collection_position: 1 });
- },
- );
-
- openRootCollection();
- H.getPinnedSection().within(() => {
- cy.findByText(SQL_QUESTION_DETAILS_REQUIRED_PARAMETER.name).should(
- "be.visible",
- );
- cy.findByText("A question").should("be.visible");
- });
- });
-
it("should render all pinned items in a single section without type headings", () => {
cy.request("PUT", `/api/dashboard/${ORDERS_DASHBOARD_ID}`, {
collection_position: 1,
@@ -199,12 +163,25 @@ describe("scenarios > collection pinned items overview", () => {
cy.request("PUT", `/api/card/${ORDERS_COUNT_QUESTION_ID}`, {
collection_position: 2,
});
+ H.createQuestion(PIVOT_QUESTION_DETAILS).then(({ body: { id } }) => {
+ cy.request("PUT", `/api/card/${id}`, { collection_position: 3 });
+ });
+ H.createNativeQuestion(SQL_QUESTION_DETAILS_REQUIRED_PARAMETER).then(
+ ({ body: { id } }) => {
+ cy.request("PUT", `/api/card/${id}`, { collection_position: 4 });
+ },
+ );
openRootCollection();
H.getPinnedSection().within(() => {
cy.findByText(DASHBOARD_NAME).should("be.visible");
cy.findByText(QUESTION_NAME).should("be.visible");
+ cy.findByText(PIVOT_QUESTION_DETAILS.name).should("be.visible");
+ cy.findByText(SQL_QUESTION_DETAILS_REQUIRED_PARAMETER.name).should(
+ "be.visible",
+ );
+ cy.findAllByText("A question").should("have.length", 3);
cy.findByText("Dashboards").should("not.exist");
cy.findByText("Pinned questions").should("not.exist");
});
diff --git a/e2e/test/scenarios/collections/collections-reproductions.cy.spec.ts b/e2e/test/scenarios/collections/collections-reproductions.cy.spec.ts
index 8cba2dc403f..45e68373be6 100644
--- a/e2e/test/scenarios/collections/collections-reproductions.cy.spec.ts
+++ b/e2e/test/scenarios/collections/collections-reproductions.cy.spec.ts
@@ -1,4 +1,5 @@
const { H } = cy;
+import { USER_GROUPS } from "e2e/support/cypress_data";
import {
ADMIN_PERSONAL_COLLECTION_ID,
FIRST_COLLECTION_ID,
@@ -7,6 +8,8 @@ import {
} from "e2e/support/cypress_sample_instance_data";
import type { CollectionId } from "metabase-types/api";
+const { ALL_USERS_GROUP } = USER_GROUPS;
+
describe("issue 20911", () => {
const COLLECTION_ACCESS_PERMISSION_INDEX = 0;
const FIRST_COLLECTION = "First collection";
@@ -209,12 +212,15 @@ describe("issue 56567", () => {
["readonly", "View"],
];
- it("should propagate permission to sub-collections when 'Also change sub-collections' is checked (metabase#56567)", () => {
+ it("should propagate permission to sub-collections only when 'Also change sub-collections' is checked (metabase#56567)", () => {
withTestCollections((collectionAId, collectionBId) => {
- cy.visit(`/admin/permissions/collections/${collectionAId}`);
-
- H.assertPermissionTable(getTestPermissionsTable("No access"));
+ cy.intercept("PUT", "/api/collection/graph?skip-graph=true").as(
+ "savePermissions",
+ );
+ cy.log(
+ "should NOT propagate when 'Also change sub-collections' is unchecked",
+ );
cy.visit(`/admin/permissions/collections/${collectionBId}`);
H.assertPermissionTable(getTestPermissionsTable("No access"));
@@ -224,37 +230,35 @@ describe("issue 56567", () => {
// opens up the permissions select
H.getPermissionRowPermissions("All Users").click();
- // checks the 'Also change sub-collections' toggle
- H.popover().findByRole("switch").click({ force: true });
- H.popover().findByRole("switch").should("be.checked");
-
- // selected desired permission
+ // selected desired permission without checking 'Also change sub-collections'
H.popover().findByText("View").click();
// opens up the permissions select again
H.getPermissionRowPermissions("All Users").click();
- // ensures the toggle is still checked
- H.popover().findByRole("switch").should("be.checked");
+ // ensures the toggle is not checked
+ H.popover().findByRole("switch").should("not.be.checked");
- cy.intercept("PUT", "/api/collection/graph?skip-graph=true").as(
- "savePermissions",
- );
cy.button("Save").click();
cy.wait("@savePermissions");
// Checks permissions for collection A is set to "View" as expected
- cy.visit(`/admin/permissions/collections/${collectionBId}`);
+ cy.visit(`/admin/permissions/collections/${collectionAId}`);
H.assertPermissionTable(getTestPermissionsTable("View"));
- // Check the permission set to collection A was propagated to collection B
+ // Check the permission set to collection A was NOT propagated to collection B
cy.visit(`/admin/permissions/collections/${collectionBId}`);
- H.assertPermissionTable(getTestPermissionsTable("View"));
- });
- });
+ H.assertPermissionTable(getTestPermissionsTable("No access"));
+
+ cy.log("should propagate when 'Also change sub-collections' is checked");
+ cy.updateCollectionGraph({
+ [ALL_USERS_GROUP]: { [collectionAId]: "none" },
+ });
+
+ cy.visit(`/admin/permissions/collections/${collectionAId}`);
+
+ H.assertPermissionTable(getTestPermissionsTable("No access"));
- it("should NOT propagate permission to sub-collections when 'Also change sub-collections' is unchecked", () => {
- withTestCollections((collectionAId, collectionBId) => {
cy.visit(`/admin/permissions/collections/${collectionBId}`);
H.assertPermissionTable(getTestPermissionsTable("No access"));
@@ -264,18 +268,19 @@ describe("issue 56567", () => {
// opens up the permissions select
H.getPermissionRowPermissions("All Users").click();
- // selected desired permission without checking 'Also change sub-collections'
+ // checks the 'Also change sub-collections' toggle
+ H.popover().findByRole("switch").click({ force: true });
+ H.popover().findByRole("switch").should("be.checked");
+
+ // selected desired permission
H.popover().findByText("View").click();
// opens up the permissions select again
H.getPermissionRowPermissions("All Users").click();
- // ensures the toggle is not checked
- H.popover().findByRole("switch").should("not.be.checked");
+ // ensures the toggle is still checked
+ H.popover().findByRole("switch").should("be.checked");
- cy.intercept("PUT", "/api/collection/graph?skip-graph=true").as(
- "savePermissions",
- );
cy.button("Save").click();
cy.wait("@savePermissions");
@@ -283,9 +288,9 @@ describe("issue 56567", () => {
cy.visit(`/admin/permissions/collections/${collectionAId}`);
H.assertPermissionTable(getTestPermissionsTable("View"));
- // Check the permission set to collection A was NOT propagated to collection B
+ // Check the permission set to collection A was propagated to collection B
cy.visit(`/admin/permissions/collections/${collectionBId}`);
- H.assertPermissionTable(getTestPermissionsTable("No access"));
+ H.assertPermissionTable(getTestPermissionsTable("View"));
});
});
});
diff --git a/e2e/test/scenarios/collections/collections.cy.spec.js b/e2e/test/scenarios/collections/collections.cy.spec.js
index 4fe2d20562d..d3a69360891 100644
--- a/e2e/test/scenarios/collections/collections.cy.spec.js
+++ b/e2e/test/scenarios/collections/collections.cy.spec.js
@@ -15,8 +15,6 @@ import {
THIRD_COLLECTION_ID,
} from "e2e/support/cypress_sample_instance_data";
-import { displaySidebarChildOf } from "./helpers/e2e-collections-sidebar.js";
-
const { nocollection } = USERS;
const { DATA_GROUP } = USER_GROUPS;
const { ORDERS, ORDERS_ID, FEEDBACK_ID } = SAMPLE_DATABASE;
@@ -25,16 +23,13 @@ describe("scenarios > collection defaults", () => {
beforeEach(() => {
H.restore();
cy.signInAsAdmin();
- cy.intercept("GET", "/api/**/items?pinned-state*").as("getPinnedItems");
cy.intercept("GET", "/api/collection/tree**").as("getTree");
cy.intercept("GET", "/api/collection/*/items?**").as("getCollectionItems");
});
describe("new collection button", () => {
beforeEach(() => {
- H.restore();
H.resetSnowplow();
- cy.signInAsAdmin();
H.enableTracking();
});
@@ -133,7 +128,7 @@ describe("scenarios > collection defaults", () => {
cy.viewport(800, 500);
H.startNewCollectionFromSidebar();
- cy.findByTestId("new-collection-modal").then((modal) => {
+ cy.findByTestId("new-collection-modal").within(() => {
cy.findByPlaceholderText("My new fantastic collection").type(
"Test collection",
{ force: true },
@@ -162,13 +157,14 @@ describe("scenarios > collection defaults", () => {
it("should navigate effortlessly through collections tree", () => {
visitRootCollection();
- H.navigationSidebar().within(() => {
- cy.log(
- "should allow a user to expand a collection without navigating to it",
- );
+ cy.log(
+ "should allow a user to expand a collection without navigating to it",
+ );
+
+ // 1. click on the chevron to expand the sub collection
+ H.displaySidebarChildOf("First collection");
- // 1. click on the chevron to expand the sub collection
- displaySidebarChildOf("First collection");
+ H.navigationSidebar().within(() => {
// 2. I should see the nested collection name
cy.findByText("Second collection");
cy.findByText("Third collection").should("not.exist");
@@ -210,6 +206,15 @@ describe("scenarios > collection defaults", () => {
ensureCollectionHasNoChildren("Third collection");
ensureCollectionHasNoChildren("Your personal collection");
});
+
+ cy.log("new collections are created within the current collection");
+ H.startNewCollectionFromSidebar();
+ cy.findByTestId("new-collection-modal").within(() => {
+ cy.findByText("Collection it's saved in").should("be.visible");
+ cy.findByTestId("collection-picker-button")
+ .findByText("Second collection")
+ .should("be.visible");
+ });
});
it("should correctly display deep nested collections with long names", () => {
@@ -227,9 +232,7 @@ describe("scenarios > collection defaults", () => {
H.visitCollection(THIRD_COLLECTION_ID);
// 1. Expand so that deeply nested collection is showing
- H.navigationSidebar().within(() => {
- displaySidebarChildOf("Fourth collection");
- });
+ H.displaySidebarChildOf("Fourth collection");
// 2. Ensure we show the helpful tooltip with the full (long) collection name
// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
@@ -273,33 +276,31 @@ describe("scenarios > collection defaults", () => {
});
});
- it("should support markdown in collection description", () => {
+ it("should support markdown in collection description and allow it to be edited in the sidesheet", () => {
+ cy.request("PUT", `/api/collection/${FIRST_COLLECTION_ID}`, {
+ description: "[link](https://metabase.com)",
+ });
cy.request("PUT", `/api/collection/${SECOND_COLLECTION_ID}`, {
description: "[link](https://metabase.com)",
});
H.visitCollection(FIRST_COLLECTION_ID);
- cy.get("table").within(() => {
- cy.findByText("Second collection")
- .closest("tr")
- .within(() => {
- cy.icon("info").trigger("mouseenter");
- });
- });
+ cy.log("Markdown description renders in the collection items tooltip");
+ cy.findByTestId("collection-table")
+ .findByText("Second collection")
+ .closest("tr")
+ .icon("info")
+ .as("descriptionIcon")
+ .trigger("mouseenter");
cy.findByRole("tooltip").within(() => {
cy.findByRole("link").should("include.text", "link");
cy.findByRole("link").should("not.include.text", "[link]");
});
- });
-
- it("should allow description to be edited in the sidesheet", () => {
- cy.request("PUT", `/api/collection/${FIRST_COLLECTION_ID}`, {
- description: "[link](https://metabase.com)",
- });
- H.visitCollection(FIRST_COLLECTION_ID);
+ cy.get("@descriptionIcon").trigger("mouseleave");
+ cy.findByRole("tooltip").should("not.exist");
cy.log("Description visible in collection caption");
cy.findByTestId("collection-caption")
@@ -334,56 +335,54 @@ describe("scenarios > collection defaults", () => {
});
});
- describe("render last edited by when names are null", () => {
- it("should render short value without tooltip", () => {
- cy.intercept(
- "GET",
- "/api/collection/root/items?models=dashboard**",
- (req) => {
- req.on("response", (res) => {
- res.send(
- assocIn(res.body, ["data", 0, "last-edit-info"], {
- id: 1,
- last_name: null,
- first_name: null,
- email: "[email protected]",
- timestamp: "2022-07-05T07:31:09.054-07:00",
- }),
- );
- });
- },
- );
- visitRootCollection();
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText("[email protected]").trigger("mouseenter");
- cy.findByRole("tooltip").should("not.exist");
+ it("should render last edited by email when names are null, with a tooltip only for long values", () => {
+ const LONG_EMAIL = "[email protected]";
+ const SHORT_EMAIL = "[email protected]";
+ const lastEditInfo = (email) => ({
+ id: 1,
+ last_name: null,
+ first_name: null,
+ email,
+ timestamp: "2022-07-05T07:31:09.054-07:00",
});
- it("should render long value with tooltip", () => {
- cy.intercept(
- "GET",
- "/api/collection/root/items?models=dashboard**",
- (req) => {
- req.on("response", (res) => {
- res.send(
- assocIn(res.body, ["data", 0, "last-edit-info"], {
- id: 1,
- last_name: null,
- first_name: null,
- email: "[email protected]",
- timestamp: "2022-07-05T07:31:09.054-07:00",
- }),
- );
- });
- },
- );
- visitRootCollection();
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText("[email protected]").trigger(
- "mouseenter",
- );
- cy.findByRole("tooltip").should("exist");
- });
+ cy.intercept(
+ "GET",
+ "/api/collection/root/items?models=dashboard**",
+ (req) => {
+ req.on("response", (res) => {
+ const withLong = assocIn(
+ res.body,
+ ["data", 0, "last-edit-info"],
+ lastEditInfo(LONG_EMAIL),
+ );
+ res.send(
+ assocIn(
+ withLong,
+ ["data", 1, "last-edit-info"],
+ lastEditInfo(SHORT_EMAIL),
+ ),
+ );
+ });
+ },
+ );
+ visitRootCollection();
+
+ cy.log("long value renders with a tooltip");
+ cy.findByTestId("collection-table")
+ .findByText(LONG_EMAIL)
+ .as("longEmail")
+ .trigger("mouseenter");
+ cy.findByRole("tooltip").should("be.visible");
+
+ cy.get("@longEmail").trigger("mouseleave");
+ cy.findByRole("tooltip").should("not.exist");
+
+ cy.log("short value renders without a tooltip");
+ cy.findByTestId("collection-table")
+ .findByText(SHORT_EMAIL)
+ .trigger("mouseenter");
+ cy.findByRole("tooltip").should("not.exist");
});
it("should not show you the parent collection in recents or search results", () => {
@@ -405,12 +404,7 @@ describe("scenarios > collection defaults", () => {
});
describe("Collection related issues reproductions", () => {
- beforeEach(() => {
- H.restore();
- cy.signInAsAdmin();
- });
-
- it("should handle moving a question when you don't have access to entire collection path (metabase#44316", () => {
+ it("should handle moving a question when you don't have access to entire collection path (metabase#44316)", () => {
H.createCollection({
name: "Collection A",
}).then(({ body: collectionA }) => {
@@ -478,41 +472,11 @@ describe("scenarios > collection defaults", () => {
);
});
- it("should show list of collection items even if one question has invalid parameters (metabase#25543)", () => {
- const questionDetails = {
- native: { query: "select 1 --[[]]", "template-tags": {} },
- };
-
- H.createNativeQuestion(questionDetails);
-
- visitRootCollection();
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText("Orders in a dashboard");
- });
-
- it("should be able to drag an item to the root collection (metabase#16498)", () => {
- moveItemToCollection("Orders", "First collection");
-
- H.visitCollection(FIRST_COLLECTION_ID);
-
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText("Orders").as("dragSubject");
-
- H.navigationSidebar().findByText("Our analytics").as("dropTarget");
-
- H.dragAndDrop("dragSubject", "dropTarget");
-
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText("Moved question");
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText("Orders").should("not.exist");
-
- visitRootCollection();
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText("Orders");
- });
-
it("should be able to drag an item into a sub-collection shown in the items table (metabase#37329)", () => {
+ H.createNativeQuestion({
+ name: "Native question with invalid parameters",
+ native: { query: "select 1 --[[]]", "template-tags": {} },
+ });
H.createDocument({
name: "Quarterly Notes",
collection_id: null,
@@ -539,6 +503,16 @@ describe("scenarios > collection defaults", () => {
visitRootCollection();
+ cy.log(
+ "Collection items are listed even if one question has invalid parameters (metabase#25543)",
+ );
+ cy.findByTestId("collection-table").within(() => {
+ cy.findByText("Native question with invalid parameters").should(
+ "be.visible",
+ );
+ cy.findByText("Orders in a dashboard").should("be.visible");
+ });
+
cy.log("Drag a question into the sub-collection row");
cy.findByTestId("collection-table").within(() => {
cy.findByText("Orders").as("dragSubject");
@@ -581,6 +555,23 @@ describe("scenarios > collection defaults", () => {
cy.findByTestId("collection-table").findByText("Orders");
cy.findByTestId("collection-table").findByText("Quarterly Notes");
cy.findByTestId("collection-table").findByText("Count of orders");
+
+ cy.log("Drag an item to the root collection (metabase#16498)");
+ cy.findByTestId("collection-table")
+ .findByText("Orders")
+ .as("rootDragSubject");
+ H.navigationSidebar().findByText("Our analytics").as("rootDropTarget");
+
+ H.dragAndDrop("rootDragSubject", "rootDropTarget");
+
+ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
+ cy.findByText("Moved question");
+ cy.findByTestId("collection-table")
+ .findByText("Orders")
+ .should("not.exist");
+
+ visitRootCollection();
+ cy.findByTestId("collection-table").findByText("Orders");
});
it("should reject dragging a subcollection directly or in a mixed selection (metabase#37329)", () => {
@@ -591,18 +582,23 @@ describe("scenarios > collection defaults", () => {
"PUT",
/\/api\/(card|collection)\/\d+$/,
cy.spy().as("moveRequest"),
- );
+ ).as("move");
cy.log("Subcollections cannot initiate a drag");
- cy.findByTestId("collection-table")
- .findByText("First collection")
- .closest("a")
- .should("have.attr", "draggable", "false");
+ cy.findByTestId("collection-table").within(() => {
+ cy.findByText("First collection")
+ .closest("a")
+ .should("have.attr", "draggable", "false");
+ cy.findByText("First collection").as("collectionDragSubject");
+ cy.findByText("Destination collection").as("collectionDropTarget");
+ });
+
+ H.dragAndDrop("collectionDragSubject", "collectionDropTarget");
+
cy.findByTestId("items-drag-preview").should("not.exist");
cy.findByTestId("collection-table")
.findByText("First collection")
.should("be.visible");
- cy.get("@moveRequest").should("not.have.been.called");
cy.log("A mixed selection is rejected as one operation");
cy.findByTestId("collection-table").within(() => {
@@ -619,7 +615,22 @@ describe("scenarios > collection defaults", () => {
cy.findByText("First collection").should("be.visible");
cy.findByText("Destination collection").should("be.visible");
});
- cy.get("@moveRequest").should("not.have.been.called");
+
+ cy.log("Dropping only the question moves it with a single request");
+ cy.findByTestId("collection-table").within(() => {
+ selectItemUsingCheckbox("First collection");
+ });
+ cy.findByTestId("toast-card")
+ .findByText("1 item selected")
+ .should("be.visible");
+
+ H.dragAndDrop("dragSubject", "dropTarget");
+ cy.wait("@move");
+
+ cy.findByTestId("collection-table")
+ .findByText("Orders")
+ .should("not.exist");
+ cy.get("@moveRequest").should("have.been.calledOnce");
});
describe("nested collections with revoked parent access", () => {
@@ -665,10 +676,10 @@ describe("scenarios > collection defaults", () => {
cy.visit("/");
H.navigationSidebar().within(() => {
+ cy.findByText("Child").should("be.visible");
+ cy.findByText("Your personal collection").should("be.visible");
cy.findByText("Our analytics").should("not.exist");
cy.findByText("Parent").should("not.exist");
- cy.findByText("Child");
- cy.findByText("Your personal collection");
});
// Even if user tries to navigate directly to the root collection, we have to make sure its content is not shown
@@ -696,7 +707,7 @@ describe("scenarios > collection defaults", () => {
});
});
- it("sub-collection should be available in save and move modals (metabase#14122)", () => {
+ it("sub-collection should be available in move modal (metabase#14122)", () => {
const COLLECTION = "14122C";
// Create Parent collection within admin's personal collection
@@ -835,18 +846,46 @@ describe("scenarios > collection defaults", () => {
// Select all
cy.findByLabelText("Select all items").click();
assertSelectAllIsIndeterminate(false);
+ cy.findByLabelText("Select all items").should("be.checked");
H.getPinnedSection()
.findByRole("checkbox", { name: "Orders, Count" })
.should("have.attr", "aria-checked", "true");
- cy.findByTestId("toast-card")
- .findByText(/\d+ items selected/)
- .should("be.visible");
+ H.getUnpinnedSection()
+ .findAllByRole("checkbox")
+ .each((checkbox) => {
+ cy.wrap(checkbox).should("be.checked");
+ });
+
+ // Deselecting the pinned card keeps the rest of the selection
+ H.getPinnedSection()
+ .findByRole("checkbox", { name: "Orders, Count" })
+ .click();
+ H.getPinnedSection()
+ .findByRole("checkbox", { name: "Orders, Count" })
+ .should("have.attr", "aria-checked", "false");
+ assertSelectAllIsIndeterminate(true);
+ cy.findByTestId("toast-card").should("be.visible");
+ H.getPinnedSection()
+ .findByRole("checkbox", { name: "Orders, Count" })
+ .click();
+ assertSelectAllIsIndeterminate(false);
+ cy.findByLabelText("Select all items").should("be.checked");
// Deselect all
cy.findByLabelText("Select all items").click();
- cy.findAllByRole("checkbox").should("not.be.checked");
+ cy.findByLabelText("Select all items").should("not.be.checked");
+ assertSelectAllIsIndeterminate(false);
cy.findByTestId("toast-card").should("not.exist");
+ H.getPinnedSection().findByText("Orders, Count").should("be.visible");
+ H.getPinnedSection()
+ .findByRole("checkbox", { name: "Orders, Count" })
+ .should("not.exist");
+ H.getUnpinnedSection()
+ .findAllByRole("checkbox")
+ .each((checkbox) => {
+ cy.wrap(checkbox).should("not.be.checked");
+ });
});
it("should support shift+click and the Select menu entry", () => {
@@ -882,7 +921,7 @@ describe("scenarios > collection defaults", () => {
.should("be.visible");
});
- it("should clear the selection with Escape and trash it with Delete", () => {
+ it("should clear the selection with Escape and trash it with Delete or the bulk actions menu (metabase#16496)", () => {
cy.visit("/collection/root");
selectItemUsingCheckbox("Orders");
cy.findByTestId("toast-card")
@@ -899,6 +938,24 @@ describe("scenarios > collection defaults", () => {
H.getUnpinnedSection().findByText("Orders").should("not.exist");
cy.findByTestId("toast-card").should("not.exist");
+
+ cy.log("bulk archive from the selection toast (metabase#16496)");
+ H.getUnpinnedSection()
+ .findByText("Orders, Count")
+ .should("be.visible");
+ selectItemUsingCheckbox("Orders, Count");
+ cy.findByTestId("toast-card")
+ .findByText("1 item selected")
+ .should("be.visible");
+
+ cy.findByTestId("toast-card").findByLabelText("More actions").click();
+ H.popover().findByText("Move to trash").click();
+ H.modal().button("Move to trash").click();
+
+ H.getUnpinnedSection()
+ .findByText("Orders, Count")
+ .should("not.exist");
+ cy.findByTestId("toast-card").should("not.exist");
});
it("should clean up selection when opening another collection (metabase#16491)", () => {
@@ -919,20 +976,6 @@ describe("scenarios > collection defaults", () => {
});
});
- describe("archive", () => {
- it("should be possible to bulk archive items (metabase#16496)", () => {
- cy.visit("/collection/root");
- selectItemUsingCheckbox("Orders");
-
- cy.findByTestId("toast-card").findByLabelText("More actions").click();
- H.popover().findByText("Move to trash").click();
- H.modal().button("Move to trash").click();
-
- H.getUnpinnedSection().findByText("Orders").should("not.exist");
- cy.findByTestId("toast-card").should("not.exist");
- });
- });
-
describe("move", () => {
it("should be possible to bulk move items and undo", () => {
cy.visit("/collection/root");
@@ -958,8 +1001,92 @@ describe("scenarios > collection defaults", () => {
cy.findByTestId("toast-undo").should("not.exist");
});
- it("moving collections should disable moving into any of the moving collections", () => {
+ it("moving collections should disable moving into any of the moving collections, including in recents and search (metabase#45248)", () => {
H.createCollection({ name: "Another collection" });
+ H.createCollection({ name: "Outer collection 1" }).then(
+ ({ body: { id: parentCollectionId } }) => {
+ H.createCollection({
+ name: "Inner collection 1",
+ parent_id: parentCollectionId,
+ }).then(({ body: { id: innerCollectionId } }) => {
+ cy.wrap(innerCollectionId).as("innerCollectionId");
+ });
+ H.createCollection({
+ name: "Inner collection 2",
+ parent_id: parentCollectionId,
+ });
+ },
+ );
+ H.createCollection({ name: "Outer collection 2" }).then(
+ ({ body: { id: outerCollectionId } }) => {
+ cy.wrap(outerCollectionId).as("outerCollectionId");
+ },
+ );
+
+ cy.log(
+ "mark an inner and an unrelated collection as recently selected",
+ );
+ cy.get("@innerCollectionId").then((innerCollectionId) => {
+ cy.request("POST", "/api/activity/recents", {
+ context: "selection",
+ model: "collection",
+ model_id: innerCollectionId,
+ });
+ });
+ cy.get("@outerCollectionId").then((outerCollectionId) => {
+ cy.request("POST", "/api/activity/recents", {
+ context: "selection",
+ model: "collection",
+ model_id: outerCollectionId,
+ });
+ });
+ cy.visit("/collection/root");
+
+ cy.log("single move in recents and search (metabase#45248)");
+
+ cy.wait("@getCollectionItems");
+
+ H.openCollectionItemMenu("Outer collection 1");
+
+ H.popover().findByText("Move").click();
+
+ H.entityPickerModal().within(() => {
+ cy.findByText("Outer collection 2").should("exist");
+ cy.findByText(/Inner collection/i).should("not.exist");
+
+ cy.findByText("Recent items").click();
+ // search and recent results are labeled "[collection name] [parent collection name]"
+ cy.findByRole("link", { name: /Outer collection 2 / }).should(
+ "exist",
+ );
+ cy.findByText(/Inner collection/i).should("not.exist");
+
+ cy.findByPlaceholderText("Search…").type("collection");
+ cy.findByRole("link", { name: /Outer collection 2 / }).should(
+ "exist",
+ );
+ cy.findByText(/Inner collection/i).should("not.exist");
+
+ cy.button("Cancel").click();
+ });
+
+ cy.log("bulk move in recents (metabase#45248)");
+
+ cy.findByTestId("collection-table").within(() => {
+ selectItemUsingCheckbox("Orders");
+ selectItemUsingCheckbox("Outer collection 1");
+ });
+
+ cy.findByTestId("toast-card").button("Move").click();
+
+ H.entityPickerModal().within(() => {
+ cy.findByText("Outer collection 2").should("exist");
+ cy.findByText("Recent items").click();
+ cy.findByRole("link", { name: /Outer collection 2 / }).should(
+ "exist",
+ );
+ cy.findByText(/Inner collection/i).should("not.exist");
+ });
cy.log("moving a single collection");
cy.visit(`/collection/${SECOND_COLLECTION_ID}`);
@@ -1037,61 +1164,6 @@ describe("scenarios > collection defaults", () => {
);
});
});
-
- it("moving collections should disable moving into any of the moving collections in recents or search (metabase#45248)", () => {
- H.createCollection({ name: "Outer collection 1" }).then(
- ({ body: { id: parentCollectionId } }) => {
- cy.wrap(parentCollectionId).as("outerCollectionId");
- H.createCollection({
- name: "Inner collection 1",
- parent_id: parentCollectionId,
- }).then(({ body: { id: innerCollectionId } }) => {
- cy.wrap(innerCollectionId).as("innerCollectionId");
- });
- H.createCollection({
- name: "Inner collection 2",
- parent_id: parentCollectionId,
- });
- },
- );
- H.createCollection({ name: "Outer collection 2" });
-
- // mark the inner collection as recently selected
- cy.get("@innerCollectionId").then((innerCollectionId) => {
- cy.request("POST", "/api/activity/recents", {
- context: "selection",
- model: "collection",
- model_id: innerCollectionId,
- });
- });
- cy.visit("/collection/root");
-
- cy.log("single move");
-
- cy.wait("@getCollectionItems");
-
- H.openCollectionItemMenu("Outer collection 1");
-
- H.popover().findByText("Move").click();
-
- H.entityPickerModal().within(() => {
- cy.findByText(/inner collection/).should("not.exist");
- cy.button("Cancel").click();
- });
-
- cy.log("bulk move");
-
- cy.findByTestId("collection-table").within(() => {
- selectItemUsingCheckbox("Orders");
- selectItemUsingCheckbox("Outer collection 1");
- });
-
- cy.findByTestId("toast-card").button("Move").click();
-
- H.entityPickerModal().within(() => {
- cy.findByText(/inner collection/).should("not.exist");
- });
- });
});
});
@@ -1106,23 +1178,10 @@ describe("scenarios > collection defaults", () => {
cy.findByText("First collection");
});
});
-
- it("should create new collections within the current collection", () => {
- H.visitCollection(THIRD_COLLECTION_ID);
- H.startNewCollectionFromSidebar();
-
- cy.findByTestId("new-collection-modal").then((modal) => {
- cy.findByText("Collection it's saved in").should("be.visible");
- cy.findByTestId("collection-picker-button")
- .findByText("Third collection")
- .should("be.visible");
- });
- });
});
describe("x-rays", () => {
beforeEach(() => {
- H.restore();
cy.signInAsNormalUser();
cy.intercept("GET", "/api/automagic-dashboards/model/*").as("dashboard");
});
@@ -1133,7 +1192,11 @@ describe("scenarios > collection defaults", () => {
openEllipsisMenuFor("Orders");
H.popover().findByText("X-ray this").click();
- cy.wait("@dashboard");
+ cy.wait("@dashboard").its("response.statusCode").should("eq", 200);
+
+ cy.url().should("include", "/auto/dashboard/model/");
+ cy.findByTestId("automatic-dashboard-header").should("be.visible");
+ H.getDashboardCards().should("have.length.greaterThan", 0);
});
});
});
@@ -1400,7 +1463,7 @@ describe("scenarios > collection items listing", () => {
);
});
- it("should allow to navigate back and forth", () => {
+ it("should allow to navigate back and forth and reset pagination when sorting", () => {
visitRootCollection();
// First page
@@ -1429,6 +1492,19 @@ describe("scenarios > collection items listing", () => {
cy.findByText(`1 - ${PAGE_SIZE}`);
cy.findByTestId("pagination-total").should("have.text", TOTAL_ITEMS);
cy.findAllByTestId("collection-entry").should("have.length", PAGE_SIZE);
+
+ cy.log("sorting on a page other than the first resets pagination");
+ // The second page is cached, so revisiting it sends no request
+ cy.findByLabelText("Next page").click();
+ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
+ cy.findByText(`${PAGE_SIZE + 1} - ${TOTAL_ITEMS}`);
+
+ toggleSortingFor(/Last edited at/i);
+ cy.wait("@getCollectionItems");
+
+ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
+ cy.findByText(`1 - ${PAGE_SIZE}`);
+ cy.findAllByTestId("collection-entry").should("have.length", PAGE_SIZE);
});
});
@@ -1460,7 +1536,10 @@ describe("scenarios > collection items listing", () => {
visitRootCollection();
// We're waiting for the loading spinner to disappear from the main sidebar.
// Otherwise, this causes the page re-render and the flaky test.
- cy.findByTestId("main-navbar-root").get("circle").should("not.exist");
+ cy.findByTestId("main-navbar-root")
+ .findByText("Our analytics")
+ .should("be.visible");
+ cy.findByTestId("main-navbar-root").find("circle").should("not.exist");
cy.log("sorted alphabetically by default");
assertCollectionItemsOrder("collection-entry-name", [
@@ -1584,30 +1663,6 @@ describe("scenarios > collection items listing", () => {
"First collection",
]);
});
-
- it("should reset pagination if sorting applied on not first page", () => {
- _.times(15, (i) => H.createDashboard(`dashboard ${i}`));
- _.times(15, (i) =>
- H.createQuestion({
- name: `generated question ${i}`,
- query: TEST_QUESTION_QUERY,
- }),
- );
-
- visitRootCollection();
-
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText(`1 - ${PAGE_SIZE}`);
-
- cy.findByLabelText("Next page").click();
- cy.wait("@getCollectionItems");
-
- toggleSortingFor(/Last edited at/i);
- cy.wait("@getCollectionItems");
-
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText(`1 - ${PAGE_SIZE}`);
- });
});
});
@@ -1617,15 +1672,15 @@ describe("scenarios > collections > entity id support", () => {
cy.signInAsAdmin();
});
- it("/collection/entity/${entity_id} should redirect to /collection/${id}", () => {
+ it("/collection/entity/${entity_id} and /collection/entity/${entity_id}/move should redirect to /collection/${id} and /collection/${id}/move", () => {
+ cy.log("/collection/entity/${entity_id}");
cy.visit(`/collection/entity/${FIRST_COLLECTION_ENTITY_ID}`);
cy.url().should("contain", `/collection/${FIRST_COLLECTION_ID}`);
// Making sure the collection loads
H.main().findByText("First collection").should("be.visible");
- });
- it("/collection/entity/${entity_id}/move should redirect to /collection/${id}/move", () => {
+ cy.log("/collection/entity/${entity_id}/move");
cy.visit(`/collection/entity/${FIRST_COLLECTION_ENTITY_ID}/move`);
cy.url().should("contain", `/collection/${FIRST_COLLECTION_ID}/move`);
@@ -1693,23 +1748,6 @@ function ensureCollectionIsExpanded(collection, { children = [] } = {}) {
}
}
-function moveItemToCollection(itemName, collectionName) {
- cy.request("GET", "/api/collection/root/items").then((resp) => {
- const ALL_ITEMS = resp.body.data;
-
- const { id, model } = getCollectionItem(ALL_ITEMS, itemName);
- const { id: collection_id } = getCollectionItem(ALL_ITEMS, collectionName);
-
- cy.request("PUT", `/api/${model}/${id}`, {
- collection_id,
- });
- });
-
- function getCollectionItem(collection, itemName) {
- return collection.find((item) => item.name === itemName);
- }
-}
-
// the button element that gets attributes is 2 levels up from the text
function findPickerItem(name) {
return cy.findByText(name).closest("a");
diff --git a/e2e/test/scenarios/collections/helpers/e2e-collections-sidebar.js b/e2e/test/scenarios/collections/helpers/e2e-collections-sidebar.js
deleted file mode 100644
index 507bffd2564..00000000000
--- a/e2e/test/scenarios/collections/helpers/e2e-collections-sidebar.js
+++ /dev/null
@@ -1,7 +0,0 @@
-export function displaySidebarChildOf(collectionName) {
- cy.findByText(collectionName)
- .parentsUntil("[data-testid=sidebar-collection-link-root]")
- .find(".Icon-chevronright")
- .eq(0) // there may be more nested icons, but we need the top level one
- .click();
-}
diff --git a/e2e/test/scenarios/collections/instance-analytics.cy.spec.js b/e2e/test/scenarios/collections/instance-analytics.cy.spec.js
index d2e2e510fec..82ae80f0e57 100644
--- a/e2e/test/scenarios/collections/instance-analytics.cy.spec.js
+++ b/e2e/test/scenarios/collections/instance-analytics.cy.spec.js
@@ -7,9 +7,8 @@ import {
const ANALYTICS_COLLECTION_NAME = "Usage analytics";
const CUSTOM_REPORTS_COLLECTION_NAME = "Custom reports";
const PEOPLE_MODEL_NAME = "People";
-const METRICS_DASHBOARD_NAME = "Metabase metrics";
-describe("scenarios > Metabase Analytics Collection (AuditV2) ", () => {
+describe("scenarios > Metabase Analytics Collection (AuditV2)", () => {
describe("admin", () => {
beforeEach(() => {
cy.intercept("GET", "/api/field/*/values").as("fieldValues");
@@ -23,7 +22,6 @@ describe("scenarios > Metabase Analytics Collection (AuditV2) ", () => {
});
it("should not show the sidebar preview when working with instance analyics (metabase#49904)", () => {
- cy.signInAsAdmin();
H.visitQuestion(ORDERS_QUESTION_ID);
cy.findByRole("button", { name: /Editor/ }).click();
cy.findByLabelText("View SQL").click();
@@ -58,7 +56,7 @@ describe("scenarios > Metabase Analytics Collection (AuditV2) ", () => {
});
it(
- "should default to saving audit content in custom reports collection",
+ "should default to saving audit content in custom reports collection and not allow editing or leaking analytics content (metabase#36228, metabase#44856)",
{ requestTimeout: 15000 },
() => {
cy.log("saving edited question");
@@ -79,7 +77,7 @@ describe("scenarios > Metabase Analytics Collection (AuditV2) ", () => {
cy.findByTestId("qb-header").findByText("Save").click();
- cy.findByTestId("save-question-modal").within((modal) => {
+ cy.findByTestId("save-question-modal").within(() => {
cy.findByTestId("dashboard-and-collection-picker-button").findByText(
"Custom reports",
);
@@ -98,7 +96,12 @@ describe("scenarios > Metabase Analytics Collection (AuditV2) ", () => {
cy.findByTestId("qb-header").icon("ellipsis").click();
- H.popover().findByText("Duplicate").click();
+ cy.log("Analytics models can't be edited (metabase#36228)");
+ H.popover().within(() => {
+ cy.findByText("Duplicate").should("be.visible");
+ cy.findByText("Edit query definition").should("not.exist");
+ cy.findByText("Duplicate").click();
+ });
H.modal().within(() => {
cy.findByTextEnsureVisible("Custom reports");
@@ -113,13 +116,49 @@ describe("scenarios > Metabase Analytics Collection (AuditV2) ", () => {
.button(/Duplicate/i)
.should("not.exist");
+ cy.log(
+ "Instance analytics database doesn't leak into the SQL query builder (metabase#44856)",
+ );
+ H.newButton("SQL query").click();
+ cy.findByTestId("selected-database").should(
+ "have.text",
+ "Sample Database",
+ );
+ cy.findByTestId("gui-builder-data").should("not.exist");
+
+ cy.log(
+ "Instance analytics database doesn't leak into the permissions editor (metabase#44856)",
+ );
+ // it's important that we do this manually, as this will only reproduce if theres no page load
+ H.goToAdmin();
+ cy.findByLabelText("Navigation bar").findByText("Permissions").click();
+ H.sidebar().findByText("Administrators").click();
+ cy.findByTestId("permission-table")
+ .findByText("Sample Database")
+ .should("be.visible");
+ cy.findByTestId("permission-table")
+ .findByText(/internal metabase database/i)
+ .should("not.exist");
+
+ H.sidebar().findByText("Databases").click();
+
+ H.sidebar().findByText("Sample Database").should("be.visible");
+ H.sidebar()
+ .findByText(/internal metabase database/i)
+ .should("not.exist");
+
cy.log("saving copied dashboard");
getItemId(ANALYTICS_COLLECTION_NAME, "Person overview").then((id) => {
H.visitDashboard(id);
});
- cy.findByTestId("dashboard-header").findByText("Make a copy").click();
+ cy.log("Analytics dashboards can't be edited (metabase#36228)");
+ cy.findByTestId("dashboard-header").within(() => {
+ cy.findByText("Make a copy").should("be.visible");
+ cy.icon("pencil").should("not.exist");
+ cy.findByText("Make a copy").click();
+ });
H.modal().within(() => {
cy.findByTextEnsureVisible("Custom reports");
@@ -138,10 +177,11 @@ describe("scenarios > Metabase Analytics Collection (AuditV2) ", () => {
);
visitCollection(CUSTOM_REPORTS_COLLECTION_NAME);
- cy.findByTestId("collection-menu").within(() => {
- cy.icon("ellipsis").click();
- cy.contains("Move to trash").should("not.exist");
- cy.contains("Move").should("not.exist");
+ H.openCollectionMenu();
+ H.popover().within(() => {
+ cy.findByText("Edit permissions").should("be.visible");
+ cy.findByText("Move to trash").should("not.exist");
+ cy.findByText("Move").should("not.exist");
});
visitCollection(ANALYTICS_COLLECTION_NAME);
@@ -166,7 +206,10 @@ describe("scenarios > Metabase Analytics Collection (AuditV2) ", () => {
);
visitCollection(ANALYTICS_COLLECTION_NAME);
- cy.findByTestId("collection-menu").icon("ellipsis").should("not.exist");
+ H.getCollectionActions()
+ .findByLabelText("Edit permissions")
+ .should("be.visible");
+ H.getCollectionActions().icon("ellipsis").should("not.exist");
visitCollection("Our analytics");
@@ -186,78 +229,6 @@ describe("scenarios > Metabase Analytics Collection (AuditV2) ", () => {
});
});
- it("should not allow editing analytics content (metabase#36228)", () => {
- // dashboard
- getItemId(ANALYTICS_COLLECTION_NAME, METRICS_DASHBOARD_NAME).then(
- (id) => {
- H.visitDashboard(id);
- },
- );
-
- cy.findByTestId("dashboard-header").within(() => {
- cy.findByText("Make a copy");
- cy.icon("pencil").should("not.exist");
- });
-
- // model
- getItemId(ANALYTICS_COLLECTION_NAME, PEOPLE_MODEL_NAME).then((id) => {
- H.visitModel(id);
- });
-
- cy.findByTestId("qb-header").icon("ellipsis").click();
-
- H.popover().within(() => {
- cy.findByText("Duplicate").should("be.visible");
- cy.findByText("Edit query definition").should("not.exist");
- });
- });
-
- it("should not leak instance analytics database into SQL query builder (metabase#44856)", () => {
- getItemId(ANALYTICS_COLLECTION_NAME, PEOPLE_MODEL_NAME).then((id) => {
- H.visitModel(id);
- });
-
- H.newButton("SQL query").click();
-
- // sample DB should be the only one
- cy.findByTestId("gui-builder-data")
- .icon("cheverondown")
- .should("not.exist");
- });
-
- it("should not leak instance analytics database into permissions editor (metabase#44856)", () => {
- getItemId(ANALYTICS_COLLECTION_NAME, PEOPLE_MODEL_NAME).then((id) => {
- H.visitModel(id);
- });
-
- // it's important that we do this manually, as this will only reproduce if theres no page load
- H.goToAdmin();
- cy.findByLabelText("Navigation bar").findByText("Permissions").click();
- H.sidebar().findByText("Administrators").click();
- cy.findByTestId("permission-table")
- .findByText(/internal metabase database/i)
- .should("not.exist");
-
- H.sidebar().findByText("Databases").click();
-
- H.sidebar()
- .findByText(/internal metabase database/i)
- .should("not.exist");
- });
- });
-
- describe("API tests", () => {
- beforeEach(() => {
- cy.intercept("GET", "/api/field/*/values").as("fieldValues");
- cy.intercept("POST", "/api/dataset").as("datasetQuery");
- cy.intercept("POST", "api/card").as("saveCard");
- cy.intercept("POST", "api/dashboard/*/copy").as("copyDashboard");
-
- H.restore();
- cy.signInAsAdmin();
- H.activateToken("pro-self-hosted");
- });
-
it("should not allow editing analytics content (metabase#36228)", () => {
// get the analytics collection
cy.request("GET", "/api/collection/root/items").then(({ body }) => {
@@ -306,7 +277,7 @@ describe("question and dashboard links", () => {
H.activateToken("pro-self-hosted");
});
- it("should show an analytics link for questions", () => {
+ it("should show an analytics link for questions and dashboards", () => {
H.visitQuestion(ORDERS_QUESTION_ID);
cy.intercept("GET", "/api/collection/**").as("collection");
@@ -334,9 +305,7 @@ describe("question and dashboard links", () => {
cy.findByText("Entity Type");
cy.findByText("question");
});
- });
- it("should show an analytics link for dashboards", () => {
H.visitDashboard(ORDERS_DASHBOARD_ID);
cy.intercept("GET", "/api/collection/**").as("collection");
@@ -369,14 +338,16 @@ describe("question and dashboard links", () => {
cy.signInAsNormalUser();
H.visitQuestion(ORDERS_QUESTION_ID);
- H.openQuestionInfoSidesheet()
- .findByRole("link", { name: /Insights/i })
- .should("not.exist");
+ H.openQuestionInfoSidesheet().within(() => {
+ cy.findByRole("tab", { name: "Overview" }).should("be.visible");
+ cy.findByRole("link", { name: /Insights/i }).should("not.exist");
+ });
H.visitDashboard(ORDERS_DASHBOARD_ID);
- H.openDashboardInfoSidebar()
- .findByRole("link", { name: /Insights/i })
- .should("not.exist");
+ H.openDashboardInfoSidebar().within(() => {
+ cy.findByRole("tab", { name: "Overview" }).should("be.visible");
+ cy.findByRole("link", { name: /Insights/i }).should("not.exist");
+ });
});
});
@@ -389,15 +360,17 @@ describe("question and dashboard links", () => {
it("should never appear in OSS", () => {
H.visitQuestion(ORDERS_QUESTION_ID);
- H.openQuestionInfoSidesheet()
- .findByRole("link", { name: /Insights/i })
- .should("not.exist");
+ H.openQuestionInfoSidesheet().within(() => {
+ cy.findByRole("tab", { name: "Overview" }).should("be.visible");
+ cy.findByRole("link", { name: /Insights/i }).should("not.exist");
+ });
H.visitDashboard(ORDERS_DASHBOARD_ID);
- H.openDashboardInfoSidebar()
- .findByRole("link", { name: /Insights/i })
- .should("not.exist");
+ H.openDashboardInfoSidebar().within(() => {
+ cy.findByRole("tab", { name: "Overview" }).should("be.visible");
+ cy.findByRole("link", { name: /Insights/i }).should("not.exist");
+ });
});
});
});
diff --git a/e2e/test/scenarios/collections/permissions.cy.spec.js b/e2e/test/scenarios/collections/permissions.cy.spec.js
index dd5219ff940..c9e7668ec9f 100644
--- a/e2e/test/scenarios/collections/permissions.cy.spec.js
+++ b/e2e/test/scenarios/collections/permissions.cy.spec.js
@@ -3,17 +3,13 @@ import { USERS } from "e2e/support/cypress_data";
import { FIRST_COLLECTION_ID } from "e2e/support/cypress_sample_instance_data.js";
import { onlyOn } from "e2e/support/helpers/e2e-skip-test-helpers";
-import { displaySidebarChildOf } from "./helpers/e2e-collections-sidebar.js";
-
const PERMISSIONS = {
curate: ["admin", "normal", "nodata"],
view: ["readonly"],
- no: ["nocollection", "nosql", "none"],
};
describe("collection permissions", () => {
beforeEach(() => {
- cy.intercept("GET", "/api/search*").as("search");
H.restore();
});
@@ -28,20 +24,22 @@ describe("collection permissions", () => {
});
describe("create dashboard", () => {
- it("should offer to save dashboard to a currently opened collection", () => {
- cy.visit("/collection/root");
- H.navigationSidebar().within(() => {
- displaySidebarChildOf("First collection");
- cy.findByText("Second collection").click();
- });
- H.appBar().within(() => {
- cy.icon("add").click();
+ onlyOn(user !== "nodata", () => {
+ it("should offer to save dashboard to a currently opened collection", () => {
+ cy.visit("/collection/root");
+ H.displaySidebarChildOf("First collection");
+ H.navigationSidebar()
+ .findByText("Second collection")
+ .click();
+ H.appBar().within(() => {
+ cy.icon("add").click();
+ });
+ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
+ cy.findByText("Dashboard").click();
+ cy.findByLabelText(/Which collection/).findByText(
+ "Second collection",
+ );
});
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText("Dashboard").click();
- cy.findByLabelText(/Which collection/).findByText(
- "Second collection",
- );
});
onlyOn(user === "admin", () => {
@@ -60,8 +58,52 @@ describe("collection permissions", () => {
});
});
- describe("pin", () => {
- it("pinning should work properly for both questions and dashboards", () => {
+ it(`should move, duplicate${user === "admin" ? " and archive" : ", archive and pin"} questions and dashboards (metabase#15256, metabase#15253, metabase#15080, metabase#16617)`, () => {
+ cy.log("Move and undo moving a question and a dashboard");
+ move("Orders");
+ move("Orders in a dashboard");
+
+ cy.log(
+ "Duplicate the dashboard without obstructions from the modal (metabase#15256)",
+ );
+ duplicate("Orders in a dashboard");
+
+ cy.log("Archive and unarchive items");
+ archiveUnarchive("Orders", "question");
+ archiveUnarchive("Orders in a dashboard", "dashboard");
+
+ if (user !== "nodata") {
+ H.createNativeQuestion({
+ name: "Model",
+ type: "model",
+ native: {
+ query: "SELECT 1",
+ },
+ });
+ archiveUnarchive("Model", "model");
+ }
+
+ cy.log(
+ "Trashed items show up in the trash (metabase#15080, metabase#16617)",
+ );
+ cy.visit("collection/root");
+ H.openCollectionItemMenu("Orders");
+ H.popover().within(() => {
+ cy.findByText("Move to trash").click();
+ });
+ cy.findByTestId("toast-undo").within(() => {
+ cy.findByText("Trashed question");
+ cy.icon("close").click();
+ });
+ H.navigationSidebar().within(() => {
+ cy.findByText("Trash").click();
+ });
+ cy.location("pathname").should("eq", "/trash");
+ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
+ cy.findByText("Orders");
+
+ if (user !== "admin") {
+ cy.log("Pin a question and a dashboard");
cy.visit("/collection/root");
// Assert that we're starting from a scenario with no pins
cy.findByTestId("pinned-items").should("not.exist");
@@ -81,209 +123,140 @@ describe("collection permissions", () => {
cy.findByText("Orders in a dashboard");
cy.findByText("Orders, Count");
});
- });
- });
-
- describe("move", () => {
- it("should let a user move/undo move a question", () => {
- move("Orders");
- });
-
- it("should let a user move/undo move a dashboard", () => {
- move("Orders in a dashboard");
- });
- });
-
- describe("duplicate", () => {
- it("should be able to duplicate the dashboard without obstructions from the modal (metabase#15256)", () => {
- duplicate("Orders in a dashboard");
- });
+ }
});
describe("archive", () => {
- it("should be able to archive/unarchive question (metabase#15253)", () => {
- archiveUnarchive("Orders", "question");
- });
-
- it("should be able to archive/unarchive dashboard", () => {
- archiveUnarchive("Orders in a dashboard", "dashboard");
- });
-
- it("should be able to archive/unarchive model", () => {
- cy.skipOn(user === "nodata");
- H.createNativeQuestion({
- name: "Model",
- type: "model",
- native: {
- query: "SELECT 1",
- },
- });
- archiveUnarchive("Model", "model");
- });
-
- describe("archive page", () => {
- it("should show archived items (metabase#15080, metabase#16617)", () => {
- cy.visit("collection/root");
- H.openCollectionItemMenu("Orders");
- H.popover().within(() => {
- cy.findByText("Move to trash").click();
- });
- cy.findByTestId("toast-undo").within(() => {
- cy.findByText("Trashed question");
- cy.icon("close").click();
- });
- H.navigationSidebar().within(() => {
- cy.findByText("Trash").click();
- });
- cy.location("pathname").should("eq", "/trash");
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText("Orders");
- });
- });
-
- describe("collections", () => {
- it("shouldn't be able to archive/edit root or personal collection", () => {
- cy.visit("/collection/root");
- cy.icon("edit").should("not.exist");
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText("Your personal collection").click();
- cy.icon("edit").should("not.exist");
- });
-
- it("archiving sub-collection should redirect to its parent", () => {
- cy.request("GET", "/api/collection").then((xhr) => {
- // We need to obtain the ID programatically
- const { id: THIRD_COLLECTION_ID } = xhr.body.find(
- (collection) => collection.slug === "third_collection",
- );
-
- cy.intercept(
- "PUT",
- `/api/collection/${THIRD_COLLECTION_ID}`,
- ).as("editCollection");
-
- cy.visit(`/collection/${THIRD_COLLECTION_ID}`);
- });
-
- H.openCollectionMenu();
- H.popover().within(() =>
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- linter erroring for no reason
- cy.findByText("Move to trash").click(),
- );
- H.modal().findByText("Move to trash").click();
-
- cy.wait("@editCollection");
-
- cy.findByTestId("archive-banner").should("exist");
-
- H.navigationSidebar().within(() => {
- cy.findByText("First collection");
- cy.findByText("Second collection");
- cy.findByText("Third collection").should("not.exist");
- });
-
- // While we're here, we can test unarchiving the collection as well
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText("Trashed collection");
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText("Undo").click();
-
- cy.wait("@editCollection");
-
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText(
- "Sorry, you don’t have permission to see that.",
- ).should("not.exist");
- cy.findByTestId("archive-banner").should("not.exist");
-
- // But unarchived collection is now visible in the sidebar
- H.navigationSidebar().within(() => {
- cy.findByText("Third collection");
- });
- });
-
- it("visiting already archived collection by its ID shouldn't let you edit it (metabase#12489)", () => {
- cy.request("GET", "/api/collection").then((xhr) => {
- const { id: THIRD_COLLECTION_ID } = xhr.body.find(
- (collection) => collection.slug === "third_collection",
+ onlyOn(user !== "nodata", () => {
+ describe("collections", () => {
+ it("shouldn't be able to archive/edit root or personal collection", () => {
+ const { first_name, last_name } = USERS[user];
+
+ cy.visit("/collection/root");
+ cy.findByTestId("collection-name-heading").should(
+ "contain",
+ "Our analytics",
);
- // Archive it
- cy.request(
- "PUT",
- `/api/collection/${THIRD_COLLECTION_ID}`,
- {
- archived: true,
- },
+ if (user === "admin") {
+ H.openCollectionMenu();
+ H.popover().within(() => {
+ cy.findByText("Edit permissions").should(
+ "be.visible",
+ );
+ cy.findByText("Move").should("not.exist");
+ cy.findByText("Move to trash").should("not.exist");
+ });
+ } else {
+ H.getCollectionActions()
+ .findByLabelText("More info")
+ .should("be.visible");
+ H.getCollectionActions()
+ .icon("ellipsis")
+ .should("not.exist");
+ }
+
+ H.navigationSidebar()
+ .findByText("Your personal collection")
+ .click();
+ cy.findByTestId("collection-name-heading").should(
+ "contain",
+ `${first_name} ${last_name}'s Personal Collection`,
);
-
- // What happens if we visit the archived collection by its id?
- // This is the equivalent of hitting the back button but it also shows that the same UI is present whenever we visit the collection by its id
- cy.visit(`/collection/${THIRD_COLLECTION_ID}`);
+ H.getCollectionActions()
+ .findByLabelText("More info")
+ .should("be.visible");
+ H.getCollectionActions()
+ .icon("ellipsis")
+ .should("not.exist");
});
- cy.findByTestId("collection-name-heading")
- .as("title")
- .contains("Third collection");
- // Creating new sub-collection at this point shouldn't be possible
- // We shouldn't be able to change permissions for an archived collection (the root issue of #12489!)
- cy.findByTestId("collection-menu").should("not.exist");
-
- /**
- * We can take 2 routes from here - it will really depend on the design decision:
- * 1. Edit icon shouldn't exist at all in which case some other call to drill-through menu/button should exist
- * notifying the user that this collection is archived and prompting them to unarchive it
- * 2. Edit icon stays but with "Unarchive this item" ONLY in the menu
- */
-
- // Option 1
- cy.icon("edit").should("not.exist");
-
- // Option 2
- // cy.icon("edit").click();
- // popover().within(() => {
- // cy.findByText("Edit this collection").should("not.exist");
- // cy.findByText("Archive this collection").should(
- // "not.exist",
- // );
- // cy.findByText("Unarchive this collection");
- // });
- });
- it("abandoning archive process should keep you in the same collection (metabase#15289)", () => {
- cy.request("GET", "/api/collection").then((xhr) => {
- const { id: THIRD_COLLECTION_ID } = xhr.body.find(
- (collection) => collection.slug === "third_collection",
+ it("should cancel, trash, and undo trashing a sub-collection, and not allow editing it once archived (metabase#15289, metabase#12489)", () => {
+ cy.request("GET", "/api/collection").then((xhr) => {
+ // We need to obtain the ID programatically
+ const { id: THIRD_COLLECTION_ID } = xhr.body.find(
+ (collection) =>
+ collection.slug === "third_collection",
+ );
+
+ cy.intercept(
+ "PUT",
+ `/api/collection/${THIRD_COLLECTION_ID}`,
+ ).as("editCollection");
+
+ cy.visit(`/collection/${THIRD_COLLECTION_ID}`);
+
+ cy.log(
+ "Abandoning the trash process keeps you in the same collection (metabase#15289)",
+ );
+ H.openCollectionMenu();
+ H.popover().within(() =>
+ cy.findByText("Move to trash").click(),
+ );
+ H.modal().findByText("Cancel").click();
+ H.modal().should("not.exist");
+ cy.location("pathname").should(
+ "eq",
+ `/collection/${THIRD_COLLECTION_ID}-third-collection`,
+ );
+ cy.findByTestId("collection-name-heading").contains(
+ "Third collection",
+ );
+
+ H.openCollectionMenu();
+ H.popover().within(() =>
+ cy.findByText("Move to trash").click(),
+ );
+ H.modal().findByText("Move to trash").click();
+
+ cy.wait("@editCollection");
+
+ cy.findByTestId("archive-banner").should("exist");
+
+ H.navigationSidebar().within(() => {
+ cy.findByText("First collection");
+ cy.findByText("Second collection");
+ cy.findByText("Third collection").should("not.exist");
+ });
+
+ // While we're here, we can test unarchiving the collection as well
+
+ cy.findByText("Trashed collection");
+
+ cy.findByText("Undo").click();
+
+ cy.wait("@editCollection");
+
+ cy.findByText(
+ "Sorry, you don’t have permission to see that.",
+ ).should("not.exist");
+ cy.findByTestId("archive-banner").should("not.exist");
+
+ // But unarchived collection is now visible in the sidebar
+ H.navigationSidebar().within(() => {
+ cy.findByText("Third collection");
+ });
+
+ cy.log(
+ "Visiting an archived collection by its ID shouldn't let you edit it (metabase#12489)",
+ );
+ cy.request(
+ "PUT",
+ `/api/collection/${THIRD_COLLECTION_ID}`,
+ {
+ archived: true,
+ },
+ );
+ cy.visit(`/collection/${THIRD_COLLECTION_ID}`);
+ });
+ cy.findByTestId("collection-name-heading").contains(
+ "Third collection",
);
- cy.visit(`/collection/${THIRD_COLLECTION_ID}`);
- H.openCollectionMenu();
- H.popover().within(() =>
- cy.findByText("Move to trash").click(),
- );
- H.modal().findByText("Cancel").click();
- cy.location("pathname").should(
- "eq",
- `/collection/${THIRD_COLLECTION_ID}-third-collection`,
- );
- cy.findByTestId("collection-name-heading")
- .as("title")
- .contains("Third collection");
+ cy.findByTestId("archive-banner").should("be.visible");
+ // We shouldn't be able to change permissions for an archived collection
+ cy.findByTestId("collection-menu").should("not.exist");
});
});
});
-
- function archiveUnarchive(item, expectedEntityName) {
- cy.visit("/collection/root");
- H.openCollectionItemMenu(item);
- H.popover().within(() => {
- cy.findByText("Move to trash").click();
- });
- cy.findByText(item).should("not.exist");
- cy.findByText(`Trashed ${expectedEntityName}`);
- cy.findByText("Undo").click();
- cy.findByText(
- "Sorry, you don’t have permission to see that.",
- ).should("not.exist");
- cy.findByText(item);
- }
});
});
});
@@ -293,28 +266,11 @@ describe("collection permissions", () => {
cy.signIn(user);
});
- it("should not show pins or a helper text (metabase#20043)", () => {
- cy.visit("/collection/root");
-
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText("Orders in a dashboard");
- cy.icon("pin").should("not.exist");
- });
-
- it("should be offered to duplicate dashboard in collections they have `read` access to", () => {
+ it("should not offer bulk actions or pins, but should offer to duplicate dashboard in collections they have `read` access to (metabase#16490, metabase#20043)", () => {
const { first_name, last_name } = USERS[user];
cy.visit("/collection/root");
- H.openCollectionItemMenu("Orders in a dashboard");
- H.popover().findByText("Duplicate").click();
- cy.findByTestId("collection-picker-button").should(
- "have.text",
- `${first_name} ${last_name}'s Personal Collection`,
- );
- });
-
- it("should not be able to use bulk actions on collection items (metabase#16490)", () => {
- cy.visit("/collection/root");
+ cy.log("No bulk actions on collection items (metabase#16490)");
// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
cy.findByText("Orders")
.closest("tr")
@@ -330,11 +286,24 @@ describe("collection permissions", () => {
cy.icon("dashboard").trigger("mouseover");
cy.findByRole("checkbox").should("not.exist");
});
+
+ cy.log("No option to pin items (metabase#20043)");
+ H.openCollectionItemMenu("Orders in a dashboard");
+ H.popover().within(() => {
+ cy.findByText("Duplicate").should("be.visible");
+ cy.findByText("Pin this").should("not.exist");
+ cy.findByText("Duplicate").click();
+ });
+ cy.findByTestId("collection-picker-button").should(
+ "have.text",
+ `${first_name} ${last_name}'s Personal Collection`,
+ );
});
["/", "/collection/root"].forEach((route) => {
- it("should not be offered to save dashboard in collections they have `read` access to (metabase#15281)", () => {
+ it(`should not be offered to save dashboard in collections they have \`read\` access to from ${route} (metabase#15281)`, () => {
const { first_name, last_name } = USERS[user];
+ cy.intercept("GET", "/api/search*").as("search");
cy.visit(route);
cy.icon("add").click();
// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
@@ -352,10 +321,11 @@ describe("collection permissions", () => {
// Test will fail on this step first
cy.findByText("First collection").should("not.exist");
// This is the second step that makes sure not even search returns collections with read-only access
- cy.findByPlaceholderText("Search…").type("third{Enter}");
+ // Enter would confirm the selected collection and close the picker
+ cy.findByPlaceholderText("Search…").type("third");
cy.wait("@search");
- cy.findByText(/Loading/i).should("not.exist");
+ cy.findByText("We didn't find anything").should("be.visible");
cy.findByText("Third collection").should("not.exist");
});
});
@@ -445,15 +415,6 @@ function pinItem(item) {
H.popover().icon("pin").click();
}
-function exposeChildrenFor(collectionName) {
- H.navigationSidebar()
- .findByText(collectionName)
- .parentsUntil("[data-testid=sidebar-collection-link-root]")
- .find(".Icon-chevronright")
- .eq(0) // there may be more nested icons, but we need the top level one
- .click();
-}
-
function move(item) {
cy.visit("/collection/root");
H.openCollectionItemMenu(item);
@@ -468,7 +429,7 @@ function move(item) {
cy.findByText(item).should("not.exist");
// Make sure item was properly moved to a correct sub-collection
- exposeChildrenFor("First collection");
+ H.displaySidebarChildOf("First collection");
cy.findByText("Second collection").click();
cy.findByText(item);
// Undo the whole thing
@@ -480,6 +441,7 @@ function move(item) {
}
function duplicate(item) {
+ cy.intercept("POST", "/api/dashboard/*/copy").as("copyDashboard");
cy.visit("/collection/root");
H.openCollectionItemMenu(item);
cy.findByText("Duplicate").click();
@@ -487,8 +449,24 @@ function duplicate(item) {
.as("modal")
.within(() => {
clickButton("Duplicate");
+ cy.wait("@copyDashboard");
cy.findByText("Failed").should("not.exist");
});
cy.get("@modal").should("not.exist");
cy.findByText(`${item} - Duplicate`);
}
+
+function archiveUnarchive(item, expectedEntityName) {
+ cy.visit("/collection/root");
+ H.openCollectionItemMenu(item);
+ H.popover().within(() => {
+ cy.findByText("Move to trash").click();
+ });
+ cy.findByText(item).should("not.exist");
+ cy.findByText(`Trashed ${expectedEntityName}`);
+ cy.findByText("Undo").click();
+ cy.findByText("Sorry, you don’t have permission to see that.").should(
+ "not.exist",
+ );
+ cy.findByText(item);
+}
diff --git a/e2e/test/scenarios/collections/personal-collections.cy.spec.js b/e2e/test/scenarios/collections/personal-collections.cy.spec.js
index 255dff6dbf0..2589f7bdbb3 100644
--- a/e2e/test/scenarios/collections/personal-collections.cy.spec.js
+++ b/e2e/test/scenarios/collections/personal-collections.cy.spec.js
@@ -27,6 +27,9 @@ describe("personal collections", () => {
cy.visit("/");
cy.wait("@getSessionProperties");
+ H.navigationSidebar()
+ .findByText("Your personal collection")
+ .should("be.visible");
H.navigationSidebar()
.findByLabelText("Other users' personal collections")
.should("not.exist");
@@ -67,12 +70,16 @@ describe("personal collections", () => {
});
});
- it("cannot edit details for personal collections nor change permissions for personal collections or sub-collections (metabase#8406)", () => {
+ it("cannot edit details for personal collections nor change permissions for personal collections or sub-collections, but can view other users' personal sub-collections (metabase#8406, metabase#15339)", () => {
// Let's use the API to create a sub-collection "Foo" in admin's personal collection
cy.request("POST", "/api/collection", {
name: "Foo",
parent_id: ADMIN_PERSONAL_COLLECTION_ID,
});
+ H.createCollection({
+ name: "Nodata sub-collection",
+ parent_id: NO_DATA_PERSONAL_COLLECTION_ID,
+ });
H.visitCollection(ADMIN_PERSONAL_COLLECTION_ID);
@@ -84,16 +91,6 @@ describe("personal collections", () => {
cy.icon("ellipsis").should("not.exist");
});
- // This leads to an infinite loop and a timeout in the CI
- // Please see: https://github.com/metabase/metabase/issues/21026#issuecomment-1094114700
-
- // Check that it's not possible to open permissions modal via URL for personal collection
- // cy.location().then(location => {
- // cy.visit(`${location}/permissions`);
- // modal().should("not.exist");
- // cy.url().should("eq", String(location));
- // });
-
// Go to the newly created sub-collection "Foo"
H.navigationSidebar().findByText("Foo").click();
cy.findByDisplayValue("Foo").should("be.enabled");
@@ -107,13 +104,6 @@ describe("personal collections", () => {
cy.findByText("Edit permissions").should("not.exist");
});
- // Check that it's not possible to open permissions modal via URL for personal collection child
- // cy.location().then(location => {
- // cy.visit(`${location}/permissions`);
- // modal().should("not.exist");
- // cy.url().should("eq", String(location));
- // });
-
// Go to random user's personal collection
H.visitCollection(NO_DATA_PERSONAL_COLLECTION_ID);
@@ -121,22 +111,20 @@ describe("personal collections", () => {
cy.icon("info").should("exist");
cy.icon("ellipsis").should("not.exist");
});
- });
-
- it("should be able view other users' personal sub-collections (metabase#15339)", () => {
- H.createCollection({
- name: "Foo",
- parent_id: NO_DATA_PERSONAL_COLLECTION_ID,
- });
- cy.visit(`/collection/${NO_DATA_PERSONAL_COLLECTION_ID}`);
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText("Foo");
+ cy.log(
+ "Other users' personal sub-collections are visible (metabase#15339)",
+ );
+ cy.findByTestId("collection-table")
+ .findByText("Nodata sub-collection")
+ .should("be.visible");
});
});
- describe("all users", () => {
- Object.keys(USERS).forEach((user) => {
+ describe("admin and non-admin users", () => {
+ // The test acts only inside the user's own personal collection, where group
+ // collection permissions don't apply; nocollection has the most restricted UI
+ ["admin", "nocollection"].forEach((user) => {
describe(`${user} user`, () => {
beforeEach(() => {
cy.signIn(user);
@@ -149,12 +137,28 @@ describe("personal collections", () => {
H.navigationSidebar().as("sidebar").findByText("Foo").click();
});
- it("should be able to edit collection(s) inside personal collection", () => {
+ it("should be able to edit and trash collection(s) inside personal collection (metabase#15343)", () => {
+ cy.intercept("PUT", "/api/collection/*").as("updateCollection");
+
// Create new collection inside previously added collection
addNewCollection("Bar");
cy.get("@sidebar").findByText("Bar").click();
cy.findByPlaceholderText("Add title").type("1").blur();
+ cy.wait("@updateCollection")
+ .its("response.statusCode")
+ .should("eq", 200);
cy.findByPlaceholderText("Add description").type("ex-bar").blur();
+ cy.wait("@updateCollection")
+ .its("response.statusCode")
+ .should("eq", 200);
+
+ cy.findByTestId("collection-name-heading").should(
+ "have.value",
+ "Bar1",
+ );
+ cy.findByTestId("collection-caption")
+ .findByText("ex-bar")
+ .should("be.visible");
cy.get("@sidebar").findByText("Foo").click();
cy.get("@sidebar").findByText("Bar1");
diff --git a/e2e/test/scenarios/collections/revision-history.cy.spec.js b/e2e/test/scenarios/collections/revision-history.cy.spec.js
index f10b6651602..8a4774ac23b 100644
--- a/e2e/test/scenarios/collections/revision-history.cy.spec.js
+++ b/e2e/test/scenarios/collections/revision-history.cy.spec.js
@@ -8,7 +8,6 @@ import { onlyOn } from "e2e/support/helpers/e2e-skip-test-helpers";
const PERMISSIONS = {
curate: ["admin", "normal", "nodata"],
view: ["readonly"],
- no: ["nocollection", "nosql", "none"],
};
describe("revision history", () => {
@@ -36,10 +35,12 @@ describe("revision history", () => {
openRevisionHistory();
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText(/created this/);
-
- cy.findAllByText("Revert").should("not.exist");
+ H.sidesheet().within(() => {
+ cy.findAllByTestId("revision-history-event")
+ .should("have.length", 1)
+ .and("contain.text", "created this");
+ cy.findByTestId("question-revert-button").should("not.exist");
+ });
});
});
@@ -85,9 +86,11 @@ describe("revision history", () => {
openRevisionHistory();
H.sidesheet().within(() => {
cy.findByRole("tab", { name: "History" }).click();
- cy.findByText(/added a card/)
- .siblings("button")
- .should("not.exist");
+ cy.findAllByTestId("revision-history-event").should(
+ "have.length",
+ 2,
+ );
+ cy.findByText(/added a card/).should("be.visible");
cy.findByText(/rearranged the cards/).should("not.exist");
});
});
@@ -122,44 +125,41 @@ describe("revision history", () => {
cy.findByTestId("visualization-root").should("contain", "117.03");
});
- it("should be able to access the question's revision history via the revision history button in the header of the query builder", () => {
+ it("should be able to access the question's revision history via the header button and the info sidesheet, and revert the question", () => {
cy.skipOn(user === "nodata");
H.visitQuestion(ORDERS_QUESTION_ID);
+ cy.findByTestId("saved-question-header-title").should(
+ "have.value",
+ "Orders renamed",
+ );
+ cy.log("open revision history via the header button");
cy.findByTestId("revision-history-button").click();
- cy.findByRole("tab", { name: "History" }).click();
-
- cy.findByTestId("question-revert-button").click();
-
- cy.wait("@revert").then(({ response: { statusCode, body } }) => {
- expect(statusCode).to.eq(200);
- expect(body.cause).not.to.exist;
+ H.sidesheet().within(() => {
+ cy.findByRole("tab", { name: "History" }).click();
+ // The revert button only becomes visible on hover
+ cy.findByTestId("question-revert-button").should("exist");
});
+ H.sidesheet().findByLabelText("Close").click();
+ H.sidesheet().should("not.exist");
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.contains(/^Orders$/);
- });
-
- it("should be able to revert the question via the action button found in the saved question timeline", () => {
- cy.skipOn(user === "nodata");
-
- H.visitQuestion(ORDERS_QUESTION_ID);
-
+ cy.log("open revision history via the question info sidesheet");
H.questionInfoButton().click();
- cy.findByRole("tab", { name: "History" }).click();
-
- // Last revert is the original state
- // eslint-disable-next-line metabase/no-unsafe-element-filtering
- cy.findAllByTestId("question-revert-button").last().click();
+ H.sidesheet().within(() => {
+ cy.findByRole("tab", { name: "History" }).click();
+ cy.findByTestId("question-revert-button").click();
+ });
cy.wait("@revert").then(({ response: { statusCode, body } }) => {
expect(statusCode).to.eq(200);
expect(body.cause).not.to.exist;
});
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.contains(/^Orders$/);
+ cy.findByTestId("saved-question-header-title").should(
+ "have.value",
+ "Orders",
+ );
});
});
});
@@ -167,20 +167,32 @@ describe("revision history", () => {
onlyOn(permission === "view", () => {
describe(`${user} user`, () => {
it("should not see question nor dashboard revert buttons (metabase#13229)", () => {
+ cy.signInAsAdmin();
+ cy.request("PUT", `/api/card/${ORDERS_QUESTION_ID}`, {
+ name: "Orders renamed",
+ });
cy.signIn(user);
H.visitDashboard(ORDERS_DASHBOARD_ID);
openRevisionHistory();
- cy.findAllByRole("button", { name: "Revert" }).should(
- "not.exist",
- );
+ H.sidesheet().within(() => {
+ cy.findAllByTestId("revision-history-event").should(
+ "have.length.gte",
+ 2,
+ );
+ cy.findByTestId("question-revert-button").should("not.exist");
+ });
H.visitQuestion(ORDERS_QUESTION_ID);
- cy.findByRole("button", { name: /Edited .*/ }).click();
-
- cy.findAllByRole("button", { name: "Revert" }).should(
- "not.exist",
- );
+ H.questionInfoButton().click();
+ H.sidesheet().within(() => {
+ cy.findByRole("tab", { name: "History" }).click();
+ cy.findAllByTestId("revision-history-event").should(
+ "have.length.gte",
+ 2,
+ );
+ cy.findByTestId("question-revert-button").should("not.exist");
+ });
});
});
});
diff --git a/e2e/test/scenarios/collections/tenant-collections-list.cy.spec.ts b/e2e/test/scenarios/collections/tenant-collections-list.cy.spec.ts
index ae3a6865f8e..1122cf5e9cc 100644
--- a/e2e/test/scenarios/collections/tenant-collections-list.cy.spec.ts
+++ b/e2e/test/scenarios/collections/tenant-collections-list.cy.spec.ts
@@ -13,7 +13,7 @@ describe("scenarios > collections > tenant collections list", () => {
cy.request("PUT", "/api/setting", { "use-tenants": true });
});
- it("should display tenant collections", () => {
+ it("should display active tenant collections", () => {
const tenants: Tenant[] = Array.from({ length: 3 }, (_, i) => ({
name: `Tenant ${String(i + 1).padStart(2, "0")}`,
slug: `tenant-${String(i + 1).padStart(2, "0")}`,
@@ -22,17 +22,33 @@ describe("scenarios > collections > tenant collections list", () => {
cy.log("creating multiple tenants");
tenants.forEach((tenant) => cy.request("POST", "/api/ee/tenant", tenant));
+ cy.log("create tenant to be deactivated");
+ cy.request("POST", "/api/ee/tenant", {
+ name: "Deactivated Tenant",
+ slug: "deactivated-tenant",
+ }).then(({ body: tenant }) => {
+ cy.log("deactivate the tenant");
+ cy.request("PUT", `/api/ee/tenant/${tenant.id}`, { is_active: false });
+ });
+
cy.visit("/collection/tenant-specific");
- cy.log("all tenant collections are displayed");
+ cy.log("all active tenant collections are displayed");
H.main().within(() => {
tenants.forEach((tenant) => {
cy.findByText(tenant.name).should("be.visible");
});
});
+ cy.log("deactivated tenant should not be visible");
+ H.main().findByText("Deactivated Tenant").should("not.exist");
+
cy.log("all collections should be clickable links");
- cy.findAllByRole("link").should("have.length.at.least", tenants.length);
+ tenants.forEach((tenant) => {
+ H.main()
+ .findByRole("link", { name: new RegExp(tenant.name) })
+ .should("be.visible");
+ });
cy.log("can navigate to tenant collection");
H.main().findByText("Tenant 01").click();
@@ -40,29 +56,4 @@ describe("scenarios > collections > tenant collections list", () => {
cy.url().should("not.include", "/collection/tenant-specific");
H.main().findByText("Tenant collection: Tenant 01").should("be.visible");
});
-
- it("does not show deactivated tenants", () => {
- cy.log("create active tenant");
- cy.request("POST", "/api/ee/tenant", {
- name: "Active Tenant",
- slug: "active-tenant",
- });
-
- cy.log("create tenant to be deactivated");
- cy.request("POST", "/api/ee/tenant", {
- name: "Deactivated Tenant",
- slug: "deactivated-tenant",
- }).then(({ body: tenant }) => {
- cy.log("deactivate the tenant");
- cy.request("PUT", `/api/ee/tenant/${tenant.id}`, { is_active: false });
- });
-
- cy.visit("/collection/tenant-specific");
-
- cy.log("active tenant should be visible");
- H.main().findByText("Active Tenant").should("be.visible");
-
- cy.log("deactivated tenant should not be visible");
- H.main().findByText("Deactivated Tenant").should("not.exist");
- });
});
diff --git a/e2e/test/scenarios/collections/trash.cy.spec.js b/e2e/test/scenarios/collections/trash.cy.spec.js
index 9f062ea8348..58af1c98e56 100644
--- a/e2e/test/scenarios/collections/trash.cy.spec.js
+++ b/e2e/test/scenarios/collections/trash.cy.spec.js
@@ -1,6 +1,8 @@
import { P, isMatching } from "ts-pattern";
const { H } = cy;
+import { USER_GROUPS } from "e2e/support/cypress_data";
+import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
import {
FIRST_COLLECTION_ID,
ORDERS_COUNT_QUESTION_ID,
@@ -9,6 +11,9 @@ import {
READ_ONLY_PERSONAL_COLLECTION_ID,
} from "e2e/support/cypress_sample_instance_data";
+const { ORDERS_ID } = SAMPLE_DATABASE;
+const { ALL_USERS_GROUP, COLLECTION_GROUP, DATA_GROUP } = USER_GROUPS;
+
describe("scenarios > collections > trash", () => {
beforeEach(() => {
H.restore();
@@ -22,6 +27,7 @@ describe("scenarios > collections > trash", () => {
type: "model",
name: "Model A",
native: { query: "select * from products limit 5" },
+ collection_position: 1,
},
true,
);
@@ -48,7 +54,9 @@ describe("scenarios > collections > trash", () => {
cy.findByText("Deleted at");
});
- cy.log("trashed items in collection should have option to move to trash");
+ cy.log(
+ "trashed items should offer restore and permanent delete, not move to trash",
+ );
toggleEllipsisMenuFor("Collection A");
H.popover().within(() => {
cy.findByText("Move to trash").should("not.exist");
@@ -63,11 +71,13 @@ describe("scenarios > collections > trash", () => {
});
cy.log("there should not be pins in the trash");
+ collectionTable().findByText("Model A").should("be.visible");
cy.findByTestId("pinned-items").should("not.exist");
- cy.log("trash should not appear in 'our analtyics'");
+ cy.log("trash should not appear in 'our analytics'");
visitRootCollection();
collectionTable().within(() => {
+ cy.findByText("Orders").should("be.visible");
cy.findByText("Trash").should("not.exist");
});
@@ -101,6 +111,7 @@ describe("scenarios > collections > trash", () => {
cy.log("trash should not appear in collection permissions sidebar");
cy.visit("/admin/permissions/collections");
+ H.sidebar().findByText("First collection").should("be.visible");
H.sidebar().findByText("Trash").should("not.exist");
});
@@ -249,10 +260,6 @@ describe("scenarios > collections > trash", () => {
event,
),
);
- visitRootCollection();
- collectionTable().within(() => {
- cy.findByText("Dashboard A").should("not.exist");
- });
ensureCanRestoreFromPage("Dashboard A");
ensureBookmarkVisible("Dashboard A");
@@ -279,43 +286,11 @@ describe("scenarios > collections > trash", () => {
event,
),
);
- visitRootCollection();
- collectionTable().within(() => {
- cy.findByText("Question A").should("not.exist");
- });
ensureCanRestoreFromPage("Question A");
ensureBookmarkVisible("Question A");
});
});
- it("should not show restore option if entity is within nested in an archived collection list", () => {
- cy.log("create test resources");
- createCollection({ name: "Collection A" })
- .as("collectionA")
- .then((a) => createCollection({ name: "Collection B", parent_id: a.id }));
-
- cy.get("@collectionA").then((collectionA) => {
- H.archiveCollection(collectionA.id);
- });
-
- cy.log("only shows restore in root trash collection");
- cy.visit("/trash");
-
- toggleEllipsisMenuFor("Collection A");
- H.popover().findByText("Restore").should("exist");
- collectionTable().findByText("Collection A").click();
-
- toggleEllipsisMenuFor("Collection B");
- H.popover().findByText("Restore").should("not.exist");
-
- cy.log("only shows restore on entity page if in root trash collection");
- cy.visit("/trash");
- collectionTable().findByText("Collection A").click();
- archiveBanner().findByText("Restore").should("exist");
- collectionTable().findByText("Collection B").click();
- archiveBanner().findByText("Restore").should("not.exist");
- });
-
it("should be able to move <entity> out of trash collection", () => {
cy.log("create test resources");
createCollection({ name: "Collection A" }, true);
@@ -424,9 +399,60 @@ describe("scenarios > collections > trash", () => {
const query = { native: { query: "select 1;" } };
createNativeQuestion({ name: "Question A", ...query }, true);
createNativeQuestion({ name: "Question B", ...query }, true);
+ createCollection({ name: "Collection C" }).then((collectionC) => {
+ createCollection({ name: "Collection D", parent_id: collectionC.id });
+ H.archiveCollection(collectionC.id);
+ });
cy.visit("/trash");
+ cy.log("only shows restore in root trash collection");
+ toggleEllipsisMenuFor("Collection C");
+ H.popover().within(() => {
+ cy.findByText("Delete permanently").should("be.visible");
+ cy.findByText("Restore").should("be.visible");
+ });
+ collectionTable().findByText("Collection C").click();
+ archiveBanner().findByText("Restore").should("exist");
+
+ toggleEllipsisMenuFor("Collection D");
+ H.popover().within(() => {
+ cy.findByText("Delete permanently").should("be.visible");
+ cy.findByText("Restore").should("not.exist");
+ });
+ toggleEllipsisMenuFor("Collection D");
+
+ cy.log("only shows restore on entity page if in root trash collection");
+ collectionTable().findByText("Collection D").click();
+ cy.findByTestId("collection-name-heading").should(
+ "have.text",
+ "Collection D",
+ );
+ archiveBanner().within(() => {
+ cy.findByText("Delete permanently").should("be.visible");
+ cy.findByText("Restore").should("not.exist");
+ });
+
+ cy.log("can delete from a trashed collection");
+ cy.go("back");
+ cy.findByTestId("collection-name-heading").should(
+ "have.text",
+ "Collection C",
+ );
+ toggleEllipsisMenuFor("Collection D");
+ H.popover().findByText("Delete permanently").click();
+ H.modal().findByText("Delete Collection D permanently?").should("exist");
+ H.modal().findByText("Delete permanently").click();
+ cy.findByTestId("collection-empty-state").should("be.visible");
+
+ archiveBanner().findByText("Delete permanently").click();
+ H.modal().findByText("Delete Collection C permanently?").should("exist");
+ H.modal().findByText("Delete permanently").click();
+ collectionTable().within(() => {
+ cy.findByText("Collection A").should("exist");
+ cy.findByText("Collection C").should("not.exist");
+ });
+
cy.log("can delete from trash list");
toggleEllipsisMenuFor("Collection A");
H.popover()
@@ -465,7 +491,6 @@ describe("scenarios > collections > trash", () => {
collectionTable().within(() => {
cy.findByText("Collection B").click();
});
- // FUTURE: replace following two lines with commented out code when collections can be deleted
archiveBanner().findByText("Delete permanently").click();
H.modal().findByText("Delete Collection B permanently?").should("exist");
H.modal().findByText("Delete permanently").click();
@@ -503,7 +528,16 @@ describe("scenarios > collections > trash", () => {
cy.visit("/trash");
});
- it("user should be able to bulk restore", () => {
+ it("user should be able to bulk restore and bulk move out of trash", () => {
+ createCollection({ name: "Collection B" }, true);
+ createDashboard({ name: "Dashboard B" }, true);
+ createNativeQuestion(
+ { name: "Question B", native: { query: "select 1;" } },
+ true,
+ );
+ cy.visit("/trash");
+
+ cy.log("user should be able to bulk restore");
selectItem("Collection A");
selectItem("Dashboard A");
selectItem("Question A");
@@ -511,29 +545,38 @@ describe("scenarios > collections > trash", () => {
cy.findByTestId("toast-card")
.should("be.visible")
.within(() => {
- cy.findByText("Delete permanently").should("not.be.disabled");
- cy.findByText("Move").should("not.be.disabled");
- cy.findByText("Restore").should("not.be.disabled").click();
+ cy.button("Delete permanently").should("be.enabled");
+ cy.button("Move").should("be.enabled");
+ cy.button("Restore").should("be.enabled").click();
});
collectionTable().within(() => {
+ cy.findByText("Collection B").should("exist");
cy.findByText("Collection A").should("not.exist");
cy.findByText("Dashboard A").should("not.exist");
cy.findByText("Question A").should("not.exist");
});
- });
+ cy.findByTestId("toast-card").should("not.exist");
- it("user should be able to bulk move out of trash", () => {
- selectItem("Collection A");
- selectItem("Dashboard A");
- selectItem("Question A");
+ visitRootCollection();
+ collectionTable().within(() => {
+ cy.findByText("Collection A").should("exist");
+ cy.findByText("Dashboard A").should("exist");
+ cy.findByText("Question A").should("exist");
+ });
+ cy.visit("/trash");
+
+ cy.log("user should be able to bulk move out of trash");
+ selectItem("Collection B");
+ selectItem("Dashboard B");
+ selectItem("Question B");
cy.findByTestId("toast-card")
.should("be.visible")
.within(() => {
- cy.findByText("Restore").should("not.be.disabled");
- cy.findByText("Delete permanently").should("not.be.disabled");
- cy.findByText("Move").should("not.be.disabled").click();
+ cy.button("Restore").should("be.enabled");
+ cy.button("Delete permanently").should("be.enabled");
+ cy.button("Move").should("be.enabled").click();
});
H.modal().within(() => {
@@ -542,9 +585,9 @@ describe("scenarios > collections > trash", () => {
});
collectionTable().within(() => {
- cy.findByText("Collection A").should("not.exist");
- cy.findByText("Dashboard A").should("not.exist");
- cy.findByText("Question A").should("not.exist");
+ cy.findByText("Collection B").should("not.exist");
+ cy.findByText("Dashboard B").should("not.exist");
+ cy.findByText("Question B").should("not.exist");
});
H.navigationSidebar().within(() => {
@@ -552,9 +595,9 @@ describe("scenarios > collections > trash", () => {
});
collectionTable().within(() => {
- cy.findByText("Collection A").should("exist");
- cy.findByText("Dashboard A").should("exist");
- cy.findByText("Question A").should("exist");
+ cy.findByText("Collection B").should("exist");
+ cy.findByText("Dashboard B").should("exist");
+ cy.findByText("Question B").should("exist");
});
});
@@ -565,9 +608,9 @@ describe("scenarios > collections > trash", () => {
cy.findByTestId("toast-card")
.should("be.visible")
.within(() => {
- cy.findByText("Restore").should("not.be.disabled");
- cy.findByText("Move").should("not.be.disabled");
- cy.findByText("Delete permanently").should("not.be.disabled").click();
+ cy.button("Restore").should("be.enabled");
+ cy.button("Move").should("be.enabled");
+ cy.button("Delete permanently").should("be.enabled").click();
});
H.modal().within(() => {
@@ -588,13 +631,14 @@ describe("scenarios > collections > trash", () => {
createQuestion(
{
name: "Question A",
- query: { "source-table": 1, limit: 10 },
+ query: { "source-table": ORDERS_ID, limit: 10 },
},
true,
).as("question");
cy.get("@question").then((question) => {
H.visitQuestion(question.id);
+ archiveBanner().should("be.visible");
// should not have disabled actions in top navbar
cy.findAllByTestId("qb-header-action-panel").within(() => {
cy.findByText("Filter").should("not.exist");
@@ -613,6 +657,7 @@ describe("scenarios > collections > trash", () => {
cy.get("@dashboard").then((dashboard) => {
H.visitDashboard(dashboard.id);
+ archiveBanner().should("be.visible");
cy.findAllByTestId("dashboard-header").within(() => {
cy.icon("pencil").should("not.exist");
@@ -628,41 +673,10 @@ describe("scenarios > collections > trash", () => {
createCollection({ name: "Collection A" }).as("collection");
cy.get("@collection").then((collection) => {
- createNativeQuestion(
- {
- name: "Question A",
- native: { query: "select 1;" },
- collection_id: collection.id,
- },
- true,
- ).as("question");
- createDashboard(
- { name: "Dashboard A", collection_id: collection.id },
- true,
- ).as("dashboard");
-
- cy.visit("/admin/permissions/collections");
-
- H.selectSidebarItem("Collection A");
- const COLLECTION_ACCESS_PERMISSION_INDEX = 0;
-
- H.modifyPermission(
- "All Users",
- COLLECTION_ACCESS_PERMISSION_INDEX,
- "View",
- );
- H.modifyPermission(
- "collection",
- COLLECTION_ACCESS_PERMISSION_INDEX,
- "View",
- );
- H.modifyPermission("data", COLLECTION_ACCESS_PERMISSION_INDEX, "View");
-
- cy.button("Save changes").click();
- H.modal().within(() => {
- cy.findByText("Save permissions?");
- cy.findByText("Are you sure you want to do this?");
- cy.button("Yes").click();
+ cy.updateCollectionGraph({
+ [ALL_USERS_GROUP]: { [collection.id]: "read" },
+ [COLLECTION_GROUP]: { [collection.id]: "read" },
+ [DATA_GROUP]: { [collection.id]: "read" },
});
H.archiveCollection(collection.id);
@@ -766,11 +780,14 @@ describe("scenarios > collections > trash", () => {
});
describe("sidebar drag and drop", () => {
- it("should not allow items in the trash to be moved into the trash", () => {
- createDashboard({ name: "Dashboard A" }, true);
+ it("should not allow items in the trash to be moved into the trash, but allow items to be moved out of and into the trash and allow it to be undone", () => {
+ createDashboard({ name: "Dashboard A" }, true).then((dashboard) => {
+ cy.wrap(dashboard.id).as("dashboardId");
+ });
cy.intercept("PUT", "/api/dashboard/**").as("updateDashboard");
cy.visit("/trash");
+ cy.log("should not allow items in the trash to be moved into the trash");
dragAndDrop(
H.main().findByText("Dashboard A"),
H.navigationSidebar().findByText("Trash"),
@@ -780,17 +797,14 @@ describe("scenarios > collections > trash", () => {
// assert no update request went out
cy.get("@updateDashboard.all").should("have.length", 0);
cy.findByTestId("toast-undo").should("not.exist");
- H.main(() => {
- cy.findByText(/Deleted items will appear here/).should("not.exist");
+ H.main().within(() => {
cy.findByText("Dashboard A").should("exist");
+ cy.findByText(/Deleted items will appear here/).should("not.exist");
});
- });
-
- it("should allow items in the trash to be moved out of the trash and allow it to be undone", () => {
- createDashboard({ name: "Dashboard A" }, true);
- cy.intercept("PUT", "/api/dashboard/**").as("updateDashboard");
- cy.visit("/trash");
+ cy.log(
+ "should allow items in the trash to be moved out of the trash and allow it to be undone",
+ );
dragAndDrop(
H.main().findByText("Dashboard A"),
H.navigationSidebar().findByText("First collection"),
@@ -808,14 +822,16 @@ describe("scenarios > collections > trash", () => {
cy.findByText(/Deleted items will appear here/).should("not.exist");
cy.findByText("Dashboard A").should("exist");
});
- });
- it("should allow items outside the trash to be moved in the trash and allow it to be undone", () => {
- createDashboard({
- name: "Dashboard A",
- collection_id: FIRST_COLLECTION_ID,
+ cy.log(
+ "should allow items outside the trash to be moved in the trash and allow it to be undone",
+ );
+ cy.get("@dashboardId").then((dashboardId) => {
+ cy.request("PUT", `/api/dashboard/${dashboardId}`, {
+ archived: false,
+ collection_id: FIRST_COLLECTION_ID,
+ });
});
- cy.intercept("PUT", "/api/dashboard/**").as("updateDashboard");
H.visitCollection(FIRST_COLLECTION_ID);
dragAndDrop(
@@ -823,25 +839,27 @@ describe("scenarios > collections > trash", () => {
H.navigationSidebar().findByText("Trash"),
);
- cy.get("@updateDashboard.all").should("have.length", 1);
+ cy.get("@updateDashboard.all").should("have.length", 3);
H.main().findByText("Dashboard A").should("not.exist");
cy.findByTestId("toast-undo").should("exist");
H.undo();
- cy.get("@updateDashboard.all").should("have.length", 2);
+ cy.get("@updateDashboard.all").should("have.length", 4);
H.main().within(() => {
cy.findByText("Dashboard A").should("exist");
});
});
});
- it("should open only one context menu at a time (metabase#44910)", () => {
+ it("should open only one context menu at a time and not deselect items when aborting operations (metabase#44910, metabase#44911)", () => {
cy.request("PUT", `/api/card/${ORDERS_QUESTION_ID}`, { archived: true });
cy.request("PUT", `/api/card/${ORDERS_COUNT_QUESTION_ID}`, {
archived: true,
});
+ cy.request("PUT", `/api/card/${ORDERS_MODEL_ID}`, { archived: true });
cy.visit("/trash");
+ cy.log("should open only one context menu at a time (metabase#44910)");
toggleEllipsisMenuFor("Orders");
cy.findAllByRole("menu")
.should("have.length", 1)
@@ -855,16 +873,13 @@ describe("scenarios > collections > trash", () => {
.and("contain", "Move")
.and("contain", "Restore")
.and("contain", "Delete permanently");
- });
- it("should not deselect items when aborting operations (metabase#44911)", () => {
- cy.request("PUT", `/api/card/${ORDERS_QUESTION_ID}`, { archived: true });
- cy.request("PUT", `/api/card/${ORDERS_COUNT_QUESTION_ID}`, {
- archived: true,
- });
- cy.request("PUT", `/api/card/${ORDERS_MODEL_ID}`, { archived: true });
- cy.visit("/trash");
+ cy.realPress("Escape");
+ cy.findAllByRole("menu").should("not.exist");
+ cy.log(
+ "should not deselect items when aborting operations (metabase#44911)",
+ );
selectItem("Orders");
selectItem("Orders Model");
@@ -889,13 +904,20 @@ describe("scenarios > collections > trash", () => {
assertChecked("Orders Model");
cy.log("Going through with action should reset selection");
+ cy.intercept("DELETE", "/api/card/*").as("deleteCard");
cy.findByTestId("toast-card")
.should("be.visible")
.findByText("Delete permanently")
.click();
H.modal().findByText("Delete permanently").click();
- assertChecked("Orders, Count", false);
+ cy.wait(["@deleteCard", "@deleteCard"]);
+ cy.findByTestId("toast-card").should("not.exist");
+ collectionTable().within(() => {
+ cy.findByText("Orders, Count").should("be.visible");
+ cy.findByText("Orders").should("not.exist");
+ cy.findByText("Orders Model").should("not.exist");
+ });
});
});
diff --git a/e2e/test/scenarios/collections/uploads.cy.spec.js b/e2e/test/scenarios/collections/uploads.cy.spec.js
index a7ae6d4b307..cd674b3e8ea 100644
--- a/e2e/test/scenarios/collections/uploads.cy.spec.js
+++ b/e2e/test/scenarios/collections/uploads.cy.spec.js
@@ -6,8 +6,6 @@ import { FIXTURE_PATH, VALID_CSV_FILES } from "e2e/support/helpers";
describe("CSV Uploading", { tags: ["@external", "@actions"] }, () => {
beforeEach(() => {
cy.intercept("POST", "/api/dataset").as("dataset");
- cy.intercept("POST", "/api/table/*/append-csv").as("appendCSV");
- cy.intercept("POST", "/api/table/*/replace-csv").as("replaceCSV");
});
it("Can upload a CSV file to an empty postgres schema", () => {
@@ -102,7 +100,8 @@ describe("CSV Uploading", { tags: ["@external", "@actions"] }, () => {
H.expectNoBadSnowplowEvents();
});
- VALID_CSV_FILES.forEach((testFile) => {
+ // VALID_CSV_FILES[0] is uploaded and checked by the append/replace test below
+ VALID_CSV_FILES.slice(1).forEach((testFile) => {
it(`Can upload ${testFile.fileName} to a collection`, () => {
uploadFileToCollection(testFile);
@@ -110,18 +109,10 @@ describe("CSV Uploading", { tags: ["@external", "@actions"] }, () => {
event: "csv_upload_successful",
});
- const tableQuery = `SELECT * FROM information_schema.tables WHERE table_name LIKE '%${testFile.tableName}_%' ORDER BY table_name DESC LIMIT 1;`;
-
- H.queryWritableDB(tableQuery, dialect).then((result) => {
- expect(result.rows.length).to.equal(1);
- const tableName =
- result.rows[0].table_name ?? result.rows[0].TABLE_NAME;
- H.queryWritableDB(
- `SELECT count(*) as count FROM ${tableName};`,
- dialect,
- ).then((result) => {
- expect(Number(result.rows[0].count)).to.equal(testFile.rowCount);
- });
+ assertUploadedRowCount({
+ dialect,
+ testFile,
+ rowCount: testFile.rowCount,
});
});
});
@@ -141,81 +132,74 @@ describe("CSV Uploading", { tags: ["@external", "@actions"] }, () => {
});
cy.log("metabase#55382");
- cy.findByRole("dialog", { name: "Upload error details" })
- .findByRole("button", { name: "Close" })
- .click();
+ closeUploadErrorDetails();
+ cy.intercept("PUT", "/api/collection/*").as("trashCollection");
H.openCollectionMenu();
H.popover().findByText("Move to trash").click();
+ H.modal().button("Move to trash").click();
+ cy.wait("@trashCollection");
+
+ cy.findByTestId("toast-undo").should("contain", "Trashed collection");
cy.findByRole("dialog", { name: "Upload error details" }).should(
"not.exist",
);
});
});
- describe("CSV appends", () => {
- it("Can append a CSV file to an existing table", () => {
- uploadFileToCollection(VALID_CSV_FILES[0]);
- cy.findByTestId("view-footer").findByText(
- `Showing ${VALID_CSV_FILES[0].rowCount} rows`,
- );
+ it("Can upload a CSV to a collection, then append and replace data in the table, but not with a different schema", () => {
+ const { rowCount } = VALID_CSV_FILES[0];
- uploadToExisting({
- testFile: VALID_CSV_FILES[0],
- uploadMode: "append",
- });
- cy.findByTestId("view-footer").findByText(
- `Showing ${VALID_CSV_FILES[0].rowCount * 2} rows`,
- );
+ uploadFileToCollection(VALID_CSV_FILES[0]);
+
+ H.expectUnstructuredSnowplowEvent({
+ event: "csv_upload_successful",
+ });
+ assertUploadedRowCount({
+ dialect,
+ testFile: VALID_CSV_FILES[0],
+ rowCount,
});
- it("Cannot append a CSV file to a table with a different schema", () => {
- uploadFileToCollection(VALID_CSV_FILES[0]);
- cy.findByTestId("view-footer").findByText(
- `Showing ${VALID_CSV_FILES[0].rowCount} rows`,
- );
+ cy.findByTestId("view-footer").findByText(`Showing ${rowCount} rows`);
- uploadToExisting({
- testFile: VALID_CSV_FILES[1],
- identicalSchema: false,
- uploadMode: "append",
- });
- cy.findByTestId("view-footer").findByText(
- `Showing ${VALID_CSV_FILES[0].rowCount} rows`,
- );
+ cy.log("append with an identical schema");
+ uploadToExisting({
+ testFile: VALID_CSV_FILES[0],
+ uploadMode: "append",
});
- });
+ cy.findByTestId("view-footer").findByText(
+ `Showing ${rowCount * 2} rows`,
+ );
- describe("CSV replacement", () => {
- it("Can replace data in an existing table", () => {
- uploadFileToCollection(VALID_CSV_FILES[0]);
- cy.findByTestId("view-footer").findByText(
- `Showing ${VALID_CSV_FILES[0].rowCount} rows`,
- );
+ cy.log("replace with an identical schema");
+ uploadToExisting({
+ testFile: VALID_CSV_FILES[0],
+ uploadMode: "replace",
+ });
+ cy.findByTestId("view-footer").findByText(`Showing ${rowCount} rows`);
- uploadToExisting({
- testFile: VALID_CSV_FILES[0],
- uploadMode: "replace",
- });
- cy.findByTestId("view-footer").findByText(
- `Showing ${VALID_CSV_FILES[0].rowCount} rows`,
- );
+ cy.log("append with a different schema");
+ uploadToExisting({
+ testFile: VALID_CSV_FILES[1],
+ identicalSchema: false,
+ uploadMode: "append",
});
+ closeUploadErrorDetails();
- it("Cannot data in a table with a different schema", () => {
- uploadFileToCollection(VALID_CSV_FILES[0]);
- cy.findByTestId("view-footer").findByText(
- `Showing ${VALID_CSV_FILES[0].rowCount} rows`,
- );
+ cy.log("replace with a different schema");
+ uploadToExisting({
+ testFile: VALID_CSV_FILES[1],
+ identicalSchema: false,
+ uploadMode: "replace",
+ });
+ closeUploadErrorDetails();
- uploadToExisting({
- testFile: VALID_CSV_FILES[1],
- identicalSchema: false,
- uploadMode: "replace",
- });
- cy.findByTestId("view-footer").findByText(
- `Showing ${VALID_CSV_FILES[0].rowCount} rows`,
- );
+ cy.log("rejected uploads leave the table unchanged");
+ assertUploadedRowCount({
+ dialect,
+ testFile: VALID_CSV_FILES[0],
+ rowCount,
});
});
});
@@ -224,7 +208,6 @@ describe("CSV Uploading", { tags: ["@external", "@actions"] }, () => {
it("should allow you to choose a model to append to if there are multiple (metabase#53824)", () => {
H.restore("postgres-writable");
cy.signInAsAdmin();
- H.enableTracking();
H.enableUploads("postgres");
H.headlessUpload(FIRST_COLLECTION_ID, VALID_CSV_FILES[0]);
@@ -252,9 +235,10 @@ describe("CSV Uploading", { tags: ["@external", "@actions"] }, () => {
.click();
H.popover().findByText(VALID_CSV_FILES[0].humanName).click();
- cy.findByRole("textbox", { name: "Select a model" })
- .should("have.value", VALID_CSV_FILES[0].humanName)
- .click();
+ cy.findByRole("textbox", { name: "Select a model" }).should(
+ "have.value",
+ VALID_CSV_FILES[0].humanName,
+ );
});
});
@@ -359,11 +343,36 @@ function uploadFileToCollection(testFile, viewModel = true) {
}
}
+function closeUploadErrorDetails() {
+ cy.findByRole("dialog", { name: "Upload error details" })
+ .findByRole("button", { name: "Close" })
+ .click();
+ cy.findByRole("dialog", { name: "Upload error details" }).should("not.exist");
+}
+
+function assertUploadedRowCount({ dialect, testFile, rowCount }) {
+ const tableQuery = `SELECT * FROM information_schema.tables WHERE table_name LIKE '%${testFile.tableName}_%' ORDER BY table_name DESC LIMIT 1;`;
+
+ H.queryWritableDB(tableQuery, dialect).then((result) => {
+ expect(result.rows.length).to.equal(1);
+ const tableName = result.rows[0].table_name ?? result.rows[0].TABLE_NAME;
+ H.queryWritableDB(
+ `SELECT count(*) as count FROM ${tableName};`,
+ dialect,
+ ).then((result) => {
+ expect(Number(result.rows[0].count)).to.equal(rowCount);
+ });
+ });
+}
+
function uploadToExisting({
testFile,
identicalSchema = true,
uploadMode = "append",
}) {
+ cy.intercept("POST", "/api/table/*/append-csv").as("appendCSV");
+ cy.intercept("POST", "/api/table/*/replace-csv").as("replaceCSV");
+
// assumes we're already looking at an uploadable model page
cy.findByTestId("qb-header").icon("upload").click();