bt-core-app 1.1.1 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/extensions.json +3 -0
- package/dist/bt-core-app.js +23241 -0
- package/dist/style.css +1 -0
- package/package.json +1 -1
- package/test/api.test.ts +84 -0
- package/test/forage.test.ts +31 -0
- package/test/helpers.test.ts +231 -0
- package/test/navigation.test.ts +99 -0
- package/test/stores-last-update.test.ts +138 -0
- package/test/stores-session.test.ts +118 -0
- package/test/track.test.ts +29 -0
- package/test/utils.ts +15 -0
- package/tsconfig.json +33 -0
- package/vite.config.ts +7 -1
- package/index.html +0 -13
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { setActivePinia, createPinia } from 'pinia'
|
|
2
|
+
import { createSessionStore, createWholeLastUpdateStore } from '../src/composables/stores'
|
|
3
|
+
import { createApi } from '../src/composables/api'
|
|
4
|
+
import { describe, test, expect, beforeEach, afterAll, afterEach, beforeAll } from 'vitest'
|
|
5
|
+
import { setupServer } from 'msw/node'
|
|
6
|
+
import { http, HttpResponse } from 'msw'
|
|
7
|
+
import { createApp } from 'vue'
|
|
8
|
+
import { withSetup } from './utils'
|
|
9
|
+
|
|
10
|
+
const handlers = [
|
|
11
|
+
http.get('https://test-api/get/1', () => {
|
|
12
|
+
return HttpResponse.json({
|
|
13
|
+
data: { test: 'a' }
|
|
14
|
+
})
|
|
15
|
+
}),
|
|
16
|
+
http.get('https://test-api/get/2', () => {
|
|
17
|
+
return new HttpResponse('not found', {
|
|
18
|
+
status: 304
|
|
19
|
+
})
|
|
20
|
+
}),
|
|
21
|
+
http.get('https://test-api/getAll', () => {
|
|
22
|
+
return HttpResponse.json({
|
|
23
|
+
data: [{ test: 'a' }, { test: 'b' }],
|
|
24
|
+
count: 2,
|
|
25
|
+
filters: ['test', 'test two']
|
|
26
|
+
})
|
|
27
|
+
}),
|
|
28
|
+
http.post('https://test-api/post', () => {
|
|
29
|
+
return HttpResponse.json({ data: { test: 'b' } })
|
|
30
|
+
}),
|
|
31
|
+
http.patch('https://test-api/patch', () => {
|
|
32
|
+
return HttpResponse.json({ data: { test: 'c', rowVersion: 2 } })
|
|
33
|
+
})
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
const server = setupServer(...handlers)
|
|
37
|
+
|
|
38
|
+
beforeAll(() => server.listen({ onUnhandledRequest: 'error' }))
|
|
39
|
+
|
|
40
|
+
afterAll(() => server.close())
|
|
41
|
+
|
|
42
|
+
afterEach(() => {
|
|
43
|
+
server.resetHandlers()
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
describe('use session store with no api no caching', () => {
|
|
47
|
+
const [api, app] = withSetup(() => createApi())
|
|
48
|
+
|
|
49
|
+
const pinia = createPinia()
|
|
50
|
+
app.use(pinia)
|
|
51
|
+
setActivePinia(pinia)
|
|
52
|
+
|
|
53
|
+
const store = createSessionStore({
|
|
54
|
+
storageMode: 'session',
|
|
55
|
+
storeName: 'sesh'
|
|
56
|
+
})()
|
|
57
|
+
|
|
58
|
+
test('all session activity', async () => {
|
|
59
|
+
await store.post<any>({ data: { id: '1', test: 'a' }})
|
|
60
|
+
let postRes = await store.get<any>({ id: '1' })
|
|
61
|
+
expect(postRes.data).toEqual({ id: '1', test: 'a' })
|
|
62
|
+
await store.patch<any>({ nav: 'test', data: { id: '1', test: 'b' }})
|
|
63
|
+
postRes = await store.get<any>({ id: '1' })
|
|
64
|
+
expect(postRes.data).toEqual({ id: '1', test: 'b' })
|
|
65
|
+
await store.deleteItem({ id: '1' })
|
|
66
|
+
postRes = await store.get<any>({ id: '1' })
|
|
67
|
+
expect(postRes).toEqual(undefined)
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
describe('use session store with api no caching', () => {
|
|
72
|
+
const [api, app] = withSetup(() => createApi({
|
|
73
|
+
findPath: () => 'https://test-api/',
|
|
74
|
+
defaultThrowError: false
|
|
75
|
+
}))
|
|
76
|
+
|
|
77
|
+
const pinia = createPinia()
|
|
78
|
+
app.use(pinia)
|
|
79
|
+
|
|
80
|
+
setActivePinia(pinia)
|
|
81
|
+
|
|
82
|
+
const store = createSessionStore({
|
|
83
|
+
storageMode: 'session',
|
|
84
|
+
api: api,
|
|
85
|
+
storeName: 'test'
|
|
86
|
+
})()
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
test('get', async () => {
|
|
90
|
+
const res = await store.get<any>({ nav: 'test', id: '1' })
|
|
91
|
+
expect(res).toEqual({ data: { test: 'a' }})
|
|
92
|
+
//expect(store.searchMemory['test_no-user-id_1']).toEqual({ data: { test: 'a' }})
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
test('get all', async () => {
|
|
96
|
+
const res = await store.getAll<any>({ nav: 'test' })
|
|
97
|
+
expect(res).toEqual({
|
|
98
|
+
data: [{test: 'a' },{test: 'b'}],
|
|
99
|
+
count: 2,
|
|
100
|
+
filters: ['test', 'test two']
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
test('post', async () => {
|
|
105
|
+
const res = await store.post<any>({ nav: 'test', data: { test: 'a', id: '11' }})
|
|
106
|
+
expect(res).not.toBeNull()
|
|
107
|
+
//gets api post return
|
|
108
|
+
let getRes = await store.get<any>({ nav: 'test', id: '11' })
|
|
109
|
+
expect(getRes.data).toEqual({ test: 'b' })
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
test('patch', async () => {
|
|
113
|
+
const res = await store.patch<any>({ nav: 'test', data: { test: 'a', id: '1', rowVersion: 1 }})
|
|
114
|
+
let getRes = await store.get<any>({ nav: 'test', id: '1' })
|
|
115
|
+
expect(getRes.data.rowVersion).toEqual(2)
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
})
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest"
|
|
2
|
+
import { withSetup } from './utils'
|
|
3
|
+
import { useTracker } from '../src/composables/track'
|
|
4
|
+
import { twiddleThumbs } from "../src/composables/helpers"
|
|
5
|
+
|
|
6
|
+
describe("track", () => {
|
|
7
|
+
test('tracker test', async () => {
|
|
8
|
+
|
|
9
|
+
const item = { test: 'a' }
|
|
10
|
+
const [{ asyncItem, isChanged, restartTracker }] = withSetup(() => useTracker(item))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
expect(isChanged.value).toEqual(false)
|
|
14
|
+
asyncItem.value.test = 'b'
|
|
15
|
+
await twiddleThumbs(500)
|
|
16
|
+
expect(isChanged.value).toEqual(true)
|
|
17
|
+
asyncItem.value.test = 'a'
|
|
18
|
+
await twiddleThumbs(500)
|
|
19
|
+
expect(isChanged.value).toEqual(false)
|
|
20
|
+
asyncItem.value.test = 'b'
|
|
21
|
+
await twiddleThumbs(500)
|
|
22
|
+
expect(isChanged.value).toEqual(true)
|
|
23
|
+
restartTracker()
|
|
24
|
+
await twiddleThumbs(500)
|
|
25
|
+
expect(isChanged.value).toEqual(false)
|
|
26
|
+
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
})
|
package/test/utils.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createApp } from 'vue'
|
|
2
|
+
|
|
3
|
+
export function withSetup(composable) {
|
|
4
|
+
let result
|
|
5
|
+
const app = createApp({
|
|
6
|
+
setup() {
|
|
7
|
+
result = composable()
|
|
8
|
+
return () => {}
|
|
9
|
+
}
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
app.mount(document.createElement('div'))
|
|
13
|
+
|
|
14
|
+
return [result, app]
|
|
15
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"baseUrl": ".",
|
|
4
|
+
"target": "ES2020",
|
|
5
|
+
"useDefineForClassFields": true,
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"lib": ["ES2020", "ES2021.String", "DOM", "DOM.Iterable"],
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
|
|
10
|
+
/* Bundler mode */
|
|
11
|
+
"moduleResolution": "bundler",
|
|
12
|
+
"allowImportingTsExtensions": true,
|
|
13
|
+
"resolveJsonModule": true,
|
|
14
|
+
"isolatedModules": true,
|
|
15
|
+
"noEmit": true,
|
|
16
|
+
"jsx": "preserve",
|
|
17
|
+
|
|
18
|
+
/* Linting */
|
|
19
|
+
"strict": true,
|
|
20
|
+
"noUnusedLocals": true,
|
|
21
|
+
"noUnusedParameters": true,
|
|
22
|
+
"noFallthroughCasesInSwitch": true,
|
|
23
|
+
"paths": {
|
|
24
|
+
"@/*": [
|
|
25
|
+
"src/*"
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
"types": ["vitest/globals"]
|
|
29
|
+
},
|
|
30
|
+
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"],
|
|
31
|
+
"references": [{ "path": "./tsconfig.node.json" }],
|
|
32
|
+
"exclude": ["node_modules"]
|
|
33
|
+
}
|
package/vite.config.ts
CHANGED
|
@@ -10,10 +10,16 @@ export default defineConfig({
|
|
|
10
10
|
globals: true,
|
|
11
11
|
environment: 'happy-dom'
|
|
12
12
|
},
|
|
13
|
+
build: {
|
|
14
|
+
lib: {
|
|
15
|
+
entry: path.resolve(__dirname, './src/index.ts'),
|
|
16
|
+
formats: ['es']
|
|
17
|
+
}
|
|
18
|
+
},
|
|
13
19
|
plugins: [vue()],
|
|
14
20
|
resolve: {
|
|
15
21
|
alias: {
|
|
16
22
|
'@': path.resolve(__dirname, './src')
|
|
17
23
|
}
|
|
18
24
|
}
|
|
19
|
-
})
|
|
25
|
+
})
|
package/index.html
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8" />
|
|
5
|
-
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
-
<title>Vite + Vue + TS</title>
|
|
8
|
-
</head>
|
|
9
|
-
<body>
|
|
10
|
-
<div id="app"></div>
|
|
11
|
-
<script type="module" src="/src/main.ts"></script>
|
|
12
|
-
</body>
|
|
13
|
-
</html>
|