Updating test.
This commit is contained in:
parent
590ba5de60
commit
33c1f7364d
|
@ -19,7 +19,7 @@ const getIntegrationOrder = (type: string | undefined) => {
|
||||||
return type.charCodeAt(0) + 4
|
return type.charCodeAt(0) + 4
|
||||||
}
|
}
|
||||||
|
|
||||||
class SortedIntegrationStore extends BudiStore<UIIntegration[]> {
|
export class SortedIntegrationStore extends BudiStore<UIIntegration[]> {
|
||||||
constructor() {
|
constructor() {
|
||||||
super([])
|
super([])
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
import { it, expect, describe, beforeEach, vi } from "vitest"
|
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 { DatasourceTypes } from "constants/backend"
|
||||||
|
|
||||||
import { derived } from "svelte/store"
|
import { derived } from "svelte/store"
|
||||||
import { integrations } from "stores/builder/integrations"
|
import { integrations } from "stores/builder/integrations"
|
||||||
|
|
||||||
vi.mock("svelte/store", () => ({
|
vi.mock("svelte/store", () => ({
|
||||||
derived: vi.fn(),
|
derived: vi.fn(() => ({
|
||||||
|
subscribe: vi.fn(),
|
||||||
|
})),
|
||||||
writable: vi.fn(() => ({
|
writable: vi.fn(() => ({
|
||||||
subscribe: vi.fn(),
|
subscribe: vi.fn(),
|
||||||
})),
|
})),
|
||||||
|
@ -14,6 +16,8 @@ vi.mock("svelte/store", () => ({
|
||||||
|
|
||||||
vi.mock("stores/builder/integrations", () => ({ integrations: vi.fn() }))
|
vi.mock("stores/builder/integrations", () => ({ integrations: vi.fn() }))
|
||||||
|
|
||||||
|
const mockedDerived = vi.mocked(derived)
|
||||||
|
|
||||||
const inputA = {
|
const inputA = {
|
||||||
nonRelationalA: {
|
nonRelationalA: {
|
||||||
friendlyName: "non-relational A",
|
friendlyName: "non-relational A",
|
||||||
|
@ -104,25 +108,28 @@ const expectedOutput = [
|
||||||
]
|
]
|
||||||
|
|
||||||
describe("sorted integrations store", () => {
|
describe("sorted integrations store", () => {
|
||||||
beforeEach(ctx => {
|
interface LocalContext {
|
||||||
|
returnedStore: SortedIntegrationStore
|
||||||
|
derivedCallback: any
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach<LocalContext>(ctx => {
|
||||||
vi.clearAllMocks()
|
vi.clearAllMocks()
|
||||||
|
|
||||||
ctx.returnedStore = createSortedIntegrationsStore()
|
ctx.returnedStore = new SortedIntegrationStore()
|
||||||
|
ctx.derivedCallback = mockedDerived.mock.calls[0]?.[1]
|
||||||
ctx.derivedCallback = derived.mock.calls[0][1]
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it("calls derived with the correct parameters", () => {
|
it("calls derived with the correct parameters", () => {
|
||||||
expect(derived).toHaveBeenCalledTimes(1)
|
expect(mockedDerived).toHaveBeenCalledTimes(1)
|
||||||
expect(derived).toHaveBeenCalledWith(integrations, expect.toBeFunc())
|
expect(mockedDerived).toHaveBeenCalledWith(
|
||||||
|
integrations,
|
||||||
|
expect.any(Function)
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("derived callback", () => {
|
describe("derived callback", () => {
|
||||||
it("When no integrations are loaded", ctx => {
|
it<LocalContext>("When integrations are present", ctx => {
|
||||||
expect(ctx.derivedCallback({})).toEqual([])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("When integrations are present", ctx => {
|
|
||||||
expect(ctx.derivedCallback(inputA)).toEqual(expectedOutput)
|
expect(ctx.derivedCallback(inputA)).toEqual(expectedOutput)
|
||||||
expect(ctx.derivedCallback(inputB)).toEqual(expectedOutput)
|
expect(ctx.derivedCallback(inputB)).toEqual(expectedOutput)
|
||||||
})
|
})
|
Loading…
Reference in New Issue