This commit is contained in:
2026-08-12 16:58:52 +08:00
parent a44fd5f235
commit 16c5ed6301
13 changed files with 254 additions and 73 deletions
@@ -1,4 +1,6 @@
import ElementPlus from 'element-plus'
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import { createPinia, setActivePinia } from 'pinia'
import { enableAutoUnmount, flushPromises, mount } from '@vue/test-utils'
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
@@ -19,6 +21,8 @@ import { useAccessPreviewStore } from '@/core/access/accessPreview'
import { useAuthStore } from '@/core/auth/auth'
import WarehousesView from './WarehousesView.vue'
const warehousesSource = readFileSync(resolve(process.cwd(), 'src/modules/warehouses/pages/WarehousesView.vue'), 'utf8')
vi.mock('@/modules/warehouses/api/platformWarehouses', () => ({
listPlatformWarehouses: vi.fn(),
getPlatformWarehouse: vi.fn(),
@@ -171,6 +175,12 @@ enableAutoUnmount(afterEach)
afterAll(() => vi.unstubAllGlobals())
describe('WarehousesView', () => {
it('uses the prototype-sized centered warehouse editor with a fixed footer', () => {
expect(warehousesSource).toContain('<AppDialog v-model="editorOpen" :title="editorLabel" width="min(650px, calc(100vw - 28px))"')
expect(warehousesSource).not.toContain('<AppDrawer v-model="editorOpen"')
expect(warehousesSource).toContain(':global(.warehouse-editor-dialog .el-dialog__body) { min-height: 0; overflow-y: auto; }')
expect(warehousesSource).toContain('.drawer-form :deep(.form-grid.two-cols) { grid-template-columns: minmax(0, 1fr); }')
})
beforeEach(() => {
vi.stubGlobal('ResizeObserver', ResizeObserverStub)
document.body.innerHTML = ''
@@ -263,12 +273,12 @@ describe('WarehousesView', () => {
wrapper.findComponent({ name: 'ElDropdown' }).vm.$emit('command', 'FBA')
await flushPromises()
const drawerText = document.querySelector('.el-drawer')?.textContent || ''
expect(drawerText).toContain('新增FBA 地址')
expect(drawerText).toContain('国家或地区')
expect(drawerText).not.toContain('时区覆盖')
expect(drawerText).not.toContain('联系人')
expect(drawerText).not.toContain('收货时间')
const dialogText = document.querySelector('.warehouse-editor-dialog')?.textContent || ''
expect(dialogText).toContain('新增FBA 地址')
expect(dialogText).toContain('国家或地区')
expect(dialogText).not.toContain('时区覆盖')
expect(dialogText).not.toContain('联系人')
expect(dialogText).not.toContain('收货时间')
const countrySelect = wrapper.findAllComponents({ name: 'ElSelect' })
.find((select) => select.props('placeholder') === '美国 US')
expect(countrySelect).toBeDefined()
@@ -309,10 +319,10 @@ describe('WarehousesView', () => {
wrapper.findComponent({ name: 'ElDropdown' }).vm.$emit('command', 'DOMESTIC')
await flushPromises()
const drawerText = document.querySelector('.el-drawer')?.textContent || ''
expect(drawerText).not.toContain('国家或地区')
expect(drawerText).not.toContain('时区')
expect(drawerText).not.toContain('仓库类型')
const dialogText = document.querySelector('.warehouse-editor-dialog')?.textContent || ''
expect(dialogText).not.toContain('国家或地区')
expect(dialogText).not.toContain('时区')
expect(dialogText).not.toContain('仓库类型')
setField('input[placeholder="请输入仓库名称"]', '义乌新仓')
setField('input[placeholder="例如 浙江省"]', '浙江省')
@@ -384,10 +394,10 @@ describe('WarehousesView', () => {
await editButton.trigger('click')
await flushPromises()
const drawerText = document.querySelector('.el-drawer')?.textContent || ''
expect(drawerText).toContain('编辑FBA 地址')
expect(drawerText).not.toContain('例如 US')
expect(drawerText).not.toContain('例如 UTC-8')
const dialogText = document.querySelector('.warehouse-editor-dialog')?.textContent || ''
expect(dialogText).toContain('编辑FBA 地址')
expect(dialogText).not.toContain('例如 US')
expect(dialogText).not.toContain('例如 UTC-8')
const countrySelect = wrapper.findAllComponents({ name: 'ElSelect' })
.find((select) => select.props('placeholder') === '请选择国家或地区')