-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ce44ef
commit bc21312
Showing
3 changed files
with
50 additions
and
10 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
app/src/routes/(backstage)/(playground)/crud-operations/__tests__/+page.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { VueWrapper } from '@vue/test-utils'; | ||
import { mount, flushPromises } from '@vue/test-utils'; | ||
import * as xui from '@x/ui'; | ||
import todos from 'mock/todos/response'; | ||
|
||
import localer from '~/plugins/localer'; | ||
import router from '~/plugins/router'; | ||
|
||
import Page from '../+page.vue'; | ||
import useStore from '../store'; | ||
|
||
let wrapper: VueWrapper; | ||
|
||
afterEach(() => { | ||
wrapper.unmount(); | ||
}); | ||
|
||
test('initial', async () => { | ||
vi.spyOn(xui, 'request').mockImplementation((url, { method }: any): any => { | ||
if (url === '/todos' && method === 'POST') { | ||
return { _data: todos.basic, status: 200 }; | ||
} | ||
}); | ||
|
||
wrapper = mount(Page, { global: { plugins: [router, localer] } }); | ||
|
||
await flushPromises(); | ||
|
||
const store = useStore(); | ||
expect(store.state.todosRows).toStrictEqual(todos.basic.result); | ||
expect(store.state.todosCount).toStrictEqual(todos.basic.total); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,9 @@ | ||
import type { FastifyInstance } from 'fastify'; | ||
|
||
import response from './response'; | ||
|
||
export default async (app: FastifyInstance) => { | ||
app.post('', async () => { | ||
return { | ||
result: [ | ||
{ | ||
_id: '643e4d8f178309ee94a8dcb8', | ||
title: 'Vue', | ||
completed: true, | ||
}, | ||
], | ||
total: 1, | ||
}; | ||
return response.basic; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export default { | ||
basic: { | ||
result: [ | ||
{ _id: '1', title: 'Vue', completed: true }, | ||
{ _id: '2', title: 'Tauri', completed: true }, | ||
{ _id: '3', title: 'Fastify', completed: true }, | ||
{ _id: '4', title: 'Pulumi', completed: true }, | ||
{ _id: '5', title: 'TypeScript', completed: true }, | ||
{ _id: '6', title: 'Node.js', completed: true }, | ||
{ _id: '7', title: 'MongoDB', completed: true }, | ||
{ _id: '8', title: 'Redis', completed: true }, | ||
], | ||
total: 8, | ||
}, | ||
}; |