Personal Telegram developer console for GitHub
test: define in-app V2 guide behavior
davoodmehraban89 committed
Oct 4, 2026 at 12:23 UTC
8d2b37477e1e595d9083887dbf8faabfa89ab0e6
1 file changed
+92
test/help-guide.test.js
new
+92
@@ -0,0 +1,92 @@
1
+import { describe, it } from 'node:test';
2
+import assert from 'node:assert/strict';
3
+import { MenuManager } from '../src/menu.js';
4
+import { NexaDevBot } from '../src/bot.js';
5
+
6
+const github = {
7
+ owner: 'davoodmehraban89',
8
+ async listRepositories() { return []; },
9
+ async getRepository(repo) {
10
+ return { id: repo, name: String(repo), fullName: `davoodmehraban89/${repo}`, private: true, defaultBranch: 'main', archived: false };
11
+ }
12
+};
13
+
14
+function callbacks(view) {
15
+ return (view.reply_markup?.inline_keyboard || []).flat().map(button => button.callback_data).filter(Boolean);
16
+}
17
+
18
+describe('Nexa Dev Bot - in-app V2 guide', () => {
19
+ const menu = new MenuManager(github);
20
+
21
+ it('exposes Guide from the main inline menu', () => {
22
+ const view = menu.getMainMenuView();
23
+ assert.ok(callbacks(view).includes('menu:help'));
24
+ assert.ok(view.reply_markup.inline_keyboard.flat().some(button => button.text.includes('راهنما')));
25
+ });
26
+
27
+ it('guide index and pages explain every major V2 control with navigable chapters', async () => {
28
+ const index = await menu.renderByCallback('menu:help');
29
+ assert.match(index.text, /راهنمای Nexa Dev.*V2/);
30
+ const indexCallbacks = callbacks(index);
31
+ for (const callback of ['help:1', 'help:2', 'help:3', 'help:4', 'help:5', 'help:6']) {
32
+ assert.ok(indexCallbacks.includes(callback), `missing ${callback}`);
33
+ }
34
+
35
+ const menuHelp = await menu.renderByCallback('help:1');
36
+ for (const label of ['منوی اصلی', 'پروژهها', 'وضعیت', 'ابزارها', 'امنیت', 'راهنما']) {
37
+ assert.ok(menuHelp.text.includes(label), `menu guide missing ${label}`);
38
+ }
39
+
40
+ const repoHelp = await menu.renderByCallback('help:2');
41
+ for (const label of ['فایلها', 'Pull Request', 'Commit', 'CI / Actions', 'Branches', 'Issues', 'Releases']) {
42
+ assert.ok(repoHelp.text.includes(label), `repo guide missing ${label}`);
43
+ }
44
+
45
+ const workspaceHelp = await menu.renderByCallback('help:3');
46
+ for (const label of ['Edit', 'Editor', 'بارگذاری فایل', 'Paste متن', 'پیام Commit', 'Diff', 'آماده Commit', 'لغو Draft']) {
47
+ assert.ok(workspaceHelp.text.includes(label), `workspace guide missing ${label}`);
48
+ }
49
+
50
+ const ciHelp = await menu.renderByCallback('help:5');
51
+ for (const label of ['Job', 'Artifacts', 'log', 'اجرای مجدد', 'لغو Workflow', 'بروزرسانی', 'جدیدتر', 'قدیمیتر']) {
52
+ assert.ok(ciHelp.text.includes(label), `CI guide missing ${label}`);
53
+ }
54
+ });
55
+
56
+ it('documents the complete file-edit flow from project selection through branch-only Safe Approval commit', async () => {
57
+ const view = await menu.renderByCallback('help:4');
58
+ const expected = [
59
+ 'پروژهها',
60
+ 'فایلها',
61
+ 'Edit',
62
+ 'Editor',
63
+ 'ذخیره Draft',
64
+ 'Diff',
65
+ 'پیام Commit',
66
+ 'آماده Commit',
67
+ 'Safe Approval',
68
+ 'تأیید و اجرا',
69
+ 'nexa/edit-',
70
+ 'main'
71
+ ];
72
+ for (const item of expected) assert.ok(view.text.includes(item), `file-edit guide missing ${item}`);
73
+ assert.match(view.text, /main.*مستقیم.*تغییر|شاخه.*پیش.?فرض.*تغییر.*نمی/);
74
+ });
75
+
76
+ it('keeps Guide in the persistent bottom keyboard and routes its text without consuming workspace input', async () => {
77
+ const bot = new NexaDevBot({});
78
+ const sent = [];
79
+ bot.telegram.sendMessage = async (chatId, text, replyMarkup) => {
80
+ sent.push({ chatId, text, replyMarkup });
81
+ return { ok: true };
82
+ };
83
+
84
+ await bot.handleMessage({ chat: { id: 1 }, from: { id: 1 }, text: '/start' });
85
+ const quickKeyboard = sent[0].replyMarkup.keyboard.flat().map(button => button.text);
86
+ assert.ok(quickKeyboard.includes('📘 راهنما'));
87
+
88
+ sent.length = 0;
89
+ await bot.handleMessage({ chat: { id: 1 }, from: { id: 1 }, text: '📘 راهنما' });
90
+ assert.match(sent[0].text, /راهنمای Nexa Dev.*V2/);
91
+ });
92
+});