feat: 新增误操作结束学习交互
This commit is contained in:
@@ -6,6 +6,7 @@ import { createMemoryHistory, createRouter } from 'vue-router'
|
||||
import StartTask from '@/components/StartTask.vue'
|
||||
import router from '@/router'
|
||||
import {
|
||||
abortSession,
|
||||
continueSession,
|
||||
endSession,
|
||||
getActiveSession,
|
||||
@@ -17,6 +18,7 @@ import {
|
||||
import { getFragmentsBySession } from '@/api/reportFragments'
|
||||
|
||||
vi.mock('@/api/studySessions', () => ({
|
||||
abortSession: vi.fn(),
|
||||
continueSession: vi.fn(),
|
||||
endSession: vi.fn(),
|
||||
getActiveSession: vi.fn(),
|
||||
@@ -222,4 +224,44 @@ describe('StartTask.vue', () => {
|
||||
expect(pauseSession).toHaveBeenCalledTimes(2)
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('confirmAbort aborts session with correct phrase and navigates to study page', async () => {
|
||||
vi.mocked(abortSession).mockResolvedValue({ code: 200, message: '请求成功' } as any)
|
||||
const wrapper = await mountTask()
|
||||
|
||||
wrapper.vm.abortConfirmation = '我误操作导致开启了本次学习'
|
||||
await wrapper.vm.confirmAbort()
|
||||
|
||||
expect(abortSession).toHaveBeenCalledWith('SESSION_001', '我误操作导致开启了本次学习')
|
||||
expect(ElMessage.success).toHaveBeenCalledWith('本次学习已关闭,未产生任何数据')
|
||||
expect(localStorage.getItem('activeSession')).toBeNull()
|
||||
expect(router.currentRoute.value.path).toBe('/study')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('confirmAbort refuses wrong phrase without calling API', async () => {
|
||||
const wrapper = await mountTask()
|
||||
|
||||
wrapper.vm.abortConfirmation = '不是确认语'
|
||||
await wrapper.vm.confirmAbort()
|
||||
|
||||
expect(ElMessage.warning).toHaveBeenCalledWith('确认语输入不正确,请重新输入')
|
||||
expect(abortSession).not.toHaveBeenCalled()
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('confirmAbort shows backend message when session has fragments and stays on page', async () => {
|
||||
vi.mocked(abortSession).mockRejectedValue({
|
||||
code: 400,
|
||||
message: '这次学习已经产生了学习残片,不能按误操作结束了哦',
|
||||
} as any)
|
||||
const wrapper = await mountTask()
|
||||
|
||||
wrapper.vm.abortConfirmation = '我误操作导致开启了本次学习'
|
||||
await wrapper.vm.confirmAbort()
|
||||
|
||||
expect(ElMessage.error).toHaveBeenCalledWith('这次学习已经产生了学习残片,不能按误操作结束了哦')
|
||||
expect(router.currentRoute.value.path).not.toBe('/study')
|
||||
wrapper.unmount()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user