Updating test.

This commit is contained in:
mike12345567 2024-12-17 17:16:44 +00:00
parent 590ba5de60
commit 33c1f7364d
2 changed files with 21 additions and 14 deletions

View File

@ -19,7 +19,7 @@ const getIntegrationOrder = (type: string | undefined) => {
return type.charCodeAt(0) + 4
}
class SortedIntegrationStore extends BudiStore<UIIntegration[]> {
export class SortedIntegrationStore extends BudiStore<UIIntegration[]> {
constructor() {
super([])

View File

@ -1,12 +1,14 @@
import { it, expect, describe, beforeEach, vi } from "vitest"
import { createSortedIntegrationsStore } from "stores/builder/sortedIntegrations"
import { SortedIntegrationStore } from "stores/builder/sortedIntegrations"
import { DatasourceTypes } from "constants/backend"
import { derived } from "svelte/store"
import { integrations } from "stores/builder/integrations"
vi.mock("svelte/store", () => ({
derived: vi.fn(),
derived: vi.fn(() => ({
subscribe: vi.fn(),
})),
writable: vi.fn(() => ({
subscribe: vi.fn(),
})),
@ -14,6 +16,8 @@ vi.mock("svelte/store", () => ({
vi.mock("stores/builder/integrations", () => ({ integrations: vi.fn() }))
const mockedDerived = vi.mocked(derived)
const inputA = {
nonRelationalA: {
friendlyName: "non-relational A",
@ -104,25 +108,28 @@ const expectedOutput = [
]
describe("sorted integrations store", () => {
beforeEach(ctx => {
interface LocalContext {
returnedStore: SortedIntegrationStore
derivedCallback: any
}
beforeEach<LocalContext>(ctx => {
vi.clearAllMocks()
ctx.returnedStore = createSortedIntegrationsStore()
ctx.derivedCallback = derived.mock.calls[0][1]
ctx.returnedStore = new SortedIntegrationStore()
ctx.derivedCallback = mockedDerived.mock.calls[0]?.[1]
})
it("calls derived with the correct parameters", () => {
expect(derived).toHaveBeenCalledTimes(1)
expect(derived).toHaveBeenCalledWith(integrations, expect.toBeFunc())
expect(mockedDerived).toHaveBeenCalledTimes(1)
expect(mockedDerived).toHaveBeenCalledWith(
integrations,
expect.any(Function)
)
})
describe("derived callback", () => {
it("When no integrations are loaded", ctx => {
expect(ctx.derivedCallback({})).toEqual([])
})
it("When integrations are present", ctx => {
it<LocalContext>("When integrations are present", ctx => {
expect(ctx.derivedCallback(inputA)).toEqual(expectedOutput)
expect(ctx.derivedCallback(inputB)).toEqual(expectedOutput)
})