forked from metabase/metabase
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(admin/performance): Fix default time bug in Schedule policy (meta…
…base#45915) Closes metabase#45916
- Loading branch information
Showing
13 changed files
with
522 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
e2e/test/scenarios/admin/performance/helpers/e2e-performance-helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import dayjs from "dayjs"; | ||
import duration from "dayjs/plugin/duration"; | ||
import relativeTime from "dayjs/plugin/relativeTime"; | ||
|
||
dayjs.extend(duration); | ||
dayjs.extend(relativeTime); | ||
|
||
/** Intercept routes for caching tests */ | ||
export const interceptRoutes = () => { | ||
cy.intercept("POST", "/api/dataset").as("dataset"); | ||
cy.intercept("POST", "/api/card/*/query").as("cardQuery"); | ||
cy.intercept("PUT", "/api/cache").as("putCacheConfig"); | ||
cy.intercept("DELETE", "/api/cache").as("deleteCacheConfig"); | ||
cy.intercept("GET", "/api/cache?model=*&id=*").as("getCacheConfig"); | ||
cy.intercept("POST", "/api/dashboard/*/dashcard/*/card/*/query").as( | ||
"dashcardQuery", | ||
); | ||
cy.intercept("POST", "/api/persist/enable").as("enablePersistence"); | ||
cy.intercept("POST", "/api/persist/disable").as("disablePersistence"); | ||
cy.intercept("POST", "/api/cache/invalidate?include=overrides&database=*").as( | ||
"invalidateCacheForSampleDatabase", | ||
); | ||
}; | ||
|
||
/** Cypress log messages sometimes occur out of order so it is helpful to log to the console as well. */ | ||
export const log = (message: string) => { | ||
cy.log(message); | ||
console.log(message); | ||
}; | ||
|
||
export const databaseCachingSettingsPage = () => | ||
cy.findByRole("main", { name: "Database caching settings" }); |
93 changes: 93 additions & 0 deletions
93
e2e/test/scenarios/admin/performance/helpers/e2e-strategy-form-helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { | ||
type ScheduleComponentType, | ||
getScheduleComponentLabel, | ||
} from "metabase/components/Schedule/constants"; | ||
import type { CacheStrategyType, CacheableModel } from "metabase-types/api"; | ||
|
||
import { databaseCachingSettingsPage } from "./e2e-performance-helpers"; | ||
|
||
/** Save the cache strategy form and wait for a response from the relevant endpoint */ | ||
export const saveCacheStrategyForm = (options?: { | ||
strategyType?: CacheStrategyType; | ||
/** 'Model' as in 'type of object' */ | ||
model?: CacheableModel; | ||
}) => { | ||
let expectedRoute: string; | ||
if (options?.strategyType === "nocache" && options?.model === "root") { | ||
// When setting the default policy to "Don't cache", we delete the policy in the BE | ||
expectedRoute = "@deleteCacheConfig"; | ||
} else if (options?.strategyType === "inherit") { | ||
// When setting a database's policy to "Use default", we delete the policy in the BE | ||
expectedRoute = "@deleteCacheConfig"; | ||
} else { | ||
// Otherwise we update the cache config | ||
expectedRoute = "@putCacheConfig"; | ||
} | ||
cy.log("Save the cache strategy form"); | ||
cacheStrategyForm().button(/Save/).click(); | ||
return cy.wait(expectedRoute); | ||
}; | ||
|
||
export const cacheStrategyForm = () => | ||
cy.findByLabelText("Select the cache invalidation policy"); | ||
|
||
export const cacheStrategyRadioButton = (name: RegExp) => | ||
cacheStrategyForm().findByRole("radio", { name }); | ||
|
||
export const durationRadioButton = () => cacheStrategyRadioButton(/Duration/); | ||
export const adaptiveRadioButton = () => cacheStrategyRadioButton(/Adaptive/); | ||
export const scheduleRadioButton = () => cacheStrategyRadioButton(/Schedule/); | ||
export const dontCacheResultsRadioButton = () => | ||
cacheStrategyRadioButton(/Don.t cache results/); | ||
export const useDefaultRadioButton = () => | ||
cacheStrategyRadioButton(/Use default/); | ||
|
||
export const formLauncher = ( | ||
itemName: string, | ||
preface: | ||
| "currently" | ||
| "currently inheriting" | ||
| "currently inheriting the default policy", | ||
strategyLabel = "", | ||
) => { | ||
databaseCachingSettingsPage().should("exist"); | ||
const regExp = new RegExp(`Edit.*${itemName}.*${preface}.*${strategyLabel}`); | ||
cy.log(`Finding strategy for launcher for regular expression: ${regExp}`); | ||
const launcher = databaseCachingSettingsPage().findByLabelText(regExp); | ||
launcher.should("exist"); | ||
return launcher; | ||
}; | ||
|
||
export const openStrategyFormForDatabaseOrDefaultPolicy = ( | ||
/** To open the form for the default policy, set this parameter to "default policy" */ | ||
databaseNameOrDefaultPolicy: string, | ||
currentStrategyLabel?: string, | ||
) => { | ||
cy.visit("/admin/performance"); | ||
cy.findByRole("tab", { name: "Database caching settings" }).click(); | ||
cy.log(`Open strategy form for ${databaseNameOrDefaultPolicy}`); | ||
formLauncher( | ||
databaseNameOrDefaultPolicy, | ||
"currently", | ||
currentStrategyLabel, | ||
).click(); | ||
}; | ||
|
||
export const getScheduleComponent = (componentType: ScheduleComponentType) => | ||
cacheStrategyForm().findByLabelText(getScheduleComponentLabel(componentType)); | ||
|
||
export const openSidebar = () => { | ||
cy.findByLabelText("info icon").click(); | ||
}; | ||
export const closeSidebar = () => { | ||
cy.findByLabelText("info icon").click(); | ||
}; | ||
|
||
/** Open the sidebar form that lets you set the caching strategy. | ||
* This works on dashboards and questions */ | ||
export const openSidebarCacheStrategyForm = () => { | ||
cy.log("Open the cache strategy form in the sidebar"); | ||
openSidebar(); | ||
cy.wait("@getCacheConfig"); | ||
cy.findByLabelText("Caching policy").click(); | ||
}; |
Oops, something went wrong.