add some temporary testing files

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

View File

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

View File

@ -1,17 +1,20 @@
import { writable } from "svelte/store" import { writable } from "svelte/store"
import { queries } from "./" import { queries } from "./"
import api from "builderStore/api" import api from "../../builderStore/api"
export function createDatasourcesStore(_api = api) { export const INITIAL_DATASOURCE_VALUES = {
const { subscribe, update, set } = writable({
list: [], list: [],
selected: null, selected: null,
}) }
export function createDatasourcesStore(_api = api) {
const { subscribe, update, set } = writable(INITIAL_DATASOURCE_VALUES)
return { return {
subscribe, subscribe,
set, set,
update, update,
init: () => set(INITIAL_DATASOURCE_VALUES),
fetch: async () => { fetch: async () => {
const response = await api.get(`/api/datasources`) const response = await api.get(`/api/datasources`)
const json = await response.json() 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 { get } from 'svelte/store'
import api from 'builderStore/api'
jest.mock('builderStore/api');
import { createDatasourcesStore } from "../datasources" import { createDatasourcesStore } from "../datasources"
const mockApi = {
post: () => ({}),
get: () => ({}),
patch: () => ({}),
delete: () => ({}),
put: () => ({}),
}
describe("Automation Data Object", () => { describe("Automation Data Object", () => {
let store let store = createDatasourcesStore()
beforeEach(() => { beforeEach(() => {
store = createDatasourcesStore(mockApi) store.init()
}) })
it("Inits properly", () => { it("Inits properly", () => {
const value = get(store) 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})
}) })
}) })