add tests and move type support presets to app store

This commit is contained in:
Gerard Burns 2024-05-13 22:26:43 +01:00
parent 914beb890f
commit a95941b1e2
5 changed files with 19 additions and 4 deletions

View File

@ -16,7 +16,7 @@
DateAsNumber, DateAsNumber,
} from "./lines" } from "./lines"
import subjects from "./subjects" import subjects from "./subjects"
import { componentStore } from "stores/builder" import { appStore } from "stores/builder"
export let explanation export let explanation
export let columnIcon export let columnIcon
@ -29,7 +29,7 @@
$: explanationWithPresets = getExplanationWithPresets( $: explanationWithPresets = getExplanationWithPresets(
explanation, explanation,
$componentStore.typeSupportPresets $appStore.typeSupportPresets
) )
let support let support
let messages = [] let messages = []

View File

@ -19,6 +19,7 @@ export const INITIAL_APP_META_STATE = {
showNotificationAction: false, showNotificationAction: false,
sidePanel: false, sidePanel: false,
}, },
typeSupportPresets: {},
features: { features: {
componentValidation: false, componentValidation: false,
disableUserMetadata: false, disableUserMetadata: false,
@ -79,6 +80,13 @@ export class AppMetaStore extends BudiStore {
})) }))
} }
syncClientTypeSupportPresets(typeSupportPresets) {
this.update(state => ({
...state,
typeSupportPresets
}))
}
async syncAppRoutes() { async syncAppRoutes() {
const resp = await API.fetchAppRoutes() const resp = await API.fetchAppRoutes()
this.update(state => ({ this.update(state => ({

View File

@ -103,12 +103,12 @@ export class ComponentStore extends BudiStore {
this.update(state => ({ this.update(state => ({
...state, ...state,
components, components,
customComponents, customComponents
typeSupportPresets: components?.typeSupportPresets ?? {},
})) }))
// Sync client features to app store // Sync client features to app store
appStore.syncClientFeatures(components.features) appStore.syncClientFeatures(components.features)
appStore.syncClientTypeSupportPresets(components?.typeSupportPresets ?? {})
return components return components
} }

View File

@ -91,6 +91,12 @@ describe("Application Meta Store", () => {
}) })
}) })
it("Sync type support information to state", async ctx => {
ctx.test.appStore.syncClientTypeSupportPresets({ preset: "information" })
expect(ctx.test.store.typeSupportPresets).toStrictEqual({ preset: "information" })
})
it("Sync component feature flags to state", async ctx => { it("Sync component feature flags to state", async ctx => {
ctx.test.appStore.syncClientFeatures(clientFeaturesResp) ctx.test.appStore.syncClientFeatures(clientFeaturesResp)

View File

@ -42,6 +42,7 @@ vi.mock("stores/builder", async () => {
update: mockAppStore.update, update: mockAppStore.update,
set: mockAppStore.set, set: mockAppStore.set,
syncClientFeatures: vi.fn(), syncClientFeatures: vi.fn(),
syncClientTypeSupportPresets: vi.fn(),
} }
const mockTableStore = writable() const mockTableStore = writable()
const tables = { const tables = {