Skip to content

Commit

Permalink
Fix unit tests - Pass 3
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaHegde committed Sep 25, 2024
1 parent aa1870c commit 81d593c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
useDashboardDefaultProto,
useDashboardUrlSync,
} from "@rilldata/web-common/features/dashboards/proto-state/dashboard-url-state";
import { getDashboardStateFromUrl } from "@rilldata/web-common/features/dashboards/proto-state/fromProto";
import { getProtoFromDashboardState } from "@rilldata/web-common/features/dashboards/proto-state/toProto";
import { metricsExplorerStore } from "@rilldata/web-common/features/dashboards/stores/dashboard-stores";
import {
Expand Down Expand Up @@ -79,7 +78,7 @@ describe("useDashboardUrlSync", () => {

beforeEach(() => {
resetDashboardStore();
pageMock.goto("/dashboard/AdBids");
pageMock.goto(`/explore/${AD_BIDS_EXPLORE_NAME}`);
pageMock.gotoSpy.mockClear();
});

Expand Down Expand Up @@ -222,21 +221,21 @@ type PageMock = Readable<Page> & {
};
function createPageMock() {
const { update, subscribe } = writable<Page>({
url: new URL("http://localhost/dashboard/AdBids"),
params: { name: "AdBids" },
url: new URL("http://localhost/explore/AdBids_explore"),
params: { name: "AdBids_explore" },
} as any);

pageMock.subscribe = subscribe;
pageMock.updateState = (state: string) => {
update((page) => {
if (state) {
page.url = new URL(
`http://localhost/dashboard/AdBids?state=${encodeURIComponent(
`http://localhost/explore/AdBids_explore?state=${encodeURIComponent(
state,
)}`,
);
} else {
page.url = new URL("http://localhost/dashboard/AdBids");
page.url = new URL("http://localhost/explore/AdBids_explore");
}
return page;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
AD_BIDS_EXPLORE_INIT,
AD_BIDS_EXPLORE_NAME,
AD_BIDS_METRICS_INIT,
AD_BIDS_NAME,
AD_BIDS_SCHEMA,
AD_BIDS_TIME_RANGE_SUMMARY,
} from "@rilldata/web-common/features/dashboards/stores/test-data/data";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export function createStateManagers({
const validSpecStore: Readable<
QueryObserverResult<ValidExploreResponse, RpcStatus>
> = derived([runtime, exploreNameStore], ([r, exploreName], set) =>
useValidExplore(r.instanceId, exploreName).subscribe(set),
useValidExplore(r.instanceId, exploreName, { queryClient }).subscribe(set),
);

const timeRangeSummaryStore: Readable<
Expand All @@ -110,7 +110,7 @@ export function createStateManagers({
{},
{
query: {
queryClient: queryClient,
queryClient,
enabled: !!validSpec?.data?.metricsView?.timeDimension,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ describe("time-control-store", () => {
"2022-04-01T00:00:00.000Z",
);

console.log("refetch");
dashboardFetchMocks.mockMetricsExplore(
AD_BIDS_EXPLORE_NAME,
AD_BIDS_METRICS_INIT_WITH_TIME,
Expand Down
33 changes: 25 additions & 8 deletions web-common/src/features/explores/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
RpcStatus,
V1ExploreSpec,
V1GetExploreResponse,
V1GetResourceResponse,

Check failure on line 8 in web-common/src/features/explores/selectors.ts

View workflow job for this annotation

GitHub Actions / build

'V1GetResourceResponse' is defined but never used
type V1MetricsViewSpec,
} from "@rilldata/web-common/runtime-client";
import { ErrorType } from "@rilldata/web-common/runtime-client/http-client";
Expand All @@ -31,19 +32,35 @@ export type ValidExploreResponse = {
explore: V1ExploreSpec | undefined;
metricsView: V1MetricsViewSpec | undefined;
};
export function useValidExplore(instanceId: string, exploreName: string) {
export function useValidExplore(
instanceId: string,
exploreName: string,
queryOptions?: CreateQueryOptions<
V1GetExploreResponse,
ErrorType<RpcStatus>,
ValidExploreResponse
>,
) {
const defaultQueryOptions: CreateQueryOptions<
V1GetExploreResponse,
ErrorType<RpcStatus>,
ValidExploreResponse
> = {
select: (data) =>
<ValidExploreResponse>{
explore: data.explore?.explore?.state?.validSpec,
metricsView: data.metricsView?.metricsView?.state?.validSpec,
},
queryClient,
enabled: !!exploreName,
};
return createRuntimeServiceGetExplore(
instanceId,
{ name: exploreName },
{
query: {
select: (data) =>
<ValidExploreResponse>{
explore: data.explore?.explore?.state?.validSpec,
metricsView: data.metricsView?.metricsView?.state?.validSpec,
},
queryClient,
enabled: !!exploreName,
...defaultQueryOptions,
...queryOptions,
},
},
);
Expand Down

0 comments on commit 81d593c

Please sign in to comment.