Personal Telegram developer console for GitHub

test: verify quick menu precedence and focused paste delivery

davoodmehraban89 committed Oct 4, 2026 at 06:59 UTC 6b87cc549454df52717a2e2e8af86bb5a1adaf11
1 file changed +35 -41
test/telegram-persistent-menu-input.test.js
+35 -41
@@ -1,39 +1,9 @@
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';
4
5 const WORKSPACE_ID = 'W000000001';
6
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 -
7 test('/start installs a persistent bottom quick menu and still sends the inline main menu', async () => {
8 const bot = new NexaDevBot({});
9 const sent = [];
@@ -91,17 +61,41 @@ test('persistent menu text has precedence over pending draft input', async () =>
61 assert.match(sent.at(-1).text, /Nexa Dev Bot/);
62 });
63
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' });
64 +test('Paste text opens a focused ForceReply prompt without replacing the workspace message', async () => {
65 + const bot = new NexaDevBot({});
66 + const sent = [];
67 + const edited = [];
68 +
69 + bot.telegram.answerCallbackQuery = async () => ({ ok: true });
70 + bot.telegram.sendMessage = async (chatId, text, replyMarkup) => {
71 + sent.push({ chatId, text, replyMarkup });
72 + return { ok: true };
73 + };
74 + bot.telegram.editMessageText = async (...args) => {
75 + edited.push(args);
76 + return { ok: true };
77 + };
78 + bot.router.dispatchCallback = async (data) => {
79 + assert.equal(data, `wtext:${WORKSPACE_ID}`);
80 + return {
81 + text: '📝 متن جدید Draft را ارسال کنید',
82 + reply_markup: { inline_keyboard: [[{ text: '↩️ بازگشت', callback_data: `ws:${WORKSPACE_ID}` }]] }
83 + };
84 + };
85
99 - const prompt = await route.execute();
86 + const result = await bot.handleCallbackQuery({
87 + id: 'cb-paste',
88 + data: `wtext:${WORKSPACE_ID}`,
89 + from: { id: 42 },
90 + message: { message_id: 55, chat: { id: 7 } }
91 + });
92
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' });
93 + assert.equal(result.ok, true);
94 + assert.equal(result.inputPrompt, true);
95 + assert.equal(edited.length, 0);
96 + assert.equal(sent.length, 1);
97 + assert.equal(sent[0].replyMarkup.force_reply, true);
98 + assert.equal(sent[0].replyMarkup.selective, true);
99 + assert.match(sent[0].replyMarkup.input_field_placeholder, /Paste|کد|متن/i);
100 + assert.equal(sent[0].replyMarkup.inline_keyboard, undefined);
101 });