Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaHegde committed Dec 12, 2024
1 parent 7c3ce36 commit 3fc4354
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
AD_BIDS_TIME_RANGE_SUMMARY,
} from "@rilldata/web-common/features/dashboards/stores/test-data/data";
import {
getInitExploreStateForTest,
getPartialDashboard,
resetDashboardStore,
} from "@rilldata/web-common/features/dashboards/stores/test-data/helpers";
Expand Down Expand Up @@ -96,9 +97,11 @@ describe("sparse proto", () => {
it(`from ${title}`, () => {
const dashboard = getDefaultExploreState(
AD_BIDS_EXPLORE_NAME,
AD_BIDS_METRICS_INIT,
AD_BIDS_EXPLORE_INIT,
AD_BIDS_TIME_RANGE_SUMMARY,
getInitExploreStateForTest(
AD_BIDS_METRICS_INIT,
AD_BIDS_EXPLORE_INIT,
AD_BIDS_TIME_RANGE_SUMMARY,
),
);
const defaultProto = getProtoFromDashboardState(dashboard);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
} from "@rilldata/web-common/features/dashboards/filters/measure-filters/measure-filter-options";
import { AdvancedMeasureCorrector } from "@rilldata/web-common/features/dashboards/stores/AdvancedMeasureCorrector";
import { getDefaultExploreState } from "@rilldata/web-common/features/dashboards/stores/dashboard-store-defaults";
import { getInitExploreStateForTest } from "@rilldata/web-common/features/dashboards/stores/test-data/helpers";
import type { DashboardTimeControls } from "@rilldata/web-common/lib/time/types";
import {
V1TimeGrain,
Expand Down Expand Up @@ -36,9 +37,7 @@ describe("AdvancedMeasureCorrector", () => {
it("changing grain while in TDD for measure based on timestamp", () => {
const dashboard = getDefaultExploreState(
"AdBids",
MetricsView,
Explore,
undefined,
getInitExploreStateForTest(MetricsView, Explore),
);
dashboard.tdd.expandedMeasureName = AD_BIDS_IMPRESSIONS_MEASURE_NO_GRAIN;

Expand Down Expand Up @@ -73,9 +72,7 @@ describe("AdvancedMeasureCorrector", () => {
it("metrics view spec changed converting a measure to an advanced measure", () => {
const dashboard = getDefaultExploreState(
"AdBids",
MetricsView,
Explore,
undefined,
getInitExploreStateForTest(MetricsView, Explore),
);
dashboard.leaderboardMeasureName = AD_BIDS_IMPRESSIONS_MEASURE;
dashboard.dimensionThresholdFilters = [
Expand Down
99 changes: 52 additions & 47 deletions web-common/src/features/dashboards/stores/dashboard-stores.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
assertMetricsView,
assertMetricsViewRaw,
createAdBidsMirrorInStore,
getInitExploreStateForTest,
initStateManagers,
resetDashboardStore,
} from "@rilldata/web-common/features/dashboards/stores/test-data/helpers";
Expand Down Expand Up @@ -194,12 +195,10 @@ describe("dashboard-stores", () => {

metricsExplorerStore.init(
AD_BIDS_EXPLORE_NO_TIMESTAMP_NAME,
AD_BIDS_METRICS_INIT,
{
getInitExploreStateForTest(AD_BIDS_METRICS_INIT, {
metricsView: AD_BIDS_NO_TIMESTAMP_NAME,
...AD_BIDS_EXPLORE_INIT,
},
undefined,
}),
);
assertMetricsViewRaw(
AD_BIDS_EXPLORE_NO_TIMESTAMP_NAME,
Expand All @@ -224,22 +223,24 @@ describe("dashboard-stores", () => {
metricsExplorerStore.remove(AD_BIDS_EXPLORE_NAME);
metricsExplorerStore.init(
AD_BIDS_EXPLORE_NAME,
AD_BIDS_METRICS_INIT,
{
...AD_BIDS_EXPLORE_INIT,
defaultPreset: {
timeRange: "PT6H",
comparisonMode:
V1ExploreComparisonMode.EXPLORE_COMPARISON_MODE_UNSPECIFIED,
getInitExploreStateForTest(
AD_BIDS_METRICS_INIT,
{
...AD_BIDS_EXPLORE_INIT,
defaultPreset: {
timeRange: "PT6H",
comparisonMode:
V1ExploreComparisonMode.EXPLORE_COMPARISON_MODE_UNSPECIFIED,
},
},
},
{
timeRangeSummary: {
min: TestTimeConstants.LAST_DAY.toISOString(),
max: TestTimeConstants.NOW.toISOString(),
interval: V1TimeGrain.TIME_GRAIN_MINUTE as any,
{
timeRangeSummary: {
min: TestTimeConstants.LAST_DAY.toISOString(),
max: TestTimeConstants.NOW.toISOString(),
interval: V1TimeGrain.TIME_GRAIN_MINUTE as any,
},
},
},
),
);

let metrics = get(metricsExplorerStore).entities[AD_BIDS_EXPLORE_NAME];
Expand All @@ -251,22 +252,24 @@ describe("dashboard-stores", () => {
metricsExplorerStore.remove(AD_BIDS_EXPLORE_NAME);
metricsExplorerStore.init(
AD_BIDS_EXPLORE_NAME,
AD_BIDS_METRICS_INIT,
{
...AD_BIDS_EXPLORE_INIT,
defaultPreset: {
timeRange: "PT6H",
comparisonMode:
V1ExploreComparisonMode.EXPLORE_COMPARISON_MODE_DIMENSION,
getInitExploreStateForTest(
AD_BIDS_METRICS_INIT,
{
...AD_BIDS_EXPLORE_INIT,
defaultPreset: {
timeRange: "PT6H",
comparisonMode:
V1ExploreComparisonMode.EXPLORE_COMPARISON_MODE_DIMENSION,
},
},
},
{
timeRangeSummary: {
min: TestTimeConstants.LAST_DAY.toISOString(),
max: TestTimeConstants.NOW.toISOString(),
interval: V1TimeGrain.TIME_GRAIN_MINUTE as any,
{
timeRangeSummary: {
min: TestTimeConstants.LAST_DAY.toISOString(),
max: TestTimeConstants.NOW.toISOString(),
interval: V1TimeGrain.TIME_GRAIN_MINUTE as any,
},
},
},
),
);
metrics = get(metricsExplorerStore).entities[AD_BIDS_EXPLORE_NAME];
expect(metrics.showTimeComparison).toBeFalsy();
Expand All @@ -278,23 +281,25 @@ describe("dashboard-stores", () => {
metricsExplorerStore.remove(AD_BIDS_EXPLORE_NAME);
metricsExplorerStore.init(
AD_BIDS_EXPLORE_NAME,
AD_BIDS_METRICS_INIT,
{
...AD_BIDS_EXPLORE_INIT,
defaultPreset: {
timeRange: "PT6H",
comparisonMode:
V1ExploreComparisonMode.EXPLORE_COMPARISON_MODE_DIMENSION,
comparisonDimension: AD_BIDS_DOMAIN_DIMENSION,
getInitExploreStateForTest(
AD_BIDS_METRICS_INIT,
{
...AD_BIDS_EXPLORE_INIT,
defaultPreset: {
timeRange: "PT6H",
comparisonMode:
V1ExploreComparisonMode.EXPLORE_COMPARISON_MODE_DIMENSION,
comparisonDimension: AD_BIDS_DOMAIN_DIMENSION,
},
},
},
{
timeRangeSummary: {
min: TestTimeConstants.LAST_DAY.toISOString(),
max: TestTimeConstants.NOW.toISOString(),
interval: V1TimeGrain.TIME_GRAIN_MINUTE as any,
{
timeRangeSummary: {
min: TestTimeConstants.LAST_DAY.toISOString(),
max: TestTimeConstants.NOW.toISOString(),
interval: V1TimeGrain.TIME_GRAIN_MINUTE as any,
},
},
},
),
);
metrics = get(metricsExplorerStore).entities[AD_BIDS_EXPLORE_NAME];
expect(metrics.selectedComparisonDimension).toBe(AD_BIDS_DOMAIN_DIMENSION);
Expand Down
46 changes: 28 additions & 18 deletions web-common/src/features/dashboards/stores/test-data/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { QueryClient } from "@rilldata/svelte-query";
import { createStateManagers } from "@rilldata/web-common/features/dashboards/state-managers/state-managers";
import { getDefaultExploreState } from "@rilldata/web-common/features/dashboards/stores/dashboard-store-defaults";
import { metricsExplorerStore } from "@rilldata/web-common/features/dashboards/stores/dashboard-stores";
import { createAndExpression } from "@rilldata/web-common/features/dashboards/stores/filter-utils";
import type { MetricsExplorerEntity } from "@rilldata/web-common/features/dashboards/stores/metrics-explorer-entity";
Expand All @@ -15,12 +14,15 @@ import {
AD_BIDS_SCHEMA,
AD_BIDS_TIME_RANGE_SUMMARY,
} from "@rilldata/web-common/features/dashboards/stores/test-data/data";
import { convertPresetToExploreState } from "@rilldata/web-common/features/dashboards/url-state/convertPresetToExploreState";
import { getDefaultExplorePreset } from "@rilldata/web-common/features/dashboards/url-state/getDefaultExplorePreset";
import type { ExploreValidSpecResponse } from "@rilldata/web-common/features/explores/selectors";
import type { DashboardTimeControls } from "@rilldata/web-common/lib/time/types";
import {
type V1ExploreSpec,
type V1Expression,
type V1MetricsViewSpec,
type V1MetricsViewTimeRangeResponse,
} from "@rilldata/web-common/runtime-client";
import { deepClone } from "@vitest/utils";
import { get } from "svelte/store";
Expand All @@ -36,32 +38,40 @@ export function resetDashboardStore() {
export function initAdBidsInStore() {
metricsExplorerStore.init(
AD_BIDS_EXPLORE_NAME,
AD_BIDS_METRICS_INIT,
AD_BIDS_EXPLORE_INIT,
AD_BIDS_TIME_RANGE_SUMMARY,
getInitExploreStateForTest(
AD_BIDS_METRICS_INIT,
AD_BIDS_EXPLORE_INIT,
AD_BIDS_TIME_RANGE_SUMMARY,
),
);
}

export function initAdBidsMirrorInStore() {
metricsExplorerStore.init(
AD_BIDS_MIRROR_NAME,
AD_BIDS_METRICS_INIT,
AD_BIDS_EXPLORE_INIT,
AD_BIDS_TIME_RANGE_SUMMARY,
getInitExploreStateForTest(
AD_BIDS_METRICS_INIT,
AD_BIDS_EXPLORE_INIT,
AD_BIDS_TIME_RANGE_SUMMARY,
),
);
}

export function createDashboardState(
name: string,
metrics: V1MetricsViewSpec,
explore: V1ExploreSpec,
whereFilter: V1Expression = createAndExpression([]),
timeRange: DashboardTimeControls = AD_BIDS_DEFAULT_TIME_RANGE,
): MetricsExplorerEntity {
const explorer = getDefaultExploreState(name, metrics, explore, undefined);
explorer.whereFilter = whereFilter;
explorer.selectedTimeRange = timeRange;
return explorer;
export function getInitExploreStateForTest(
metricsViewSpec: V1MetricsViewSpec,
exploreSpec: V1ExploreSpec,
timeRangeSummary: V1MetricsViewTimeRangeResponse | undefined = undefined,
) {
const defaultExplorePreset = getDefaultExplorePreset(
exploreSpec,
timeRangeSummary,
);
const { partialExploreState } = convertPresetToExploreState(
metricsViewSpec,
exploreSpec,
defaultExplorePreset,
);
return partialExploreState;
}

export function createAdBidsMirrorInStore({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
convertFilterParamToExpression,
stripParserError,
} from "@rilldata/web-common/features/dashboards/url-state/filters/converters";
import { getExploreStateFromSessionStorage } from "@rilldata/web-common/features/dashboards/url-state/getExploreStateFromSessionStorage";
import {
FromURLParamsSortTypeMap,
FromURLParamTimeDimensionMap,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
AD_BIDS_NAME,
AD_BIDS_TIME_RANGE_SUMMARY,
} from "@rilldata/web-common/features/dashboards/stores/test-data/data";
import { getInitExploreStateForTest } from "@rilldata/web-common/features/dashboards/stores/test-data/helpers";
import {
AD_BIDS_APPLY_PUB_DIMENSION_FILTER,
AD_BIDS_OPEN_PIVOT_WITH_ALL_FIELDS,
Expand Down Expand Up @@ -228,9 +229,11 @@ describe("ExploreWebViewStore", () => {
it(title, () => {
metricsExplorerStore.init(
AD_BIDS_EXPLORE_NAME,
AD_BIDS_METRICS_3_MEASURES_DIMENSIONS,
AD_BIDS_EXPLORE_INIT,
AD_BIDS_TIME_RANGE_SUMMARY,
getInitExploreStateForTest(
AD_BIDS_METRICS_3_MEASURES_DIMENSIONS,
AD_BIDS_EXPLORE_INIT,
AD_BIDS_TIME_RANGE_SUMMARY,
),
);
createStateManagers({
queryClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
AD_BIDS_METRICS_3_MEASURES_DIMENSIONS,
AD_BIDS_TIME_RANGE_SUMMARY,
} from "@rilldata/web-common/features/dashboards/stores/test-data/data";
import { getInitExploreStateForTest } from "@rilldata/web-common/features/dashboards/stores/test-data/helpers";
import { getDefaultExplorePreset } from "@rilldata/web-common/features/dashboards/url-state/getDefaultExplorePreset";
import {
applyURLToExploreState,
Expand Down Expand Up @@ -151,9 +152,11 @@ describe("Invalid Human readable URL State", () => {
it(title, () => {
metricsExplorerStore.init(
AD_BIDS_EXPLORE_NAME,
AD_BIDS_METRICS_3_MEASURES_DIMENSIONS,
AD_BIDS_EXPLORE_INIT,
AD_BIDS_TIME_RANGE_SUMMARY,
getInitExploreStateForTest(
AD_BIDS_METRICS_3_MEASURES_DIMENSIONS,
AD_BIDS_EXPLORE_INIT,
AD_BIDS_TIME_RANGE_SUMMARY,
),
);
const initState = getCleanMetricsExploreForAssertion();
const defaultExplorePreset = getDefaultExplorePreset(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
AD_BIDS_TIME_DIMENSION_DETAILS_PRESET,
AD_BIDS_TIME_RANGE_SUMMARY,
} from "@rilldata/web-common/features/dashboards/stores/test-data/data";
import { getInitExploreStateForTest } from "@rilldata/web-common/features/dashboards/stores/test-data/helpers";
import {
AD_BIDS_CLOSE_DIMENSION_TABLE,
AD_BIDS_CLOSE_TDD,
Expand Down Expand Up @@ -343,9 +344,11 @@ describe("Human readable URL state variations", () => {
};
metricsExplorerStore.init(
AD_BIDS_EXPLORE_NAME,
AD_BIDS_METRICS_3_MEASURES_DIMENSIONS,
explore,
AD_BIDS_TIME_RANGE_SUMMARY,
getInitExploreStateForTest(
AD_BIDS_METRICS_3_MEASURES_DIMENSIONS,
explore,
AD_BIDS_TIME_RANGE_SUMMARY,
),
);
const initState = getCleanMetricsExploreForAssertion();
const defaultExplorePreset = getDefaultExplorePreset(
Expand Down Expand Up @@ -389,9 +392,11 @@ describe("Human readable URL state variations", () => {
};
metricsExplorerStore.init(
AD_BIDS_EXPLORE_NAME,
AD_BIDS_METRICS_3_MEASURES_DIMENSIONS,
explore,
AD_BIDS_TIME_RANGE_SUMMARY,
getInitExploreStateForTest(
AD_BIDS_METRICS_3_MEASURES_DIMENSIONS,
explore,
AD_BIDS_TIME_RANGE_SUMMARY,
),
);
const defaultExplorePreset = getDefaultExplorePreset(
explore,
Expand All @@ -408,8 +413,6 @@ describe("Human readable URL state variations", () => {
url.searchParams.set("state", getProtoFromDashboardState(curState));
// get back the entity from url params
const { partialExploreState: entityFromUrl } = convertURLToExploreState(
AD_BIDS_EXPLORE_NAME,
undefined,
url.searchParams,
AD_BIDS_METRICS_3_MEASURES_DIMENSIONS,
explore,
Expand All @@ -421,8 +424,6 @@ describe("Human readable URL state variations", () => {
const defaultUrl = new URL("http://localhost");
const { partialExploreState: entityFromDefaultUrl } =
convertURLToExploreState(
AD_BIDS_EXPLORE_NAME,
undefined,
defaultUrl.searchParams,
AD_BIDS_METRICS_3_MEASURES_DIMENSIONS,
explore,
Expand All @@ -443,8 +444,6 @@ export function applyURLToExploreState(
) {
const { partialExploreState: partialExploreStateDefaultUrl, errors } =
convertURLToExploreState(
AD_BIDS_EXPLORE_NAME,
undefined,
url.searchParams,
AD_BIDS_METRICS_3_MEASURES_DIMENSIONS,
exploreSpec,
Expand Down

0 comments on commit 3fc4354

Please sign in to comment.