88 lines
4.3 KiB
JavaScript
88 lines
4.3 KiB
JavaScript
// The copy table: what a candidate becomes on screen, and how the settings page
|
|
// describes the newest delivery. Assertions use the real Chinese dictionary, so
|
|
// a key rename in the dictionaries and a rename here cannot drift apart.
|
|
import { test } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
|
|
import { createCopy } from '../../src/client/core/copy.js'
|
|
import { createTranslator } from '../../src/client/i18n/index.js'
|
|
|
|
const t = createTranslator({ getSnapshot: () => ({ active: 'zh' }) })
|
|
const { copyFor, describeDelivery, describeReplay } = createCopy(t)
|
|
|
|
/** One trigger candidate with every field a caller may leave empty. */
|
|
function candidate(overrides) {
|
|
return { kind: 'completion', sessionId: 'session-1', title: '标题', detail: '', pendingKind: '', ...overrides }
|
|
}
|
|
|
|
test('a finished conversation names the trigger as the title and the conversation as the body', () => {
|
|
assert.deepEqual(copyFor(candidate()), {
|
|
kind: 'completion',
|
|
title: '会话已完成',
|
|
body: '标题 已完成这一轮回答',
|
|
})
|
|
})
|
|
|
|
test('an empty title falls back to the untitled copy', () => {
|
|
assert.equal(copyFor(candidate({ title: '' })).body, '未命名会话 已完成这一轮回答')
|
|
})
|
|
|
|
test('an approval names the waiting tool when the client publishes one', () => {
|
|
const notice = copyFor(candidate({ kind: 'approval', pendingKind: 'approval', detail: 'Bash' }))
|
|
assert.deepEqual(notice, {
|
|
kind: 'approval',
|
|
title: '需要授权',
|
|
body: '标题:工具 Bash 正在等待你的授权',
|
|
})
|
|
})
|
|
|
|
test('an approval without a tool name still says what is happening', () => {
|
|
const notice = copyFor(candidate({ kind: 'approval', pendingKind: 'approval', detail: '' }))
|
|
assert.equal(notice.body, '标题:有工具正在等待你的授权')
|
|
})
|
|
|
|
test('a question carries the question text, and a plan review the plan\'s own text', () => {
|
|
const question = copyFor(candidate({ kind: 'question', pendingKind: 'question', detail: '要继续吗?' }))
|
|
assert.deepEqual(question, { kind: 'question', title: '需要回答', body: '标题 · 要继续吗?' })
|
|
assert.equal(copyFor(candidate({ kind: 'question', pendingKind: 'question', detail: '' })).body, '标题:正在等待你的回答')
|
|
|
|
// v1.0.6 behavior, pinned on purpose: a plan review is queued with
|
|
// `kind: 'question'`, so the question branch above answers it and the
|
|
// `body.planReview` copy is unreachable. See the note in core/copy.js — fixing
|
|
// it changes what a plan review says, so it is not part of this refactor.
|
|
const review = copyFor(candidate({ kind: 'question', pendingKind: 'plan-review', detail: '' }))
|
|
assert.equal(review.kind, 'question')
|
|
assert.equal(review.body, '标题:正在等待你的回答')
|
|
assert.notEqual(review.body, t('body.planReview', { title: '标题' }))
|
|
})
|
|
|
|
test('a delivery that never happened is described as such', () => {
|
|
assert.equal(describeDelivery(null, t), '还没有投递过')
|
|
assert.equal(describeDelivery(undefined, t), '还没有投递过')
|
|
})
|
|
|
|
test('the newest delivery is described by channel, confirmation and local time', () => {
|
|
const system = describeDelivery({ outcome: 'system', shown: true, at: '17:52:30', title: '会话已完成' }, t)
|
|
assert.equal(system, '最近一次投递: 17:52:30 · 系统通知(系统已确认弹出) · 会话已完成')
|
|
|
|
const unconfirmed = describeDelivery({ outcome: 'system', shown: undefined, at: '17:52:30', title: 'X' }, t)
|
|
assert.match(unconfirmed, /系统没有回报/)
|
|
|
|
const refused = describeDelivery({ outcome: 'system', shown: false, at: '17:52:30', title: 'X' }, t)
|
|
assert.match(refused, /没弹出来/)
|
|
|
|
const fellBack = describeDelivery({ outcome: 'system-refused-threw', shown: undefined, at: '17:52:30', title: 'X' }, t)
|
|
assert.match(fellBack, /系统通知被拒绝,改用了轻弹窗/)
|
|
|
|
const replayed = describeDelivery({ outcome: 'replay', at: '17:52:30', title: 'X' }, t)
|
|
assert.match(replayed, /应用内轻弹窗(回到窗口时补发)/)
|
|
|
|
const popup = describeDelivery({ outcome: 'popup', at: '17:52:30', title: 'X' }, t)
|
|
assert.match(popup, /· 应用内轻弹窗 ·/)
|
|
})
|
|
|
|
test('the replay line counts what is still waiting', () => {
|
|
assert.equal(describeReplay(0, t), '没有待补发的提醒')
|
|
assert.equal(describeReplay(3, t), '等你回到窗口时补发:3 条')
|
|
})
|