52 lines
2.0 KiB
JavaScript
52 lines
2.0 KiB
JavaScript
const assert = require('node:assert/strict');
|
|
const { readFileSync } = require('node:fs');
|
|
const { test } = require('node:test');
|
|
const ts = require('typescript');
|
|
|
|
const source = ts.createSourceFile(
|
|
'AccountManagementList.tsx',
|
|
readFileSync(`${__dirname}/../src/components/accounts/AccountManagementList.tsx`, 'utf8'),
|
|
ts.ScriptTarget.Latest,
|
|
true,
|
|
ts.ScriptKind.TSX,
|
|
);
|
|
const code = source.getFullText();
|
|
|
|
test('列表展示粉丝、关注、获赞、互关、评论独立数值列', () => {
|
|
for (const [title, value] of [
|
|
['粉丝', 'account.follower_count'],
|
|
['关注', 'account.following_count'],
|
|
['获赞', 'account.total_favorited'],
|
|
['互关', 'account.friend_count'],
|
|
['评论', 'account.comment_total'],
|
|
]) {
|
|
assert.ok(
|
|
code.includes(`title: '${title}',\n render: (_, account) => formatCount(${value}),`),
|
|
`${title} 应为独立数值列`,
|
|
);
|
|
}
|
|
});
|
|
|
|
test('操作列包含「启动」:先启动环境再弹出登录画面', () => {
|
|
assert.match(code, /onClick=\{\(\) => startAccount\(account\)\}/);
|
|
assert.match(code, /\/phase-a\/accounts\/\$\{encodeURIComponent\(row\.id\)\}\/start/);
|
|
assert.match(code, /setLoginTarget\(row\)/);
|
|
assert.match(code, /<AccountLoginModal accountID=\{loginTarget\.id\}/);
|
|
assert.ok(code.indexOf('await creatorAction(`/phase-a/accounts/') < code.indexOf('setLoginTarget(row)'));
|
|
});
|
|
|
|
test('登录弹窗共享自动流程,成功刷新列表,关闭后卸载弹窗', () => {
|
|
assert.match(code, /loginTarget \? \(/);
|
|
assert.match(code, /onClose=\{\(\) => setLoginTarget\(null\)\}/);
|
|
assert.match(code, /onSuccess=\{\(\) => \{ void load\(\); \}\}/);
|
|
assert.doesNotMatch(code, /刷新登录画面|核验浏览器身份|requestLoginQR|verifyLogin/);
|
|
});
|
|
|
|
test('启动失败走 conflictMessage 透传 409 就绪原因', () => {
|
|
assert.ok(
|
|
code.includes(
|
|
"messageApi.error(conflictMessage(startError, '启动未完成:账号或环境不满足就绪条件,请按不可运行原因处理后重试。'));",
|
|
),
|
|
);
|
|
});
|