1
0
Fork 0
mirror of synced 2024-06-01 18:20:18 +12:00

add some temporary testing files

This commit is contained in:
Keviin Åberg Kultalahti 2021-03-26 15:43:55 +01:00
parent 0586d62878
commit ed2d541a77
11 changed files with 31 additions and 48 deletions

View file

@ -29,18 +29,15 @@
"\\.(css|less|sass|scss)$": "identity-obj-proxy",
"components(.*)$": "<rootDir>/src/components$1",
"builderStore(.*)$": "<rootDir>/src/builderStore$1",
"stores(.*)$": "<rootDir>/src/stores$1"
"stores(.*)$": "<rootDir>/src/stores$1",
"analytics(.*)$": "<rootDir>/src/analytics$1"
},
"moduleFileExtensions": [
"js",
"svelte"
],
"moduleDirectories": [
"node_modules",
"builderStore",
"stores",
"constants",
"analytics"
"node_modules"
],
"transform": {
"^.+js$": "babel-jest",

View file

@ -1,17 +1,20 @@
import { writable } from "svelte/store"
import { queries } from "./"
import api from "builderStore/api"
import api from "../../builderStore/api"
export function createDatasourcesStore(_api = api) {
const { subscribe, update, set } = writable({
export const INITIAL_DATASOURCE_VALUES = {
list: [],
selected: null,
})
}
export function createDatasourcesStore(_api = api) {
const { subscribe, update, set } = writable(INITIAL_DATASOURCE_VALUES)
return {
subscribe,
set,
update,
init: () => set(INITIAL_DATASOURCE_VALUES),
fetch: async () => {
const response = await api.get(`/api/datasources`)
const json = await response.json()

View file

@ -1,26 +0,0 @@
import { database } from "../"
describe("Backend DataSources Store", () => {
let state;
let unsub;
beforeEach(() => {
unsub = database.subscribe(s => state = s);
})
afterEach(() => {
unsub()
})
it("initialises correctly", () => {
expect(state.list, [])
})
})
const api = {
post: () => ({}),
get: () => ({}),
patch: () => ({}),
delete: () => ({}),
put: () => ({}),
}

View file

@ -1,24 +1,33 @@
import { get } from 'svelte/store'
import api from 'builderStore/api'
jest.mock('builderStore/api');
import { createDatasourcesStore } from "../datasources"
const mockApi = {
post: () => ({}),
get: () => ({}),
patch: () => ({}),
delete: () => ({}),
put: () => ({}),
}
describe("Automation Data Object", () => {
let store
let store = createDatasourcesStore()
beforeEach(() => {
store = createDatasourcesStore(mockApi)
store.init()
})
it("Inits properly", () => {
const value = get(store)
expect(value).toBe(true)
expect(value).toEqual({ list: [], selected: null})
})
it("Fetch returns and updates store", async () => {
api.get.mockReturnValueOnce({ json: () => 'some-cool-value'})
store.fetch()
expect(api.get).toBeCalledWith(`/api/datasources`)
// expect(get(store)).toEqual({ list: [], selected: null})
})
})