feature flag support in AI test
This commit is contained in:
parent
7c918302a9
commit
53b28218cf
|
@ -1,7 +1,7 @@
|
||||||
import { it, expect, describe, vi } from "vitest"
|
import { it, expect, describe, vi } from "vitest"
|
||||||
import AISettings from "./index.svelte"
|
import AISettings from "./index.svelte"
|
||||||
import { render, fireEvent } from "@testing-library/svelte"
|
import { render, fireEvent } from "@testing-library/svelte"
|
||||||
import { admin, licensing } from "stores/portal"
|
import { admin, licensing, featureFlags } from "stores/portal"
|
||||||
import { notifications } from "@budibase/bbui"
|
import { notifications } from "@budibase/bbui"
|
||||||
|
|
||||||
vi.spyOn(notifications, "error").mockImplementation(vi.fn)
|
vi.spyOn(notifications, "error").mockImplementation(vi.fn)
|
||||||
|
@ -12,12 +12,17 @@ const Hosting = {
|
||||||
Self: "self",
|
Self: "self",
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupEnv(hosting, features = {}) {
|
function setupEnv(hosting, features = {}, flags = {}) {
|
||||||
const defaultFeatures = {
|
const defaultFeatures = {
|
||||||
budibaseAIEnabled: false,
|
budibaseAIEnabled: false,
|
||||||
customAIConfigsEnabled: false,
|
customAIConfigsEnabled: false,
|
||||||
...features,
|
...features,
|
||||||
}
|
}
|
||||||
|
const defaultFlags = {
|
||||||
|
BUDIBASE_AI: false,
|
||||||
|
AI_CUSTOM_CONFIGS: false,
|
||||||
|
...flags,
|
||||||
|
}
|
||||||
admin.subscribe = vi.fn().mockImplementation(callback => {
|
admin.subscribe = vi.fn().mockImplementation(callback => {
|
||||||
callback({ cloud: hosting === Hosting.Cloud })
|
callback({ cloud: hosting === Hosting.Cloud })
|
||||||
return () => {}
|
return () => {}
|
||||||
|
@ -26,6 +31,10 @@ function setupEnv(hosting, features = {}) {
|
||||||
callback(defaultFeatures)
|
callback(defaultFeatures)
|
||||||
return () => {}
|
return () => {}
|
||||||
})
|
})
|
||||||
|
featureFlags.subscribe = vi.fn().mockImplementation(callback => {
|
||||||
|
callback(defaultFlags)
|
||||||
|
return () => {}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("AISettings", () => {
|
describe("AISettings", () => {
|
||||||
|
@ -72,7 +81,11 @@ describe("AISettings", () => {
|
||||||
let addConfigurationButton
|
let addConfigurationButton
|
||||||
let configModal
|
let configModal
|
||||||
|
|
||||||
setupEnv(Hosting.Cloud, { customAIConfigsEnabled: true })
|
setupEnv(
|
||||||
|
Hosting.Cloud,
|
||||||
|
{ customAIConfigsEnabled: true },
|
||||||
|
{ AI_CUSTOM_CONFIGS: true }
|
||||||
|
)
|
||||||
instance = render(AISettings)
|
instance = render(AISettings)
|
||||||
addConfigurationButton = instance.queryByText("Add configuration")
|
addConfigurationButton = instance.queryByText("Add configuration")
|
||||||
expect(addConfigurationButton).toBeInTheDocument()
|
expect(addConfigurationButton).toBeInTheDocument()
|
||||||
|
@ -85,7 +98,11 @@ describe("AISettings", () => {
|
||||||
let addConfigurationButton
|
let addConfigurationButton
|
||||||
let configModal
|
let configModal
|
||||||
|
|
||||||
setupEnv(Hosting.Self, { customAIConfigsEnabled: true })
|
setupEnv(
|
||||||
|
Hosting.Self,
|
||||||
|
{ customAIConfigsEnabled: true },
|
||||||
|
{ AI_CUSTOM_CONFIGS: true }
|
||||||
|
)
|
||||||
instance = render(AISettings)
|
instance = render(AISettings)
|
||||||
addConfigurationButton = instance.queryByText("Add configuration")
|
addConfigurationButton = instance.queryByText("Add configuration")
|
||||||
expect(addConfigurationButton).toBeInTheDocument()
|
expect(addConfigurationButton).toBeInTheDocument()
|
||||||
|
|
Loading…
Reference in New Issue