feat(web): 迁移前端源代码(任务 T4.1)
- 删除 novalon 前端 src/ 下所有文件 - 从 gym-manage 复制前端 src/ 完整目录树 - 替换 gym-manage-api → novalon-manage-api - 替换 gym_system → manage_system - 无 gym 残留引用
This commit is contained in:
@@ -0,0 +1,195 @@
|
||||
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { createRouter, createMemoryHistory } from 'vue-router'
|
||||
import LoginLog from '@/views/audit/LoginLog.vue'
|
||||
|
||||
vi.mock('vue-router')
|
||||
vi.mock('@/utils/request', () => {
|
||||
const mockRequest = {
|
||||
get: vi.fn().mockResolvedValue({
|
||||
content: [
|
||||
{ id: 1, username: 'admin', ip: '192.168.1.1', location: '北京', browser: 'Chrome', os: 'Windows', status: '0', loginTime: '2026-01-01T10:00:00' },
|
||||
{ id: 2, username: 'user', ip: '192.168.1.2', location: '上海', browser: 'Firefox', os: 'MacOS', status: '1', loginTime: '2026-01-02T11:00:00' },
|
||||
],
|
||||
totalElements: 2,
|
||||
}),
|
||||
post: vi.fn(),
|
||||
put: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
}
|
||||
|
||||
return {
|
||||
default: mockRequest,
|
||||
}
|
||||
})
|
||||
|
||||
describe('LoginLog Component', () => {
|
||||
let router: any
|
||||
let wrapper: any
|
||||
|
||||
beforeEach(() => {
|
||||
router = createRouter({
|
||||
history: createMemoryHistory(),
|
||||
routes: [
|
||||
{ path: '/', component: { template: '<div>Home</div>' } },
|
||||
],
|
||||
})
|
||||
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
if (wrapper) {
|
||||
wrapper.unmount()
|
||||
}
|
||||
})
|
||||
|
||||
describe('component initialization', () => {
|
||||
it('should render login log container', () => {
|
||||
wrapper = mount(LoginLog, {
|
||||
global: {
|
||||
plugins: [router],
|
||||
stubs: {
|
||||
'el-card': true,
|
||||
'el-button': true,
|
||||
'el-table': true,
|
||||
'el-table-column': true,
|
||||
'el-input': true,
|
||||
'el-tag': true,
|
||||
'el-icon': true,
|
||||
'el-pagination': true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
expect(wrapper.find('.login-log').exists()).toBe(true)
|
||||
})
|
||||
|
||||
it('should initialize with empty search keyword', () => {
|
||||
wrapper = mount(LoginLog, {
|
||||
global: {
|
||||
plugins: [router],
|
||||
stubs: {
|
||||
'el-card': true,
|
||||
'el-button': true,
|
||||
'el-table': true,
|
||||
'el-table-column': true,
|
||||
'el-input': true,
|
||||
'el-tag': true,
|
||||
'el-icon': true,
|
||||
'el-pagination': true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
expect(wrapper.vm.searchKeyword).toBe('')
|
||||
})
|
||||
|
||||
it('should initialize with correct pagination defaults', () => {
|
||||
wrapper = mount(LoginLog, {
|
||||
global: {
|
||||
plugins: [router],
|
||||
stubs: {
|
||||
'el-card': true,
|
||||
'el-button': true,
|
||||
'el-table': true,
|
||||
'el-table-column': true,
|
||||
'el-input': true,
|
||||
'el-tag': true,
|
||||
'el-icon': true,
|
||||
'el-pagination': true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
expect(wrapper.vm.pagination.current).toBe(1)
|
||||
expect(wrapper.vm.pagination.pageSize).toBe(10)
|
||||
expect(wrapper.vm.pagination.total).toBe(0)
|
||||
})
|
||||
|
||||
it('should initialize with correct sort defaults', () => {
|
||||
wrapper = mount(LoginLog, {
|
||||
global: {
|
||||
plugins: [router],
|
||||
stubs: {
|
||||
'el-card': true,
|
||||
'el-button': true,
|
||||
'el-table': true,
|
||||
'el-table-column': true,
|
||||
'el-input': true,
|
||||
'el-tag': true,
|
||||
'el-icon': true,
|
||||
'el-pagination': true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
expect(wrapper.vm.sortInfo.sort).toBe('id')
|
||||
expect(wrapper.vm.sortInfo.order).toBe('asc')
|
||||
})
|
||||
})
|
||||
|
||||
describe('sort handling', () => {
|
||||
beforeEach(() => {
|
||||
wrapper = mount(LoginLog, {
|
||||
global: {
|
||||
plugins: [router],
|
||||
stubs: {
|
||||
'el-card': true,
|
||||
'el-button': true,
|
||||
'el-table': true,
|
||||
'el-table-column': true,
|
||||
'el-input': true,
|
||||
'el-tag': true,
|
||||
'el-icon': true,
|
||||
'el-pagination': true,
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it('should update sort info on ascending order', () => {
|
||||
wrapper.vm.handleSortChange({ prop: 'username', order: 'ascending' })
|
||||
expect(wrapper.vm.sortInfo.sort).toBe('username')
|
||||
expect(wrapper.vm.sortInfo.order).toBe('asc')
|
||||
})
|
||||
|
||||
it('should update sort info on descending order', () => {
|
||||
wrapper.vm.handleSortChange({ prop: 'loginTime', order: 'descending' })
|
||||
expect(wrapper.vm.sortInfo.sort).toBe('loginTime')
|
||||
expect(wrapper.vm.sortInfo.order).toBe('desc')
|
||||
})
|
||||
})
|
||||
|
||||
describe('pagination handling', () => {
|
||||
beforeEach(() => {
|
||||
wrapper = mount(LoginLog, {
|
||||
global: {
|
||||
plugins: [router],
|
||||
stubs: {
|
||||
'el-card': true,
|
||||
'el-button': true,
|
||||
'el-table': true,
|
||||
'el-table-column': true,
|
||||
'el-input': true,
|
||||
'el-tag': true,
|
||||
'el-icon': true,
|
||||
'el-pagination': true,
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it('should reset to first page on size change', () => {
|
||||
wrapper.vm.pagination.current = 5
|
||||
wrapper.vm.handleSizeChange()
|
||||
expect(wrapper.vm.pagination.current).toBe(1)
|
||||
})
|
||||
|
||||
it('should reset to first page on search', () => {
|
||||
wrapper.vm.pagination.current = 5
|
||||
wrapper.vm.handleSearch()
|
||||
expect(wrapper.vm.pagination.current).toBe(1)
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user