Newer
Older
import { SAMPLE_DB_ID } from "e2e/support/cypress_data";
import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
import { ORDERS_QUESTION_ID } from "e2e/support/cypress_sample_instance_data";
describeWithSnowplow,
expectGoodSnowplowEvent,
expectNoBadSnowplowEvents,
getNotebookStep,
openNotebook,
openOrdersTable,
resetSnowplow,
visualize,
} from "e2e/support/helpers";
const { ORDERS, ORDERS_ID, PEOPLE } = SAMPLE_DATABASE;
const DATE_CASES = [
{
option: "Hour of day",
value: "21",
},
{
option: "Day of month",
value: "11",
},
{
option: "Day of week",
value: "Tuesday",
},
{
option: "Month of year",
value: "Feb",
},
{
option: "Quarter of year",
value: "Q1",
},
{
option: "Year",
value: "2,025",
const EMAIL_CASES = [
{
option: "Domain",
value: "yahoo",
example: "example, online",
},
{
option: "Host",
value: "yahoo.com",
example: "example.com, online.com",
},
];
const URL_CASES = [
{
option: "Domain",
value: "yahoo",
example: "example, online",
},
{
option: "Subdomain",
value: "",
example: "www, maps",
},
{
option: "Host",
value: "yahoo.com",
example: "example.com, online.com",
},
];
const DATE_QUESTION = {
query: {
"source-table": ORDERS_ID,
aggregation: [
["min", ["field", ORDERS.CREATED_AT, { "base-type": "type/DateTime" }]],
],
breakout: [
[
"field",
ORDERS.CREATED_AT,
{ "base-type": "type/DateTime", "temporal-unit": "month" },
],
],
limit: 1,
},
};
describeWithSnowplow("extract action", () => {
beforeEach(() => {
restore();
cy.signInAsAdmin();
});
describe("date columns", () => {
describe("should add a date expression for each option", () => {
DATE_CASES.forEach(({ option, value, example }) => {
it(option, () => {
openOrdersTable({ limit: 1 });
extractColumnAndCheck({
column: "Created At",
option,
value,
extraction: "Extract day, month…",
describe("should add a new column after the selected column", () => {
it("ad-hoc question", () => {
openOrdersTable();
extractColumnAndCheck({
column: "Created At",
option: "Year",
extraction: "Extract day, month…",
});
});
it("saved question without viz settings", () => {
visitQuestion(ORDERS_QUESTION_ID);
extractColumnAndCheck({
column: "Created At",
option: "Year",
extraction: "Extract day, month…",
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
});
});
it("saved question with viz settings", () => {
cy.createQuestion(
{
query: {
"source-table": ORDERS_ID,
fields: [
["field", ORDERS.ID, { "base-type": "type/BigInteger" }],
["field", ORDERS.CREATED_AT, { "base-type": "type/DateTime" }],
["field", ORDERS.QUANTITY, { "base-type": "type/Integer" }],
],
},
visualization_settings: {
"table.columns": [
{
name: "ID",
fieldRef: ["field", ORDERS.ID, null],
enabled: true,
},
{
name: "CREATED_AT",
fieldRef: [
"field",
ORDERS.CREATED_AT,
{
"temporal-unit": "default",
},
],
enabled: true,
},
{
name: "QUANTITY",
fieldRef: ["field", ORDERS.QUANTITY, null],
enabled: true,
},
],
},
},
{ visitQuestion: true },
);
extractColumnAndCheck({
column: "Created At",
option: "Year",
extraction: "Extract day, month…",
it("should add an expression based on a breakout column", () => {
cy.createQuestion(DATE_QUESTION, { visitQuestion: true });
extractColumnAndCheck({
column: "Created At: Month",
option: "Month of year",
value: "Apr",
extraction: "Extract day, month…",
});
});
it("should add an expression based on an aggregation column", () => {
cy.createQuestion(DATE_QUESTION, { visitQuestion: true });
extractColumnAndCheck({
column: "Min of Created At: Default",
option: "Year",
value: "2,022",
extraction: "Extract day, month…",
});
});
it("should handle duplicate expression names", () => {
openOrdersTable({ limit: 1 });
extractColumnAndCheck({
column: "Created At",
option: "Hour of day",
newColumn: "Hour of day",
extraction: "Extract day, month…",
});
extractColumnAndCheck({
column: "Created At",
option: "Hour of day",
newColumn: "Hour of day_2",
extraction: "Extract day, month…",
});
});
it("should be able to modify the expression in the notebook editor", () => {
openOrdersTable({ limit: 1 });
extractColumnAndCheck({
column: "Created At",
option: "Year",
value: "2,025",
extraction: "Extract day, month…",
});
openNotebook();
getNotebookStep("expression").findByText("Year").click();
enterCustomColumnDetails({ formula: "+ 2" });
popover().button("Update").click();
visualize();
cy.findByRole("gridcell", { name: "2,027" }).should("be.visible");
});
it("should use current user locale for string expressions", () => {
cy.request("GET", "/api/user/current").then(({ body: user }) => {
cy.request("PUT", `/api/user/${user.id}`, { locale: "de" });
});
openOrdersTable({ limit: 1 });
extractColumnAndCheck({
column: "Created At",
option: "Tag der Woche",
value: "Dienstag",
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
extraction: "Extract day, month…",
});
});
});
describe("email columns", () => {
beforeEach(() => {
restore();
cy.signInAsAdmin();
});
EMAIL_CASES.forEach(({ option, value, example }) => {
it(option, () => {
openPeopleTable({ limit: 1 });
extractColumnAndCheck({
column: "Email",
option,
value,
example,
extraction: "Extract domain, host…",
});
});
});
});
describe("url columns", () => {
restore();
cy.signInAsAdmin();
// Make the Email column a URL column for these tests, to avoid having to create a new model
cy.request("PUT", `/api/field/${PEOPLE.EMAIL}`, {
semantic_type: "type/URL",
});
});
URL_CASES.forEach(({ option, value, example }) => {
it(option, () => {
openPeopleTable({ limit: 1 });
extractColumnAndCheck({
column: "Email",
option,
value,
example,
extraction: "Extract domain, subdomain…",
});
function extractColumnAndCheck({
column,
option,
newColumn = option,
const requestAlias = _.uniqueId("dataset");
cy.intercept("POST", "/api/dataset").as(requestAlias);
cy.findByRole("columnheader", { name: column }).click();
popover().findByText(extraction).click();
cy.wait(1);
if (example) {
popover().findByText(option).should("contain", example);
}
popover().findByText(option).click();
cy.wait(`@${requestAlias}`);
metabase-bot[bot]
committed
cy.findAllByRole("columnheader")
.last()
.should("have.text", newColumn)
.should("be.visible");
if (value) {
cy.findByRole("gridcell", { name: value }).should("be.visible");
}
}
describeWithSnowplow("extract action", () => {
beforeEach(() => {
restore();
resetSnowplow();
cy.signInAsAdmin();
});
afterEach(() => {
expectNoBadSnowplowEvents();
});
it("should create a snowplow event for the column extraction action", () => {
openOrdersTable({ limit: 1 });
cy.wait(1);
extractColumnAndCheck({
column: "Created At",
option: "Year",
value: "2,025",
extraction: "Extract day, month…",