From 1808b586eb0d891ed446ae05c3e0d3e76e2c89d2 Mon Sep 17 00:00:00 2001 From: Nemanja Glumac <31325167+nemanjaglumac@users.noreply.github.com> Date: Thu, 7 Jul 2022 21:47:34 +0200 Subject: [PATCH] [E2E] Robustify and fix question moderation tests (#23769) * Refactor admin part of question moderation E2E test * Remove redundant test * Do not use hard coded user names --- .../moderation-question.cy.spec.js | 129 +++++++++--------- 1 file changed, 66 insertions(+), 63 deletions(-) diff --git a/frontend/test/metabase/scenarios/organization/moderation-question.cy.spec.js b/frontend/test/metabase/scenarios/organization/moderation-question.cy.spec.js index 7f3336cae82..94c39911812 100644 --- a/frontend/test/metabase/scenarios/organization/moderation-question.cy.spec.js +++ b/frontend/test/metabase/scenarios/organization/moderation-question.cy.spec.js @@ -2,87 +2,89 @@ import { describeEE, restore, visitQuestion, - popover, openQuestionActions, questionInfoButton, } from "__support__/e2e/helpers"; +import { USERS } from "__support__/e2e/cypress_data"; + +const { admin } = USERS; +const adminFullName = `${admin.first_name} ${admin.last_name}`; + describeEE("scenarios > saved question moderation", () => { describe("as an admin", () => { beforeEach(() => { restore(); cy.signInAsAdmin(); - - visitQuestion(2); }); - it("should be able to verify a saved question", () => { - openQuestionActions(); - - popover().within(() => { - cy.findByTestId("moderation-verify-action").click(); - }); - - openQuestionActions(); - popover().within(() => { - cy.findByText("Remove verification"); - }); - - cy.findByPlaceholderText("Search…").type("orders{enter}"); - cy.findByText("Orders, Count").icon("verified"); - - cy.visit("/collection/root"); + it("should be able to verify and unverify a saved question", () => { + visitQuestion(2); - cy.findByText("Orders, Count").icon("verified"); - }); + verifyQuestion(); - it("should be able to unverify a verified saved question", () => { - openQuestionActions(); - popover().within(() => { - cy.findByTestId("moderation-verify-action").click(); - }); + // 1. Question title + cy.findByTestId("qb-header-left-side").find(".Icon-verified"); - openQuestionActions(); - popover().within(() => { - cy.findByTestId("moderation-remove-verification-action").click(); - }); - - openQuestionActions(); - popover().within(() => { - cy.findByText("Verify this question").should("be.visible"); - }); + // 2. Question's history + questionInfoButton().click(); + cy.findByText("History"); + cy.findAllByText("You verified this") + .should("have.length", 2) + .and("be.visible"); - cy.findByTestId("qb-header-left-side").within(() => { - cy.icon("verified").should("not.exist"); - }); + // 3. Recently viewed list + cy.findByPlaceholderText("Search…").click(); + cy.findByTestId("recently-viewed-item") + .should("contain", "Orders, Count") + .find(".Icon-verified"); + // 4. Search results cy.findByPlaceholderText("Search…").type("orders{enter}"); - cy.findByText("Orders, Count").find(".Icon-verified").should("not.exist"); + cy.findAllByTestId("search-result-item") + .contains("Orders, Count") + .siblings(".Icon-verified"); + // 5. Question's collection cy.visit("/collection/root"); + cy.findByText("Orders, Count").closest("a").find(".Icon-verified"); - cy.findByText("Orders, Count").find(".Icon-verified").should("not.exist"); - }); + // Let's go back to the question and remove the verification + visitQuestion(2); - it("should be able to see evidence of verification/unverification in the question's timeline", () => { - openQuestionActions(); + removeQuestionVerification(); - popover().within(() => { - cy.findByTestId("moderation-verify-action").click(); - }); + // 1. Question title + cy.findByTestId("qb-header-left-side") + .find(".Icon-verified") + .should("not.exist"); + // 2. Question's history questionInfoButton().click(); cy.findByText("History"); + cy.findByText("You removed verification"); + cy.findByText("You verified this"); // Implicit assertion - there can be only one :) - cy.findAllByText("You verified this").should("be.visible"); - - openQuestionActions(); + // 3. Recently viewed list + cy.findByPlaceholderText("Search…").click(); + cy.findByTestId("recently-viewed-item") + .should("contain", "Orders, Count") + .find(".Icon-verified") + .should("not.exist"); - popover().within(() => { - cy.findByTestId("moderation-remove-verification-action").click(); - }); + // 4. Search results + cy.findByPlaceholderText("Search…").type("orders{enter}"); + cy.findAllByTestId("search-result-item") + .contains("Orders, Count") + .siblings(".Icon-verified") + .should("not.exist"); - cy.findByText("You removed verification").should("be.visible"); + // 5. Question's collection + cy.visit("/collection/root"); + cy.findByText("Orders, Count") + .closest("a") + .find(".Icon-verified") + .should("not.exist"); }); }); @@ -106,7 +108,7 @@ describeEE("scenarios > saved question moderation", () => { cy.icon("verified").should("not.exist"); questionInfoButton().click(); - cy.findByText("Bobby Tables verified this").should("not.exist"); + cy.findByText(`${adminFullName} verified this`).should("not.exist"); cy.findByPlaceholderText("Search…").type("orders{enter}"); cy.findByText("Orders, Count, Grouped by Created At (year)") @@ -135,14 +137,15 @@ describeEE("scenarios > saved question moderation", () => { cy.findByText("Orders, Count").icon("verified"); }); - - it("should be able to see the question verification in the question's timeline", () => { - visitQuestion(2); - - questionInfoButton().click(); - cy.findByText("History"); - - cy.findAllByText("Bobby Tables verified this").should("be.visible"); - }); }); }); + +function verifyQuestion() { + openQuestionActions(); + cy.findByTextEnsureVisible("Verify this question").click(); +} + +function removeQuestionVerification() { + openQuestionActions(); + cy.findByTextEnsureVisible("Remove verification").click(); +} -- GitLab