The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Stop unit specs waiting on debounce and poll timers they do not assert (#84006)
Romeo Van Snick0ae75a7203aa
diff --git a/enterprise/frontend/src/metabase-enterprise/caching/components/StrategyEditorForDatabases.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/caching/components/StrategyEditorForDatabases.unit.spec.tsxindex 47b4097d1c9..cd709e60327 100644--- a/enterprise/frontend/src/metabase-enterprise/caching/components/StrategyEditorForDatabases.unit.spec.tsx+++ b/enterprise/frontend/src/metabase-enterprise/caching/components/StrategyEditorForDatabases.unit.spec.tsx@@ -22,6 +22,13 @@ import {createMockTokenFeatures,} from "metabase-types/api/mocks";+// The search debounce is idle time in these tests: they assert what a search+// returns, not that the input waits before it asks.+jest.mock("metabase/utils/constants", () => ({+ ...jest.requireActual("metabase/utils/constants"),+ SEARCH_DEBOUNCE_DURATION: 0,+}));+function setup(opts: SetupOpts = {}) {baseSetup({enterprisePlugins: "*", // TODO be more granular about thisdiff --git a/enterprise/frontend/src/metabase-enterprise/caching/components/StrategyEditorForQuestionsAndDashboards/StrategyEditorForQuestionsAndDashboards.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/caching/components/StrategyEditorForQuestionsAndDashboards/StrategyEditorForQuestionsAndDashboards.unit.spec.tsxindex df0a614bea2..a682e03ff91 100644--- a/enterprise/frontend/src/metabase-enterprise/caching/components/StrategyEditorForQuestionsAndDashboards/StrategyEditorForQuestionsAndDashboards.unit.spec.tsx+++ b/enterprise/frontend/src/metabase-enterprise/caching/components/StrategyEditorForQuestionsAndDashboards/StrategyEditorForQuestionsAndDashboards.unit.spec.tsx@@ -30,6 +30,13 @@ import {import { StrategyEditorForQuestionsAndDashboards } from "./StrategyEditorForQuestionsAndDashboards";+// The search debounce is idle time in these tests: they assert what a search+// returns, not that the input waits before it asks.+jest.mock("metabase/utils/constants", () => ({+ ...jest.requireActual("metabase/utils/constants"),+ SEARCH_DEBOUNCE_DURATION: 0,+}));+const ROOT_STRATEGY: CacheStrategy = {type: "duration",duration: 1,diff --git a/enterprise/frontend/src/metabase-enterprise/database_replication/DatabaseReplicationModal.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/database_replication/DatabaseReplicationModal.unit.spec.tsxindex 786e55f5dcc..26921039bb3 100644--- a/enterprise/frontend/src/metabase-enterprise/database_replication/DatabaseReplicationModal.unit.spec.tsx+++ b/enterprise/frontend/src/metabase-enterprise/database_replication/DatabaseReplicationModal.unit.spec.tsx@@ -8,6 +8,13 @@ import { createMockDatabase } from "metabase-types/api/mocks";import { DatabaseReplicationModal } from "./DatabaseReplicationModal";+// The search debounce is idle time in these tests: they assert what a search+// returns, not that the input waits before it asks.+jest.mock("metabase/utils/constants", () => ({+ ...jest.requireActual("metabase/utils/constants"),+ SEARCH_DEBOUNCE_DURATION: 0,+}));+const mockPreviewResponse: PreviewDatabaseReplicationResponse = {canSetReplication: true,freeQuota: 1000000,diff --git a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotAdmin/MetabaseAIProviderSetup.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotAdmin/MetabaseAIProviderSetup.unit.spec.tsxindex 4421c805ae2..b9644e2e637 100644--- a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotAdmin/MetabaseAIProviderSetup.unit.spec.tsx+++ b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotAdmin/MetabaseAIProviderSetup.unit.spec.tsx@@ -36,6 +36,13 @@ import {getMetabaseUsageCost,} from "./MetabaseAIProviderSetup";+// These tests assert that the setup modal waits for the token refresh to report+// the feature, not how long it waits between polls.+jest.mock("metabase/settings/use-token-refresh", () => ({+ ...jest.requireActual("metabase/settings/use-token-refresh"),+ WAITING_REFRESH_INTERVAL: 50,+}));+type MetabotUsageQuota = {tokens?: number | null;free_tokens?: number | null;diff --git a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotAdmin/MetabotSettingUpModal.tsx b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotAdmin/MetabotSettingUpModal.tsxindex c55158c3782..67c68d26724 100644--- a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotAdmin/MetabotSettingUpModal.tsx+++ b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotAdmin/MetabotSettingUpModal.tsx@@ -1,7 +1,10 @@import { t } from "ttag";import { MetabotLogo } from "metabase/common/components/MetabotLogo";-import { useTokenRefreshUntil } from "metabase/settings";+import {+ WAITING_REFRESH_INTERVAL,+ useTokenRefreshUntil,+} from "metabase/settings";import {Box,Button,@@ -28,7 +31,7 @@ export function MetabotSettingUpModal({isSavingConfiguration || !hasPremiumFeature(METABASE_MANAGED_AI_FEATURE);useTokenRefreshUntil(METABASE_MANAGED_AI_FEATURE, {- intervalMs: 1000,+ intervalMs: WAITING_REFRESH_INTERVAL,skip: !opened || !isSettingUp,});diff --git a/enterprise/frontend/src/metabase-enterprise/multi_factor_auth/components/EnrolledUsersPage/EnrolledUsersPage.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/multi_factor_auth/components/EnrolledUsersPage/EnrolledUsersPage.unit.spec.tsxindex acca261f952..81fb8f010f8 100644--- a/enterprise/frontend/src/metabase-enterprise/multi_factor_auth/components/EnrolledUsersPage/EnrolledUsersPage.unit.spec.tsx+++ b/enterprise/frontend/src/metabase-enterprise/multi_factor_auth/components/EnrolledUsersPage/EnrolledUsersPage.unit.spec.tsx@@ -21,6 +21,13 @@ import {import { EnrolledUsersPage } from "./EnrolledUsersPage";+// The search debounce is idle time in these tests: they assert what a search+// returns, not that the input waits before it asks.+jest.mock("metabase/utils/constants", () => ({+ ...jest.requireActual("metabase/utils/constants"),+ SEARCH_DEBOUNCE_DURATION: 0,+}));+const CURRENT_USER_ID = 1;const OTHER_USER = createMockMfaEnrolledUser({diff --git a/enterprise/frontend/src/metabase-enterprise/multi_factor_auth/components/UnenrolledUsersPage/UnenrolledUsersPage.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/multi_factor_auth/components/UnenrolledUsersPage/UnenrolledUsersPage.unit.spec.tsxindex 36d2f1dcf6a..a30ca328d2f 100644--- a/enterprise/frontend/src/metabase-enterprise/multi_factor_auth/components/UnenrolledUsersPage/UnenrolledUsersPage.unit.spec.tsx+++ b/enterprise/frontend/src/metabase-enterprise/multi_factor_auth/components/UnenrolledUsersPage/UnenrolledUsersPage.unit.spec.tsx@@ -13,6 +13,13 @@ import type { MfaAdminUser } from "metabase-types/api";import { UnenrolledUsersPage } from "./UnenrolledUsersPage";+// The search debounce is idle time in these tests: they assert what a search+// returns, not that the input waits before it asks.+jest.mock("metabase/utils/constants", () => ({+ ...jest.requireActual("metabase/utils/constants"),+ SEARCH_DEBOUNCE_DURATION: 0,+}));+type SetupOpts = {users?: MfaAdminUser[];hasError?: boolean;diff --git a/enterprise/frontend/src/metabase-enterprise/transforms/upsells/components/TransformsSettingUpModal.tsx b/enterprise/frontend/src/metabase-enterprise/transforms/upsells/components/TransformsSettingUpModal.tsxindex 07c9808a762..c8cdda8b9b5 100644--- a/enterprise/frontend/src/metabase-enterprise/transforms/upsells/components/TransformsSettingUpModal.tsx+++ b/enterprise/frontend/src/metabase-enterprise/transforms/upsells/components/TransformsSettingUpModal.tsx@@ -1,6 +1,9 @@import { t } from "ttag";-import { useTokenRefreshUntil } from "metabase/settings";+import {+ WAITING_REFRESH_INTERVAL,+ useTokenRefreshUntil,+} from "metabase/settings";import {Box,Button,@@ -28,7 +31,10 @@ export const TransformsSettingUpModal = ({isPython = false,}: TransformsSettingUpModalProps) => {const featureToCheck = isPython ? "transforms-python" : "transforms-basic";- useTokenRefreshUntil(featureToCheck, { intervalMs: 1000, skip: !opened });+ useTokenRefreshUntil(featureToCheck, {+ intervalMs: WAITING_REFRESH_INTERVAL,+ skip: !opened,+ });const isSettingUp = !hasPremiumFeature(featureToCheck);return (diff --git a/frontend/src/metabase/browse/tables/TableBrowser/TableBrowser.unit.spec.tsx b/frontend/src/metabase/browse/tables/TableBrowser/TableBrowser.unit.spec.tsxindex 802e375ccb0..fa592bebd87 100644--- a/frontend/src/metabase/browse/tables/TableBrowser/TableBrowser.unit.spec.tsx+++ b/frontend/src/metabase/browse/tables/TableBrowser/TableBrowser.unit.spec.tsx@@ -19,6 +19,13 @@ import {import { TableBrowser } from "./TableBrowser";+// The test asserts that the browser polls while a sync is in progress, not how+// long it waits between polls.+jest.mock("metabase/browse/constants", () => ({+ ...jest.requireActual("metabase/browse/constants"),+ RELOAD_INTERVAL: 50,+}));+describe("TableBrowser", () => {beforeEach(() => {// The database breadcrumb reads the database list that the app fetches on launch.diff --git a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/EntityPickerModal.tsx b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/EntityPickerModal.tsxindex 4c8d0838c79..62690a6ef56 100644--- a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/EntityPickerModal.tsx+++ b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/EntityPickerModal.tsx@@ -12,6 +12,7 @@ import { ActionIcon, Box, Icon, Modal, TextInput } from "metabase/ui";import resizeObserver from "metabase/utils/resize-observer";import type { RecentContexts } from "metabase-types/api";+import { SEARCH_DEBOUNCE_MS } from "../constants";import { useLogRecentItem } from "../hooks";import type {EntityPickerOptions,@@ -227,7 +228,7 @@ const SearchInput = ({const [localValue, setLocalValue] = useState(value);const debouncedOnChange = useDebouncedCallback((newValue: string) => {onChange(newValue);- }, 300);+ }, SEARCH_DEBOUNCE_MS);return (<TextInputclassNames={{ input: S.textInput }}diff --git a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/test/EntityPickerModal.unit.spec.tsx b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/test/EntityPickerModal.unit.spec.tsxindex 144c3d3327f..d23491322cd 100644--- a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/test/EntityPickerModal.unit.spec.tsx+++ b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/test/EntityPickerModal.unit.spec.tsx@@ -11,6 +11,15 @@ import type { OmniPickerItem } from "../../types";import { setup } from "./setup";+// The search debounce is idle time in these tests: they assert what a search+// returns, not that the input waits before it asks.+jest.mock("metabase/common/components/Pickers/EntityPicker/constants", () => ({+ ...jest.requireActual(+ "metabase/common/components/Pickers/EntityPicker/constants",+ ),+ SEARCH_DEBOUNCE_MS: 0,+}));+const expectActiveItem = async (itemName: string) =>waitFor(() =>expect(diff --git a/frontend/src/metabase/common/components/Pickers/EntityPicker/constants.ts b/frontend/src/metabase/common/components/Pickers/EntityPicker/constants.tsnew file mode 100644index 00000000000..7d035716a3e--- /dev/null+++ b/frontend/src/metabase/common/components/Pickers/EntityPicker/constants.ts@@ -0,0 +1,5 @@+/**+ * How long the picker's search input waits after a keystroke before it+ * searches.+ */+export const SEARCH_DEBOUNCE_MS = 300;diff --git a/frontend/src/metabase/common/components/upsells/components/UpgradeModal/UpgradeModalLoading.tsx b/frontend/src/metabase/common/components/upsells/components/UpgradeModal/UpgradeModalLoading.tsxindex 9ee73e2de53..2e50207d906 100644--- a/frontend/src/metabase/common/components/upsells/components/UpgradeModal/UpgradeModalLoading.tsx+++ b/frontend/src/metabase/common/components/upsells/components/UpgradeModal/UpgradeModalLoading.tsx@@ -1,6 +1,10 @@import { t } from "ttag";-import { useGetSettingsQuery, useTokenRefreshUntil } from "metabase/settings";+import {+ WAITING_REFRESH_INTERVAL,+ useGetSettingsQuery,+ useTokenRefreshUntil,+} from "metabase/settings";import { Button, Flex, Icon, Loader, Stack, Text, Title } from "metabase/ui";import type { UpgradeFlow } from "./types";@@ -15,7 +19,7 @@ export function UpgradeModalLoading({onDone,}: UpgradeModalLoadingProps) {// Poll every second until no-upsell feature appears- useTokenRefreshUntil("no-upsell", { intervalMs: 1000 });+ useTokenRefreshUntil("no-upsell", { intervalMs: WAITING_REFRESH_INTERVAL });const { data: settings } = useGetSettingsQuery();const tokenFeatures = settings?.["token-status"]?.features ?? [];diff --git a/frontend/src/metabase/dashboard/visualizations/LinkViz/LinkViz.unit.spec.tsx b/frontend/src/metabase/dashboard/visualizations/LinkViz/LinkViz.unit.spec.tsxindex 24e4ea3afc2..1a66b974036 100644--- a/frontend/src/metabase/dashboard/visualizations/LinkViz/LinkViz.unit.spec.tsx+++ b/frontend/src/metabase/dashboard/visualizations/LinkViz/LinkViz.unit.spec.tsx@@ -36,6 +36,13 @@ import {import type { LinkVizProps } from "./LinkViz";import { LinkViz } from "./LinkViz";+// The search debounce is idle time in these tests: they assert what a search+// returns, not that the input waits before it asks.+jest.mock("metabase/utils/constants", () => ({+ ...jest.requireActual("metabase/utils/constants"),+ SEARCH_DEBOUNCE_DURATION: 0,+}));+registerVisualizations();type LinkCardVizSettings = VirtualDashboardCard["visualization_settings"] & {diff --git a/frontend/src/metabase/data-studio/data-model/pages/DataModel/DataModel.unit.spec.tsx b/frontend/src/metabase/data-studio/data-model/pages/DataModel/DataModel.unit.spec.tsxindex 39147071534..5306e598e69 100644--- a/frontend/src/metabase/data-studio/data-model/pages/DataModel/DataModel.unit.spec.tsx+++ b/frontend/src/metabase/data-studio/data-model/pages/DataModel/DataModel.unit.spec.tsx@@ -62,6 +62,13 @@ import {import { DataModel } from "./DataModel";import type { ParsedRouteParams } from "./types";+// The search debounce is idle time in these tests: they assert what a search+// returns, not that the input waits before it asks.+jest.mock("metabase/utils/constants", () => ({+ ...jest.requireActual("metabase/utils/constants"),+ SEARCH_DEBOUNCE_DURATION: 0,+}));+registerVisualizations();const DEFAULT_ROUTE_PARAMS: ParsedRouteParams = {diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/hooks/use-initial-parameter-values.unit.spec.ts b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/hooks/use-initial-parameter-values.unit.spec.tsindex b893d975869..999cd7ddf9c 100644--- a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/hooks/use-initial-parameter-values.unit.spec.ts+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/hooks/use-initial-parameter-values.unit.spec.ts@@ -2,6 +2,15 @@ import { act, renderHook, waitFor } from "@testing-library/react";import { useInitialParameterValues } from "metabase/embedding/embedding-iframe-sdk-setup/hooks/use-initial-parameter-values";+// The search debounce is idle time in these tests: they assert what a search+// returns, not that the input waits before it asks.+jest.mock("metabase/embedding/embedding-iframe-sdk-setup/constants", () => ({+ ...jest.requireActual(+ "metabase/embedding/embedding-iframe-sdk-setup/constants",+ ),+ SET_INITIAL_PARAMETER_DEBOUNCE_MS: 0,+}));+describe("useInitialParameterValues", () => {const mockUpdateSettings = jest.fn();diff --git a/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.unit.spec.tsx b/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.unit.spec.tsxindex 84826bd93eb..90c0f310446 100644--- a/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.unit.spec.tsx+++ b/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.unit.spec.tsx@@ -24,6 +24,13 @@ import {createMockUser,} from "metabase-types/api/mocks";+// The search debounce is idle time in these tests: they assert what a search+// returns, not that the input waits before it asks.+jest.mock("metabase/utils/constants", () => ({+ ...jest.requireActual("metabase/utils/constants"),+ SEARCH_DEBOUNCE_DURATION: 0,+}));+const TEST_SEARCH_RESULTS: CollectionItem[] = ["Card ABC","Card BCD",diff --git a/frontend/src/metabase/palette/components/Palette.unit.spec.tsx b/frontend/src/metabase/palette/components/Palette.unit.spec.tsxindex 736802833f7..9239e520694 100644--- a/frontend/src/metabase/palette/components/Palette.unit.spec.tsx+++ b/frontend/src/metabase/palette/components/Palette.unit.spec.tsx@@ -19,6 +19,13 @@ import {import { Palette } from "./Palette";+// The search debounce is idle time in these tests: they assert what a search+// returns, not that the input waits before it asks.+jest.mock("metabase/utils/constants", () => ({+ ...jest.requireActual("metabase/utils/constants"),+ SEARCH_DEBOUNCE_DURATION: 0,+}));+const setup = ({initialRoute,searchResults = [],diff --git a/frontend/src/metabase/palette/components/test/PaletteResults/PaletteResults-ee.unit.spec.tsx b/frontend/src/metabase/palette/components/test/PaletteResults/PaletteResults-ee.unit.spec.tsxindex 9228e6825be..bec4ea5beed 100644--- a/frontend/src/metabase/palette/components/test/PaletteResults/PaletteResults-ee.unit.spec.tsx+++ b/frontend/src/metabase/palette/components/test/PaletteResults/PaletteResults-ee.unit.spec.tsx@@ -2,6 +2,13 @@ import { screen, within } from "__support__/ui";import { type CommonSetupProps, commonSetup } from "./setup";+// The search debounce is idle time in these tests: they assert what a search+// returns, not that the input waits before it asks.+jest.mock("metabase/utils/constants", () => ({+ ...jest.requireActual("metabase/utils/constants"),+ SEARCH_DEBOUNCE_DURATION: 0,+}));+const setup = (props: CommonSetupProps = {}) => {commonSetup({ ...props, isEE: true });};diff --git a/frontend/src/metabase/palette/components/test/PaletteResults/PaletteResults-oss.unit.spec.tsx b/frontend/src/metabase/palette/components/test/PaletteResults/PaletteResults-oss.unit.spec.tsxindex 1bb302cfb32..597cc4bdb5d 100644--- a/frontend/src/metabase/palette/components/test/PaletteResults/PaletteResults-oss.unit.spec.tsx+++ b/frontend/src/metabase/palette/components/test/PaletteResults/PaletteResults-oss.unit.spec.tsx@@ -10,6 +10,27 @@ import {import { type CommonSetupProps, commonSetup } from "./setup";+// The search debounce is idle time in all but one test here, which asserts that+// the remote search waits for it.+let searchDebounceDuration = 0;++jest.mock("metabase/utils/constants", () => ({+ ...jest.requireActual("metabase/utils/constants"),+ get SEARCH_DEBOUNCE_DURATION() {+ return searchDebounceDuration;+ },+}));++const withRealSearchDebounce = () => {+ const actual = jest.requireActual("metabase/utils/constants");+ beforeEach(() => {+ searchDebounceDuration = actual.SEARCH_DEBOUNCE_DURATION;+ });+ afterEach(() => {+ searchDebounceDuration = 0;+ });+};+const setup = (props: CommonSetupProps = {}) =>commonSetup({ ...props, isEE: false });@@ -41,14 +62,18 @@ describe("PaletteResults", () => {expect(await screen.findByText("Results")).toBeInTheDocument();});- it("should surface static actions before the remote search debounce fires", async () => {- setup({ query: "new" });+ describe("with the real search debounce", () => {+ withRealSearchDebounce();- expect(await screen.findByText("New question")).toBeInTheDocument();+ it("should surface static actions before the remote search debounce fires", async () => {+ setup({ query: "new" });- // useCommandPaletteBasicActions makes one baseline /api/search call; any- // additional call means the debounced remote search has already run.- expect(fetchMock.callHistory.calls("path:/api/search").length).toBe(1);+ expect(await screen.findByText("New question")).toBeInTheDocument();++ // useCommandPaletteBasicActions makes one baseline /api/search call; any+ // additional call means the debounced remote search has already run.+ expect(fetchMock.callHistory.calls("path:/api/search").length).toBe(1);+ });});//For some reason, New Question isn't showing up without searching. My guess is virtualization weirdnessdiff --git a/frontend/src/metabase/query_builder/components/view/sidebars/SummarizeSidebar/SummarizeSidebar.unit.spec.tsx b/frontend/src/metabase/query_builder/components/view/sidebars/SummarizeSidebar/SummarizeSidebar.unit.spec.tsxindex 5ac8ca99e95..8af2f71fa6b 100644--- a/frontend/src/metabase/query_builder/components/view/sidebars/SummarizeSidebar/SummarizeSidebar.unit.spec.tsx+++ b/frontend/src/metabase/query_builder/components/view/sidebars/SummarizeSidebar/SummarizeSidebar.unit.spec.tsx@@ -18,6 +18,13 @@ import {import { SummarizeSidebar } from "./SummarizeSidebar";+// The search debounce is idle time in these tests: they assert what a search+// returns, not that the input waits before it asks.+jest.mock("metabase/utils/constants", () => ({+ ...jest.requireActual("metabase/utils/constants"),+ SEARCH_DEBOUNCE_DURATION: 0,+}));+type SetupOpts = {query?: Lib.Query;withDefaultAggregation?: boolean;diff --git a/frontend/src/metabase/querying/filters/components/FilterPicker/FilterValuePicker/FilterValuePicker.unit.spec.tsx b/frontend/src/metabase/querying/filters/components/FilterPicker/FilterValuePicker/FilterValuePicker.unit.spec.tsxindex e2b987f807f..cc0bd9dbc72 100644--- a/frontend/src/metabase/querying/filters/components/FilterPicker/FilterValuePicker/FilterValuePicker.unit.spec.tsx+++ b/frontend/src/metabase/querying/filters/components/FilterPicker/FilterValuePicker/FilterValuePicker.unit.spec.tsx@@ -45,6 +45,34 @@ import {StringFilterValuePicker,} from "./FilterValuePicker";+// The search debounce is idle time in these tests: they assert what a search+// returns, not that the input waits before it asks.+let searchDebounce = 0;++jest.mock(+ "metabase/querying/common/components/FieldValuePicker/SearchValuePicker/constants",+ () => ({+ ...jest.requireActual(+ "metabase/querying/common/components/FieldValuePicker/SearchValuePicker/constants",+ ),+ get SEARCH_DEBOUNCE() {+ return searchDebounce;+ },+ }),+);++const withRealSearchDebounce = () => {+ const actual = jest.requireActual(+ "metabase/querying/common/components/FieldValuePicker/SearchValuePicker/constants",+ );+ beforeEach(() => {+ searchDebounce = actual.SEARCH_DEBOUNCE;+ });+ afterEach(() => {+ searchDebounce = 0;+ });+};+type EndpointOpts = {fieldId?: FieldId;searchFieldId?: FieldId;@@ -735,73 +763,79 @@ describe("StringFilterValuePicker", () => {expect(onChange).toHaveBeenLastCalledWith(["a-test"]);});- it("should allow free-form input without waiting for search results", async () => {- const { onChange } = await setupStringPicker({- query,- stageIndex,- column,- values: [],- fieldId,- searchValues: {- "[email protected]": createMockFieldValues({- field_id: fieldId,- values: [["[email protected]"]],- }),- },- });+ // These three assert what happens before the debounced search fires, so+ // they need the real delay.+ describe("before the search runs", () => {+ withRealSearchDebounce();- await userEvent.type(- screen.getByPlaceholderText("Search by Email"),- "[email protected]",- );- expect(onChange).toHaveBeenLastCalledWith(["[email protected]"]);- });-- it("should not be able to create duplicates with free-form input", async () => {- const { onChange } = await setupStringPicker({- query,- stageIndex,- column,- values: ["[email protected]"],- fieldId,- searchValues: {- "[email protected]": createMockFieldValues({- field_id: fieldId,- values: [["[email protected]"]],- }),- },+ it("should allow free-form input without waiting for search results", async () => {+ const { onChange } = await setupStringPicker({+ query,+ stageIndex,+ column,+ values: [],+ fieldId,+ searchValues: {+ "[email protected]": createMockFieldValues({+ field_id: fieldId,+ values: [["[email protected]"]],+ }),+ },+ });++ await userEvent.type(+ screen.getByPlaceholderText("Search by Email"),+ "[email protected]",+ );+ expect(onChange).toHaveBeenLastCalledWith(["[email protected]"]);});- const input = screen.getByRole("combobox", { name: "Filter value" });- await userEvent.type(input, "[email protected]");- // blurring commits the typed value; wrap it so the resulting state- // updates in MultiAutocomplete are flushed inside act()- act(() => {- input.blur();+ it("should not be able to create duplicates with free-form input", async () => {+ const { onChange } = await setupStringPicker({+ query,+ stageIndex,+ column,+ values: ["[email protected]"],+ fieldId,+ searchValues: {+ "[email protected]": createMockFieldValues({+ field_id: fieldId,+ values: [["[email protected]"]],+ }),+ },+ });++ const input = screen.getByRole("combobox", { name: "Filter value" });+ await userEvent.type(input, "[email protected]");+ // blurring commits the typed value; wrap it so the resulting state+ // updates in MultiAutocomplete are flushed inside act()+ act(() => {+ input.blur();+ });+ expect(onChange).toHaveBeenLastCalledWith(["[email protected]"]);});- expect(onChange).toHaveBeenLastCalledWith(["[email protected]"]);- });- it("should not show free-form input in search results", async () => {- const { onChange } = await setupStringPicker({- query,- stageIndex,- column,- values: ["[email protected]"],- fieldId,- searchValues: {- "a@b": createMockFieldValues({- field_id: fieldId,- values: [["[email protected]"]],- }),- },+ it("should not show free-form input in search results", async () => {+ const { onChange } = await setupStringPicker({+ query,+ stageIndex,+ column,+ values: ["[email protected]"],+ fieldId,+ searchValues: {+ "a@b": createMockFieldValues({+ field_id: fieldId,+ values: [["[email protected]"]],+ }),+ },+ });++ await userEvent.type(+ screen.getByRole("combobox", { name: "Filter value" }),+ "a@b",+ );+ expect(onChange).toHaveBeenLastCalledWith(["[email protected]", "a@b"]);});-- await userEvent.type(- screen.getByRole("combobox", { name: "Filter value" }),- "a@b",- );- expect(onChange).toHaveBeenLastCalledWith(["[email protected]", "a@b"]);});it("should trim clipboard data", async () => {diff --git a/frontend/src/metabase/querying/filters/components/FilterPicker/StringFilterPicker/StringFilterPicker.unit.spec.tsx b/frontend/src/metabase/querying/filters/components/FilterPicker/StringFilterPicker/StringFilterPicker.unit.spec.tsxindex 39ec27a7a02..08b6d96bd4d 100644--- a/frontend/src/metabase/querying/filters/components/FilterPicker/StringFilterPicker/StringFilterPicker.unit.spec.tsx+++ b/frontend/src/metabase/querying/filters/components/FilterPicker/StringFilterPicker/StringFilterPicker.unit.spec.tsx@@ -33,6 +33,18 @@ import {import { StringFilterPicker } from "./StringFilterPicker";+// The search debounce is idle time in these tests: they assert what a search+// returns, not that the input waits before it asks.+jest.mock(+ "metabase/querying/common/components/FieldValuePicker/SearchValuePicker/constants",+ () => ({+ ...jest.requireActual(+ "metabase/querying/common/components/FieldValuePicker/SearchValuePicker/constants",+ ),+ SEARCH_DEBOUNCE: 0,+ }),+);+const EXPECTED_OPERATORS = ["Is","Is not",diff --git a/frontend/src/metabase/settings/index.ts b/frontend/src/metabase/settings/index.tsindex 82f3f211587..71d776fea84 100644--- a/frontend/src/metabase/settings/index.ts+++ b/frontend/src/metabase/settings/index.ts@@ -24,7 +24,11 @@ export {export { useAdminSetting, useAdminSettings } from "./use-admin-setting";export { useSetting, useUserSetting } from "./use-setting";export { useSettingSwitch } from "./use-setting-switch";-export { useTokenRefresh, useTokenRefreshUntil } from "./use-token-refresh";+export {+ useTokenRefresh,+ useTokenRefreshUntil,+ WAITING_REFRESH_INTERVAL,+} from "./use-token-refresh";export {getPlan,hasAnySsoFeature,diff --git a/frontend/src/metabase/settings/use-token-refresh.ts b/frontend/src/metabase/settings/use-token-refresh.tsindex 5d48f62ec88..006edf9db8d 100644--- a/frontend/src/metabase/settings/use-token-refresh.ts+++ b/frontend/src/metabase/settings/use-token-refresh.ts@@ -8,6 +8,12 @@ import { useGetSettingsQuery } from "./api";const REFRESH_INTERVAL = 10 * 1000; // 10 seconds+/**+ * The interval to pass when the user is waiting for the feature to arrive, as+ * opposed to the background refresh above.+ */+export const WAITING_REFRESH_INTERVAL = 1000;+/*** In some circumstances, a metabase instance may have a temporary token signalling that we* should refresh session properties. This hook will keep refreshing the session propertiesdiff --git a/frontend/src/metabase/timelines/collections/components/TimelineDetailsModal/TimelineDetailsModal.unit.spec.tsx b/frontend/src/metabase/timelines/collections/components/TimelineDetailsModal/TimelineDetailsModal.unit.spec.tsxindex 743dc2e2008..e9d1ed0d782 100644--- a/frontend/src/metabase/timelines/collections/components/TimelineDetailsModal/TimelineDetailsModal.unit.spec.tsx+++ b/frontend/src/metabase/timelines/collections/components/TimelineDetailsModal/TimelineDetailsModal.unit.spec.tsx@@ -10,6 +10,13 @@ import {import type { TimelineDetailsModalProps } from "./TimelineDetailsModal";import TimelineDetailsModal from "./TimelineDetailsModal";+// The search debounce is idle time in these tests: they assert what a search+// returns, not that the input waits before it asks.+jest.mock("metabase/utils/constants", () => ({+ ...jest.requireActual("metabase/utils/constants"),+ SEARCH_DEBOUNCE_DURATION: 0,+}));+function setup(props: TimelineDetailsModalProps) {renderWithProviders(<TimelineDetailsModal {...props} />);}