Skip to content

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

Handle both list and search default-value pickers in embedding e2e test (#82727)

Sébastienc796ec01ecc3
diff --git a/e2e/test/scenarios/embedding/embedding-dashboard.cy.spec.js b/e2e/test/scenarios/embedding/embedding-dashboard.cy.spec.js
index 59723e3de47..6c71922b95d 100644
--- a/e2e/test/scenarios/embedding/embedding-dashboard.cy.spec.js
+++ b/e2e/test/scenarios/embedding/embedding-dashboard.cy.spec.js
@@ -234,7 +234,7 @@ describe("scenarios > embedding > dashboard parameters", () => {
getDashboardFilter("Name").click();
H.toggleRequiredParameter();
H.sidebar().findByText("Default value").next().click();
- addWidgetStringFilter("Ferne Rosenbaum", {
+ setRequiredParameterDefaultValue("Ferne Rosenbaum", {
buttonLabel: "Update filter",
});
H.saveDashboard();
@@ -1485,6 +1485,53 @@ function getDashboardFilter(name) {
.findByText(name);
}
+// The default-value picker for a field-based parameter can render as either
+// a search combobox or a checkbox list, depending on the field's values
+// configuration; handle both so the test isn't sensitive to which one shows.
+function setRequiredParameterDefaultValue(value, { buttonLabel } = {}) {
+ // The widget can still be loading (neither mode rendered yet) right after
+ // the popover opens; wait until one of them actually shows up before
+ // deciding which branch to take.
+ H.popover()
+ .first()
+ .should(($popover) => {
+ const hasList =
+ $popover.find('[placeholder="Search the list"]').length > 0;
+ const hasCombobox = $popover.find("input").length > 0;
+ expect(hasList || hasCombobox, "default value widget to be ready").to.be
+ .true;
+ });
+
+ cy.get("body").then(($body) => {
+ if ($body.find('[placeholder="Search the list"]').length > 0) {
+ H.popover()
+ .first()
+ .within(() => {
+ // The list can still be settling (e.g. a background values fetch
+ // replacing the initial options) right as we click, so retry the
+ // click itself until the checkbox actually ends up checked.
+ checkFilterValueCheckbox(value);
+ cy.button(buttonLabel).click();
+ });
+ } else {
+ addWidgetStringFilter(value, { buttonLabel });
+ }
+ });
+}
+
+function checkFilterValueCheckbox(value, attempt = 0) {
+ cy.findByTestId(`${value}-filter-value`).then(($checkbox) => {
+ if ($checkbox.prop("checked")) {
+ return;
+ }
+ if (attempt > 5) {
+ throw new Error(`Could not check the "${value}" filter value checkbox`);
+ }
+ cy.wrap($checkbox).click({ force: true });
+ checkFilterValueCheckbox(value, attempt + 1);
+ });
+}
+
function assertRequiredEnabledForName({ name, enabled }) {
getDashboardFilter(name).click();
H.getRequiredToggle().should(enabled ? "be.enabled" : "not.be.enabled");