material_manage_system/frontend/src/views/Logs.test.js

46 lines
1.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { flushPromises, mount } from '@vue/test-utils'
import ElementPlus from 'element-plus'
import { describe, expect, test, vi } from 'vitest'
import Logs from './Logs.vue'
vi.mock('../stores/logs', () => ({
useLogsStore: () => ({
logs: [], loading: false,
page: { currentPage: 1, pageSize: 20, total: 0 },
fetchLogs: vi.fn()
})
}))
vi.mock('../stores/materials', () => ({
useMaterialsStore: () => ({
historicalMaterialOptions: [],
fetchHistoricalMaterialOptions: vi.fn()
})
}))
describe('导入日志详情', () => {
test('显示导入时的字段详情并保留换行', async () => {
const description = '批量导入创建:螺栓(RTIMP0001)\n物料编码:RTIMP0001\n名称:螺栓\n规格:M8\n分类:机械结构类 / 标准件\n单位:个\n状态:启用'
const wrapper = mount(Logs, {
global: {
plugins: [ElementPlus],
stubs: { teleport: true, ElSelect: true, ElOption: true, ElDatePicker: true }
}
})
try {
wrapper.vm.$.setupState.showDetail({
material_id: 31, operation_type: 'CREATE', operator: 'tester',
created_at: '2026-10-12T10:00:00', description,
old_value: '', new_value: '{"name":"螺栓","material_code":"RTIMP0001"}'
})
await flushPromises()
const detail = wrapper.get('.log-description')
expect(detail.text()).toBe(description)
expect(detail.element.style.whiteSpace).toBe('pre-wrap')
expect(wrapper.find('.value-compare').text()).toContain('"material_code": "RTIMP0001"')
} finally {
wrapper.unmount()
}
})
})