Skip to content
Snippets Groups Projects
Unverified Commit 5b9851b0 authored by Nemanja Glumac's avatar Nemanja Glumac Committed by GitHub
Browse files

Add initial set of tests around SQL dashboard filters for text/category (#17382)

parent 0a1b0db0
No related branches found
No related tags found
No related merge requests found
import {
restore,
popover,
mockSessionProperty,
filterWidget,
editDashboard,
saveDashboard,
setFilter,
} from "__support__/e2e/cypress";
import { DASHBOARD_SQL_TEXT_FILTERS } from "./helpers/e2e-dashboard-filter-data-objects";
import { addWidgetStringFilter } from "../native-filters/helpers/e2e-field-filter-helpers";
import { SAMPLE_DATASET } from "__support__/e2e/cypress_sample_dataset";
const { PRODUCTS } = SAMPLE_DATASET;
Object.entries(DASHBOARD_SQL_TEXT_FILTERS).forEach(
([filter, { value, representativeResult, sqlFilter }]) => {
describe("scenarios > dashboard > filters > SQL > text/category", () => {
beforeEach(() => {
restore();
cy.signInAsAdmin();
mockSessionProperty("field-filter-operators-enabled?", true);
const questionDetails = getQuestionDetails(sqlFilter);
cy.createNativeQuestionAndDashboard({ questionDetails }).then(
({ body: { id, card_id, dashboard_id } }) => {
cy.intercept("POST", `/api/card/${card_id}/query`).as("cardQuery");
cy.visit(`/question/${card_id}`);
// Wait for `result_metadata` to load
cy.wait("@cardQuery");
cy.visit(`/dashboard/${dashboard_id}`);
},
);
editDashboard();
setFilter("Text or Category", filter);
cy.findByText("Column to filter on")
.next("a")
.click();
popover()
.contains("Filter")
.click();
});
it(`should work for "${filter}" when set through the filter widget`, () => {
saveDashboard();
filterWidget().click();
addWidgetStringFilter(value);
cy.get(".Card").within(() => {
cy.contains(representativeResult);
});
});
it(`should work for "${filter}" when set as the default filter`, () => {
cy.findByText("Default value")
.next()
.click();
addWidgetStringFilter(value);
saveDashboard();
cy.get(".Card").within(() => {
cy.contains(representativeResult);
});
});
});
},
);
function getQuestionDetails(filter) {
return {
name: "SQL with Field Filter",
native: {
query: "select * from PRODUCTS where {{filter}}",
"template-tags": {
filter: {
id: "e05b9e58-3c51-676d-7334-4c2543709094",
name: "filter",
"display-name": "Filter",
type: "dimension",
dimension: ["field", PRODUCTS.CATEGORY, null],
"widget-type": filter,
},
},
},
};
}
...@@ -112,3 +112,36 @@ export const DASHBOARD_TEXT_FILTERS = { ...@@ -112,3 +112,36 @@ export const DASHBOARD_TEXT_FILTERS = {
representativeResult: "47.68", representativeResult: "47.68",
}, },
}; };
export const DASHBOARD_SQL_TEXT_FILTERS = {
Dropdown: {
sqlFilter: "string/=",
value: "Gizmo",
representativeResult: "Rustic Paper Wallet",
},
"Is not": {
sqlFilter: "string/!=",
value: "Gadget",
representativeResult: "Rustic Paper Wallet",
},
Contains: {
sqlFilter: "string/contains",
value: "oo",
representativeResult: "Small Marble Shoes",
},
"Does not contain": {
sqlFilter: "string/does-not-contain",
value: "oo",
representativeResult: "Rustic Paper Wallet",
},
"Starts with": {
sqlFilter: "string/starts-with",
value: "G",
representativeResult: "Rustic Paper Wallet",
},
"Ends with": {
sqlFilter: "string/ends-with",
value: "y",
representativeResult: "Small Marble Shoes",
},
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment