|
|
@@ -3,7 +3,7 @@ import { test } from 'node:test'
|
|
|
|
|
|
import { createPinia, setActivePinia } from 'pinia'
|
|
|
|
|
|
-import { DEMO_DEVICE_CODE, sharedPreloadDeviceCode, useDetailStore } from '../src/modules/cockpit/stores/detailStore.js'
|
|
|
+import { useDetailStore } from '../src/modules/cockpit/stores/detailStore.js'
|
|
|
|
|
|
const BASE_URL = 'http://test.local/api/cockpit/v1'
|
|
|
|
|
|
@@ -39,36 +39,3 @@ test('real 模式:启动预载不请求演示设备', async () => {
|
|
|
const deviceUrls = await preload('real')
|
|
|
assert.deepEqual(deviceUrls, [], 'real 模式没有真实设备可预载,不应请求 /equipments/ 分区(曾打出必然 404)')
|
|
|
})
|
|
|
-
|
|
|
-test('显式 deviceCode:真实设备仍按请求预载', async () => {
|
|
|
- setActivePinia(createPinia())
|
|
|
- const urls = []
|
|
|
- const store = useDetailStore()
|
|
|
- try {
|
|
|
- await store.loadSharedSections({
|
|
|
- deviceCode: '21119740',
|
|
|
- config: { dataSource: 'real', api: { baseUrl: BASE_URL } },
|
|
|
- fetchImpl: recordingFetch(urls),
|
|
|
- })
|
|
|
- } catch {
|
|
|
- // 同上
|
|
|
- }
|
|
|
- const deviceUrls = urls.filter((url) => /\/equipments\//.test(url))
|
|
|
- assert.ok(deviceUrls.length > 0, '显式给出设备编码时应照常预载')
|
|
|
- assert.ok(
|
|
|
- deviceUrls.every((url) => url.includes('21119740')),
|
|
|
- '预载只应请求显式给出的设备,不得混入演示设备',
|
|
|
- )
|
|
|
-})
|
|
|
-
|
|
|
-test('mock 模式:仍以演示设备为预载目标', () => {
|
|
|
- const code = sharedPreloadDeviceCode({ config: { dataSource: 'mock' } })
|
|
|
- assert.equal(code, DEMO_DEVICE_CODE, 'mock 的契约样例里有这台设备,保持原行为')
|
|
|
-})
|
|
|
-
|
|
|
-test('决策:显式编码优先,real 无编码不回退演示设备', () => {
|
|
|
- assert.equal(sharedPreloadDeviceCode({ deviceCode: 'X', config: { dataSource: 'real' } }), 'X')
|
|
|
- assert.equal(sharedPreloadDeviceCode({ config: { dataSource: 'real' } }), '')
|
|
|
- assert.equal(sharedPreloadDeviceCode({ config: { dataSource: 'mock' } }), DEMO_DEVICE_CODE)
|
|
|
- assert.equal(sharedPreloadDeviceCode(), '', '无配置时不得凭空选一台演示设备')
|
|
|
-})
|