From 3fc4354d24f207212cf03ef1682217c676922295 Mon Sep 17 00:00:00 2001 From: Aditya Hegde Date: Thu, 12 Dec 2024 12:40:50 +0530 Subject: [PATCH] Update tests --- .../proto-state/sparse-proto.spec.ts | 9 +- .../stores/AdvancedMeasureCorrector.spec.ts | 9 +- .../stores/dashboard-stores.spec.ts | 99 ++++++++++--------- .../dashboards/stores/test-data/helpers.ts | 46 +++++---- .../url-state/convertURLToExplorePreset.ts | 1 - .../url-state/explore-web-view-store.spec.ts | 9 +- .../invalid-url-state-variations.spec.ts | 9 +- .../url-state/url-state-variations.spec.ts | 23 +++-- 8 files changed, 112 insertions(+), 93 deletions(-) diff --git a/web-common/src/features/dashboards/proto-state/sparse-proto.spec.ts b/web-common/src/features/dashboards/proto-state/sparse-proto.spec.ts index 45bc03e7ee4..dec8b32a118 100644 --- a/web-common/src/features/dashboards/proto-state/sparse-proto.spec.ts +++ b/web-common/src/features/dashboards/proto-state/sparse-proto.spec.ts @@ -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"; @@ -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); diff --git a/web-common/src/features/dashboards/stores/AdvancedMeasureCorrector.spec.ts b/web-common/src/features/dashboards/stores/AdvancedMeasureCorrector.spec.ts index 566c8273cb9..82d91527546 100644 --- a/web-common/src/features/dashboards/stores/AdvancedMeasureCorrector.spec.ts +++ b/web-common/src/features/dashboards/stores/AdvancedMeasureCorrector.spec.ts @@ -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, @@ -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; @@ -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 = [ diff --git a/web-common/src/features/dashboards/stores/dashboard-stores.spec.ts b/web-common/src/features/dashboards/stores/dashboard-stores.spec.ts index f9cd1140612..4e987bf03b7 100644 --- a/web-common/src/features/dashboards/stores/dashboard-stores.spec.ts +++ b/web-common/src/features/dashboards/stores/dashboard-stores.spec.ts @@ -26,6 +26,7 @@ import { assertMetricsView, assertMetricsViewRaw, createAdBidsMirrorInStore, + getInitExploreStateForTest, initStateManagers, resetDashboardStore, } from "@rilldata/web-common/features/dashboards/stores/test-data/helpers"; @@ -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, @@ -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]; @@ -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(); @@ -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); diff --git a/web-common/src/features/dashboards/stores/test-data/helpers.ts b/web-common/src/features/dashboards/stores/test-data/helpers.ts index d382dcca79a..b7fab18b601 100644 --- a/web-common/src/features/dashboards/stores/test-data/helpers.ts +++ b/web-common/src/features/dashboards/stores/test-data/helpers.ts @@ -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"; @@ -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"; @@ -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({ diff --git a/web-common/src/features/dashboards/url-state/convertURLToExplorePreset.ts b/web-common/src/features/dashboards/url-state/convertURLToExplorePreset.ts index 4537eb0e579..cd4c4e3ec77 100644 --- a/web-common/src/features/dashboards/url-state/convertURLToExplorePreset.ts +++ b/web-common/src/features/dashboards/url-state/convertURLToExplorePreset.ts @@ -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, diff --git a/web-common/src/features/dashboards/url-state/explore-web-view-store.spec.ts b/web-common/src/features/dashboards/url-state/explore-web-view-store.spec.ts index cd6266fab5d..c58ac9a46fb 100644 --- a/web-common/src/features/dashboards/url-state/explore-web-view-store.spec.ts +++ b/web-common/src/features/dashboards/url-state/explore-web-view-store.spec.ts @@ -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, @@ -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, diff --git a/web-common/src/features/dashboards/url-state/invalid-url-state-variations.spec.ts b/web-common/src/features/dashboards/url-state/invalid-url-state-variations.spec.ts index b5045f486bf..05620b75ae0 100644 --- a/web-common/src/features/dashboards/url-state/invalid-url-state-variations.spec.ts +++ b/web-common/src/features/dashboards/url-state/invalid-url-state-variations.spec.ts @@ -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, @@ -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( diff --git a/web-common/src/features/dashboards/url-state/url-state-variations.spec.ts b/web-common/src/features/dashboards/url-state/url-state-variations.spec.ts index 19270564f81..5bbf80f892c 100644 --- a/web-common/src/features/dashboards/url-state/url-state-variations.spec.ts +++ b/web-common/src/features/dashboards/url-state/url-state-variations.spec.ts @@ -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, @@ -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( @@ -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, @@ -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, @@ -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, @@ -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,