1111
This commit is contained in:
@@ -144,8 +144,9 @@ test('late login response cannot write a token or navigate after leaving the aut
|
||||
const server = await createServer({ configFile: false, root: path.dirname(root), plugins: [vuePlugin()], appType: 'custom',
|
||||
server: { middlewareMode: true, hmr: false }, optimizeDeps: { noDiscovery: true, include: [] } })
|
||||
after(() => server.close())
|
||||
async function render(name, values = {}, routePath = '/dashboard') {
|
||||
const { default: view } = await server.ssrLoadModule(`/src/views/${name}.vue`)
|
||||
async function render(name, values = {}, routePath = '/dashboard', props = {}) {
|
||||
const componentPath = name.includes('/') ? name : `views/${name}`
|
||||
const { default: view } = await server.ssrLoadModule(`/src/${componentPath}.vue`)
|
||||
const component = { ...view, setup(props, context) {
|
||||
const state = view.setup(props, context)
|
||||
for (const [key, value] of Object.entries(values)) { assert.ok(isRef(state[key]), key); state[key].value = value }
|
||||
@@ -153,7 +154,7 @@ async function render(name, values = {}, routePath = '/dashboard') {
|
||||
} }
|
||||
const router = createRouter({ history: createMemoryHistory(), routes: [{ path: '/:pathMatch(.*)*', component }] })
|
||||
await router.push(routePath); await router.isReady()
|
||||
const app = createSSRApp({ render: () => h(component) }); app.use(router)
|
||||
const app = createSSRApp({ render: () => h(component, props) }); app.use(router)
|
||||
return renderToString(app)
|
||||
}
|
||||
|
||||
@@ -171,6 +172,59 @@ test('home renders a prominent scene, collapsed presets, a real profile entry an
|
||||
assert.ok(html.indexOf('健康评估</span>') < html.indexOf('我的</span>'))
|
||||
})
|
||||
|
||||
test('automation card separates the rule switch from physical readback and preserves previous results while stopped', async () => {
|
||||
const state = { available: true, enabled: false, actionLabel: '关闭窗帘', targetLabel: '美百帘窗帘', records: [
|
||||
{ id: 'one', actionKey: 'curtain-close', targetLabel: '美百帘窗帘', triggeredAtMs: 1794380000000, result: 'readback-confirmed' },
|
||||
{ id: 'two', actionKey: 'curtain-close', targetLabel: '美百帘窗帘', triggeredAtMs: 1794381000000, result: 'sent-readback-unconfirmed' },
|
||||
] }
|
||||
const props = { bindingId: 'simulation-left' }
|
||||
const stopped = await render('components/Ib43AutomationCard', { status: state }, '/sleep-data', props)
|
||||
assert.match(stopped, /已停止/)
|
||||
assert.match(stopped, /开启联动/)
|
||||
assert.match(stopped, /美百帘窗帘 · 已确认关闭/)
|
||||
assert.match(stopped, /已发出关帘指令,未确认关闭/)
|
||||
const started = await render('components/Ib43AutomationCard', { status: { ...state, enabled: true } }, '/sleep-data', props)
|
||||
assert.match(started, /停止联动/)
|
||||
assert.doesNotMatch(started, /开启联动/)
|
||||
|
||||
const both = await render('components/Ib43AutomationCard', { status: {
|
||||
...state,
|
||||
rules: [
|
||||
{ actionKey: 'curtain-close', actionLabel: '关闭窗帘', enabled: false, targetLabel: '美百帘窗帘' },
|
||||
{ actionKey: 'dehumidifier-humidity-preview', actionLabel: '湿度偏高时开启除湿机', enabled: true,
|
||||
targetLabel: '除湿机', previewOnly: true, conditionLabel: '室内相对湿度超过 55% 时记录开机计划。' },
|
||||
{ actionKey: 'dehumidifier-humidity-start', actionLabel: '湿度偏高时开启除湿机', enabled: false,
|
||||
targetLabel: '除湿机', previewOnly: false, conditionLabel: '室内相对湿度超过 55% 且除湿机关机时,发送开机指令。' },
|
||||
{ actionKey: 'climate-temperature-preview', actionLabel: '按室温判断空调模式', enabled: false,
|
||||
targetLabel: '空调温控器2', previewOnly: true, conditionLabel: '室温高于 25℃ 时计划制冷,低于 22℃ 时计划制热。' },
|
||||
{ actionKey: 'climate-heat-start', actionLabel: '室温偏低时开启空调制热', enabled: false,
|
||||
targetLabel: '空调温控器2', previewOnly: false, conditionLabel: '室温低于 22℃ 且空调关机时,开启制热并设为 22℃。' },
|
||||
{ actionKey: 'wake-fragrance-quick-release', actionLabel: '让香氛机「唤醒」出香一次', enabled: false,
|
||||
targetLabel: '香氛机 唤醒', previewOnly: false },
|
||||
{ actionKey: 'speaker-sleep-music', actionLabel: '用 Xiaomi Sound Pro 播放舒睡音乐', enabled: false,
|
||||
targetLabel: 'Xiaomi Sound Pro', previewOnly: false },
|
||||
],
|
||||
records: [...state.records,
|
||||
{ id: 'three', actionKey: 'dehumidifier-humidity-preview', targetLabel: '除湿机',
|
||||
triggeredAtMs: 1794382000000, result: 'preview-would-start' },
|
||||
{ id: 'four', actionKey: 'dehumidifier-humidity-start', targetLabel: '除湿机',
|
||||
triggeredAtMs: 1794383000000, result: 'readback-confirmed' },
|
||||
{ id: 'five', actionKey: 'climate-temperature-preview', targetLabel: '空调温控器2',
|
||||
triggeredAtMs: 1794384000000, result: 'preview-climate-cool' },
|
||||
{ id: 'six', actionKey: 'climate-heat-start', targetLabel: '空调温控器2',
|
||||
triggeredAtMs: 1794385000000, result: 'readback-confirmed' },
|
||||
{ id: 'seven', actionKey: 'wake-fragrance-quick-release', targetLabel: '香氛机 唤醒',
|
||||
triggeredAtMs: 1794386000000, result: 'fragrance-release-sent' },
|
||||
{ id: 'eight', actionKey: 'speaker-sleep-music', targetLabel: 'Xiaomi Sound Pro',
|
||||
triggeredAtMs: 1794387000000, result: 'speaker-playback-sent' }],
|
||||
} }, '/sleep-data', props)
|
||||
for (const text of ['开启联动', '停止预演', '超过 55% 且除湿机关机时', '除湿机 · 已确认开启', '除湿机 · 预演通过,计划开启除湿机',
|
||||
'按室温判断空调模式(预演)', '高于 25℃ 时计划制冷', '空调温控器2 · 预演通过,计划制冷',
|
||||
'室温偏低时开启空调制热', '低于 22℃ 且空调关机时', '空调温控器2 · 已确认制热至 22℃',
|
||||
'香氛机 唤醒 · 已发送一次快速出香指令', 'Xiaomi Sound Pro · 已发送舒睡音乐播放指令'])
|
||||
assert.ok(both.includes(text), text)
|
||||
})
|
||||
|
||||
const sleepBed = { id: 'left-bed', bedName: '卧室左侧', side: 'left', simulation: true, endedAtMs: null }
|
||||
const rightBed = { id: 'right-bed', bedName: '卧室右侧', side: 'right', simulation: false, endedAtMs: null }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user