Skip to content

Commit

Permalink
Explore E2E pass 1 - Fix metrics editing in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaHegde committed Sep 26, 2024
1 parent 611836e commit c15acf2
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 214 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<GlobalDimensionSearch />
{#if !$readOnly}
<Button href={`/files${filePath}`} type="secondary">
Edit Metrics <MetricsIcon size="16px" />
Edit Explore <MetricsIcon size="16px" />
</Button>
<DeployDashboardCta />
<LocalAvatarButton />
Expand Down
13 changes: 2 additions & 11 deletions web-local/tests/explores/dashboard-flow-test-setup.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
import { createMetricsViewFromModel } from "web-local/tests/utils/metricsViewHelpers";
import { createExploreFromModel } from "web-local/tests/utils/exploreHelpers";
import { createAdBidsModel } from "web-local/tests/utils/dataSpecifcHelpers";
import { test } from "../utils/test";
import { waitForFileNavEntry } from "../utils/waitHelpers";

export function useDashboardFlowTestSetup() {
test.beforeEach(async ({ page }) => {
test.setTimeout(45000);
await createAdBidsModel(page);

await Promise.all([
waitForFileNavEntry(
page,
`/dashboards/AdBids_model_dashboard.yaml`,
true,
),
createMetricsViewFromModel(page, "/models/AdBids_model.sql"),
]);
await createExploreFromModel(page);
});
}
121 changes: 50 additions & 71 deletions web-local/tests/explores/explores.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,22 @@ import { ResourceWatcher } from "web-local/tests/utils/ResourceWatcher";
import { updateCodeEditor, wrapRetryAssertion } from "../utils/commonHelpers";
import {
assertLeaderboards,
createMetricsViewFromModel,
createMetricsViewFromSource,
interactWithTimeRangeMenu,
} from "web-local/tests/utils/metricsViewHelpers";
import {
AD_BIDS_EXPLORE_PATH,
AD_BIDS_METRICS_PATH,
assertAdBidsDashboard,
createAdBidsModel,
} from "../utils/dataSpecifcHelpers";
import { createSource } from "../utils/sourceHelpers";
import { test } from "../utils/test";
import { waitForFileNavEntry } from "../utils/waitHelpers";
import { gotoNavEntry, waitForFileNavEntry } from "../utils/waitHelpers";

test.describe("explores", () => {
test("Autogenerate explore from source", async ({ page }) => {
await createSource(page, "AdBids.csv", "/sources/AdBids.yaml");
await createExploreFromSource(
page,
"/sources/AdBids.yaml",
"/metrics/AdBids_metrics.yaml",
);
await createExploreFromSource(page);
await waitForFileNavEntry(
page,
"/explore-dashboards/AdBids_metrics_explore.yaml",
Expand All @@ -40,18 +36,7 @@ test.describe("explores", () => {

test("Autogenerate explore from model", async ({ page }) => {
await createAdBidsModel(page);
await Promise.all([
waitForFileNavEntry(
page,
"/explore-dashboards/AdBids_model_metrics_explore.yaml",
true,
),
createExploreFromModel(
page,
"/models/AdBids_model.sql",
"/metrics/AdBids_model_metrics.yaml",
),
]);
await createExploreFromModel(page);

await page.getByRole("button", { name: "Preview" }).click();
await assertAdBidsDashboard(page);
Expand Down Expand Up @@ -85,7 +70,7 @@ test.describe("explores", () => {
const watcher = new ResourceWatcher(page);

await createAdBidsModel(page);
await createMetricsViewFromModel(page, "/models/AdBids_model.sql");
await createExploreFromModel(page);
await page.getByRole("button", { name: "Preview" }).click();

// Check the total records are 100k
Expand Down Expand Up @@ -230,36 +215,21 @@ test.describe("explores", () => {
// Check that the data is updated for last 6 hours
// Change time range back to all time

// Open Edit Metrics
await page.getByRole("button", { name: "Edit Metrics" }).click();
// Open Edit Explore
await page.getByRole("button", { name: "Edit Explore" }).click();

// Get the dashboard name field and change it

const changeDisplayNameDoc = `# Visit https://docs.rilldata.com/reference/project-files to learn more about Rill project files.
const changeDisplayNameDoc = `
type: explore
type: metrics_view
title: "AdBids_model_dashboard_rename"
model: "AdBids_model"
default_time_range: ""
smallest_time_grain: ""
measures:
- label: Total records
expression: count(*)
name: total_records
description: Total number of records present
format_preset: humanize
dimensions:
- name: publisher
label: Publisher
column: publisher
description: ""
- name: domain
label: Domain
column: domain
description: ""
title: "Adbids dashboard renamed"
metrics_view: AdBids_model_metrics
`;
await watcher.updateAndWaitForDashboard(changeDisplayNameDoc);
dimensions: '*'
measures: '*'
`;
await watcher.updateAndWaitForExplore(changeDisplayNameDoc);

// Remove timestamp column
// await page.getByLabel("Remove timestamp column").click();
Expand All @@ -268,21 +238,22 @@ test.describe("explores", () => {

// Assert that name changed
await expect(
page.getByRole("link", { name: "AdBids_model_dashboard_rename" }),
page.getByRole("link", { name: "Adbids dashboard renamed" }),
).toBeVisible();

// Assert that no time dimension specified
// await expect(page.getByText("No time dimension specified")).toBeVisible();

// Open Edit Metrics
await page.getByRole("button", { name: "Edit Metrics" }).click();
// Open Edit Explore
await page.getByRole("button", { name: "Edit Explore" }).click();
await gotoNavEntry(page, AD_BIDS_METRICS_PATH);

// Add timestamp column back

const addBackTimestampColumnDoc = `# Visit https://docs.rilldata.com/reference/project-files to learn more about Rill project files.
type: metrics_view
title: "AdBids_model_dashboard_rename"
title: "AdBids_model_dashboard"
model: "AdBids_model"
default_time_range: ""
smallest_time_grain: "week"
Expand All @@ -305,35 +276,25 @@ test.describe("explores", () => {
`;
await watcher.updateAndWaitForDashboard(addBackTimestampColumnDoc);
await gotoNavEntry(page, AD_BIDS_EXPLORE_PATH);

// Preview
await page.getByRole("button", { name: "Preview" }).click();

// Assert that time dimension is now week
await expect(timeGrainSelector).toHaveText("by Week");

// Open Edit Metrics
await page.getByRole("button", { name: "Edit Metrics" }).click();
// Open Edit Explore
await page.getByRole("button", { name: "Edit Explore" }).click();

const deleteOnlyMeasureDoc = `# Visit https://docs.rilldata.com/reference/project-files to learn more about Rill project files.
const deleteOnlyMeasureDoc = `
type: explore
type: metrics_view
title: "AdBids_model_dashboard_rename"
model: "AdBids_model"
default_time_range: ""
smallest_time_grain: "week"
timeseries: "timestamp"
measures: []
dimensions:
- name: publisher
label: Publisher
column: publisher
description: ""
- name: domain
label: Domain
column: domain
description: ""
title: "Adbids dashboard renamed"
metrics_view: AdBids_model_metrics
dimensions: '*'
measures: []
`;
await updateCodeEditor(page, deleteOnlyMeasureDoc);
// Check warning message appears, Preview is disabled
Expand All @@ -343,11 +304,26 @@ test.describe("explores", () => {

await expect(page.getByRole("button", { name: "Preview" })).toBeDisabled();

// add back the measure to explore
await updateCodeEditor(
page,
`
type: explore
title: "Adbids dashboard renamed"
metrics_view: AdBids_model_metrics
dimensions: '*'
measures: '*'
`,
);
await gotoNavEntry(page, AD_BIDS_METRICS_PATH);

// Add back the total rows measure for
const docWithIncompleteMeasure = `# Visit https://docs.rilldata.com/reference/project-files to learn more about Rill project files.
type: metrics_view
title: "AdBids_model_dashboard_rename"
title: "AdBids_model_dashboard"
model: "AdBids_model"
default_time_range: ""
smallest_time_grain: "week"
Expand All @@ -367,7 +343,9 @@ test.describe("explores", () => {
`;

await updateCodeEditor(page, docWithIncompleteMeasure);
await gotoNavEntry(page, AD_BIDS_EXPLORE_PATH);
await expect(page.getByRole("button", { name: "Preview" })).toBeDisabled();
await gotoNavEntry(page, AD_BIDS_METRICS_PATH);

const docWithCompleteMeasure = `# Visit https://docs.rilldata.com/reference/project-files to learn more about Rill project files.
Expand Down Expand Up @@ -398,6 +376,7 @@ dimensions:
`;

await updateCodeEditor(page, docWithCompleteMeasure);
await gotoNavEntry(page, AD_BIDS_EXPLORE_PATH);
await expect(page.getByRole("button", { name: "Preview" })).toBeEnabled();

// Preview
Expand Down Expand Up @@ -490,7 +469,7 @@ dimensions:

await expect(page.getByText("~0%")).toBeVisible();

// await page.getByRole("button", { name: "Edit Metrics" }).click();
// await page.getByRole("button", { name: "Edit Explore" }).click();

// go back to the dashboard

Expand Down
8 changes: 8 additions & 0 deletions web-local/tests/explores/leaderboard-context-column.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { expect } from "@playwright/test";
import {
AD_BIDS_EXPLORE_PATH,
AD_BIDS_METRICS_PATH,
} from "web-local/tests/utils/dataSpecifcHelpers";
import { ResourceWatcher } from "web-local/tests/utils/ResourceWatcher";
import { gotoNavEntry } from "web-local/tests/utils/waitHelpers";
import { clickMenuButton } from "../utils/commonHelpers";
import { interactWithTimeRangeMenu } from "web-local/tests/utils/metricsViewHelpers";
import { test } from "../utils/test";
Expand All @@ -11,6 +16,8 @@ test.describe("leaderboard context column", () => {
test("Leaderboard context column", async ({ page }) => {
const watcher = new ResourceWatcher(page);

await gotoNavEntry(page, AD_BIDS_METRICS_PATH);

// reset metrics, and add a metric with `valid_percent_of_total: true`
const metricsWithValidPercentOfTotal = `# Visit https://docs.rilldata.com/reference/project-files to learn more about Rill project files.
Expand Down Expand Up @@ -41,6 +48,7 @@ test.describe("leaderboard context column", () => {
description: ""
`;
await watcher.updateAndWaitForDashboard(metricsWithValidPercentOfTotal);
await gotoNavEntry(page, AD_BIDS_EXPLORE_PATH);

async function clickMenuItem(itemName: string, wait = true) {
await clickMenuButton(page, itemName, "option");
Expand Down
8 changes: 8 additions & 0 deletions web-local/tests/explores/number-formatting.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { useDashboardFlowTestSetup } from "web-local/tests/explores/dashboard-flow-test-setup";
import {
AD_BIDS_EXPLORE_PATH,
AD_BIDS_METRICS_PATH,
} from "web-local/tests/utils/dataSpecifcHelpers";
import { ResourceWatcher } from "web-local/tests/utils/ResourceWatcher";
import { interactWithTimeRangeMenu } from "web-local/tests/utils/metricsViewHelpers";
import { expect } from "@playwright/test";
import { gotoNavEntry } from "web-local/tests/utils/waitHelpers";
import { test } from "../utils/test";

test.describe("smoke tests for number formatting", () => {
Expand All @@ -10,6 +15,8 @@ test.describe("smoke tests for number formatting", () => {
test("smoke tests for number formatting", async ({ page }) => {
const watcher = new ResourceWatcher(page);

await gotoNavEntry(page, AD_BIDS_METRICS_PATH);

// This is a metrics spec with all available formatting options
const formatterFlowDashboard = `# Visit https://docs.rilldata.com/reference/project-files to learn more about Rill project files.
title: "AdBids_model_dashboard"
Expand Down Expand Up @@ -65,6 +72,7 @@ dimensions:

// update the code editor with the new spec
await watcher.updateAndWaitForDashboard(formatterFlowDashboard);
await gotoNavEntry(page, AD_BIDS_EXPLORE_PATH);

const previewButton = page.getByRole("button", { name: "Preview" });

Expand Down
Loading

0 comments on commit c15acf2

Please sign in to comment.