diff --git a/frontend/src/__tests__/HistoryView.test.js b/frontend/src/__tests__/HistoryView.test.js index b133e78..5dbda1f 100644 --- a/frontend/src/__tests__/HistoryView.test.js +++ b/frontend/src/__tests__/HistoryView.test.js @@ -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() === '日志') diff --git a/frontend/src/views/HistoryView.vue b/frontend/src/views/HistoryView.vue index b284cb4..45be151 100644 --- a/frontend/src/views/HistoryView.vue +++ b/frontend/src/views/HistoryView.vue @@ -31,7 +31,7 @@ Scheme 状态 下载地址 - 操作 + 操作 @@ -59,7 +59,7 @@ - - + @@ -67,7 +67,7 @@ - 暂无打包记录 + 暂无打包记录 @@ -161,6 +161,7 @@ import { ref, computed, onMounted, nextTick, onUnmounted, inject } from 'vue' const getToken = inject('getToken', () => '') +const isAdmin = inject('isAdmin', ref(false)) const tasks = ref([]) const authFetch = (url, options = {}) => {