feat: 限制历史操作为管理员可见

This commit is contained in:
shenlei
2026-07-20 17:18:00 +09:00
parent 13366ab3b4
commit 624f534b0f
2 changed files with 25 additions and 11 deletions
+21 -8
View File
@@ -1,4 +1,5 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { ref } from 'vue'
import { mount, flushPromises } from '@vue/test-utils'
import { createRouter, createMemoryHistory } from 'vue-router'
import HistoryView from '../views/HistoryView.vue'
@@ -22,6 +23,15 @@ function createMockRouter() {
})
}
function mountHistory(admin = false) {
return mount(HistoryView, {
global: {
plugins: [createMockRouter()],
provide: { isAdmin: ref(admin) },
},
})
}
describe('HistoryView.vue', () => {
beforeEach(() => {
vi.clearAllMocks()
@@ -129,10 +139,7 @@ describe('HistoryView.vue', () => {
})
it('已完成任务显示下载按钮', async () => {
const router = createMockRouter()
const wrapper = mount(HistoryView, {
global: { plugins: [router] },
})
const wrapper = mountHistory(true)
await flushPromises()
// 第一行(App1, completed)应该有 dSYM 和下载按钮
@@ -143,6 +150,15 @@ describe('HistoryView.vue', () => {
expect(firstRow.find('.qr-thumb').exists()).toBe(true)
})
it('普通用户不显示历史操作按钮', async () => {
const wrapper = mountHistory(false)
await flushPromises()
expect(wrapper.find('.action-btns').exists()).toBe(false)
expect(wrapper.text()).not.toContain('删除')
expect(wrapper.text()).not.toContain('日志')
})
it('空列表显示提示', async () => {
fetch.mockResolvedValue({ json: () => Promise.resolve([]) })
const router = createMockRouter()
@@ -181,10 +197,7 @@ describe('HistoryView.vue', () => {
})
it('点击查看日志打开日志弹窗', async () => {
const router = createMockRouter()
const wrapper = mount(HistoryView, {
global: { plugins: [router] },
})
const wrapper = mountHistory(true)
await flushPromises()
const logBtn = wrapper.findAll('.action-btn').find(b => b.text() === '日志')