Personal Telegram developer console for GitHub
test: define persistent menu and focused code input behavior
davoodmehraban89 committed
Oct 4, 2026 at 06:55 UTC
ef0f1b2ba79ef3042240e5069028c165f842b3db
1 file changed
+107
test/telegram-persistent-menu-input.test.js
new
+107
@@ -0,0 +1,107 @@
1
+import test from 'node:test';
2
+import assert from 'node:assert/strict';
3
+import { NexaDevBot } from '../src/bot.js';
4
+import { createWorkspaceController } from '../src/plugins/github/workspace.js';
5
+
6
+const WORKSPACE_ID = 'W000000001';
7
+
8
+function makeWorkspaceStore() {
9
+ const workspace = {
10
+ id: WORKSPACE_ID,
11
+ repoId: 123,
12
+ repoFullName: 'davood/demo',
13
+ baseBranch: 'main',
14
+ baseHeadSha: 'a'.repeat(40),
15
+ baseTreeSha: 'b'.repeat(40),
16
+ path: 'src/app.js',
17
+ blobSha: 'c'.repeat(40),
18
+ originalText: 'before\n',
19
+ originalDigest: '0'.repeat(64),
20
+ draftText: 'before\n',
21
+ draftDigest: '0'.repeat(64),
22
+ commitMessage: '',
23
+ state: 'DRAFT'
24
+ };
25
+ let pending = null;
26
+ return {
27
+ workspace,
28
+ async getWorkspace() { return structuredClone(workspace); },
29
+ async setPendingInput({ workspaceId, mode }) {
30
+ pending = { workspaceId, mode };
31
+ return structuredClone(pending);
32
+ },
33
+ async getPendingInput() { return pending ? structuredClone(pending) : null; }
34
+ };
35
+}
36
+
37
+test('/start installs a persistent bottom quick menu and still sends the inline main menu', async () => {
38
+ const bot = new NexaDevBot({});
39
+ const sent = [];
40
+ bot.telegram.sendMessage = async (chatId, text, replyMarkup) => {
41
+ sent.push({ chatId, text, replyMarkup });
42
+ return { ok: true, result: { message_id: 100 + sent.length } };
43
+ };
44
+
45
+ const result = await bot.handleMessage({ chat: { id: 7 }, from: { id: 42 }, text: '/start' });
46
+
47
+ assert.equal(result.ok, true);
48
+ assert.equal(sent.length, 2);
49
+ assert.equal(sent[0].replyMarkup.is_persistent, true);
50
+ assert.equal(sent[0].replyMarkup.resize_keyboard, true);
51
+ assert.deepEqual(sent[0].replyMarkup.keyboard.flat().map(button => button.text), [
52
+ '🏠 منوی اصلی',
53
+ '📁 پروژهها',
54
+ '📊 وضعیت',
55
+ '🔧 ابزارها',
56
+ '🔐 امنیت'
57
+ ]);
58
+ assert.ok(sent[1].replyMarkup.inline_keyboard);
59
+});
60
+
61
+test('persistent menu text has precedence over pending draft input', async () => {
62
+ const bot = new NexaDevBot({});
63
+ let pendingReads = 0;
64
+ let workspaceDispatches = 0;
65
+ const sent = [];
66
+
67
+ bot.workspaceStore = {
68
+ isConfigured: () => true,
69
+ async getPendingInput() {
70
+ pendingReads += 1;
71
+ return { workspaceId: WORKSPACE_ID, mode: 'draft' };
72
+ }
73
+ };
74
+ bot.router = {
75
+ async dispatchMessage() {
76
+ workspaceDispatches += 1;
77
+ return { text: 'should not happen', reply_markup: { inline_keyboard: [] } };
78
+ }
79
+ };
80
+ bot.telegram.sendMessage = async (chatId, text, replyMarkup) => {
81
+ sent.push({ chatId, text, replyMarkup });
82
+ return { ok: true };
83
+ };
84
+
85
+ const result = await bot.handleMessage({ chat: { id: 7 }, from: { id: 42 }, text: '🏠 منوی اصلی' });
86
+
87
+ assert.equal(result.ok, true);
88
+ assert.equal(result.quickMenu, 'main');
89
+ assert.equal(pendingReads, 0);
90
+ assert.equal(workspaceDispatches, 0);
91
+ assert.match(sent.at(-1).text, /Nexa Dev Bot/);
92
+});
93
+
94
+test('Paste text prepares a focused ForceReply code input instead of replacing the workspace message', async () => {
95
+ const workspaces = makeWorkspaceStore();
96
+ const controller = createWorkspaceController({ github: {}, workspaces });
97
+ const route = controller.resolveCallback(`wtext:${WORKSPACE_ID}`, { ownerId: '42' });
98
+
99
+ const prompt = await route.execute();
100
+
101
+ assert.equal(prompt.delivery, 'send');
102
+ assert.equal(prompt.reply_markup.force_reply, true);
103
+ assert.equal(prompt.reply_markup.selective, true);
104
+ assert.match(prompt.reply_markup.input_field_placeholder, /Paste|کد|متن/i);
105
+ assert.equal(prompt.reply_markup.inline_keyboard, undefined);
106
+ assert.deepEqual(await workspaces.getPendingInput(), { workspaceId: WORKSPACE_ID, mode: 'draft' });
107
+});