add some temporary testing files
This commit is contained in:
parent
33b7545e56
commit
6711801f97
|
@ -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",
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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: () => ({}),
|
||||
}
|
|
@ -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})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue