import { describe, it, expect, vi, beforeEach } from 'vitest' import { mount, flushPromises } from '@vue/test-utils' import { ref } from 'vue' import OperationLogView from '../views/OperationLogView.vue' global.fetch = vi.fn() describe('OperationLogView.vue', () => { beforeEach(() => { vi.clearAllMocks() fetch .mockResolvedValueOnce({ ok: true, json: () => Promise.resolve({ total: 4, action_counts: { build_created: 2, ipa_download_requested: 1 }, top_users: [{ name: 'admin', count: 4 }], top_apps: [{ name: '测试App', count: 3 }] }) }) .mockResolvedValueOnce({ ok: true, json: () => Promise.resolve([{ id: '1', created_at: '2026-07-22T08:00:00', username: 'admin', action: 'build_created', app_name: '测试App', resource_type: '', client_ip: '127.0.0.1' }]) }) }) it('管理员可查看统计和操作明细', async () => { const wrapper = mount(OperationLogView, { global: { provide: { isAdmin: ref(true), getToken: () => 'token' } } }) await flushPromises() expect(wrapper.text()).toContain('操作日志') expect(wrapper.text()).toContain('操作总数') expect(wrapper.text()).toContain('发起打包') expect(wrapper.text()).toContain('测试App') }) it('普通用户不渲染操作日志页面', async () => { const wrapper = mount(OperationLogView, { global: { provide: { isAdmin: ref(false) } } }) await flushPromises() expect(wrapper.find('.panel').exists()).toBe(false) }) })