Skip to content

Commit 93336b4

Browse files
authored
fix: url not append to the button when nested (#262)
1 parent 60afd8b commit 93336b4

File tree

5 files changed

+61
-2
lines changed

5 files changed

+61
-2
lines changed

packages/telegram-adapter/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
module.exports = {
33
preset: "ts-jest",
44
testEnvironment: "node",
5-
testPathIgnorePatterns: ["dist"],
5+
testMatch: ["**/*.spec.tsx", "**/*.spec.ts"],
66
};

packages/telegram-adapter/src/renderer.spec.tsx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,4 +294,60 @@ describe("renderElement", () => {
294294
expect(rendered.reply_markup.inline_keyboard[0].length).toBe(2);
295295
expect(rendered.reply_markup.inline_keyboard[1].length).toBe(1);
296296
});
297+
298+
describe("command with url", () => {
299+
it("should render button with url", () => {
300+
const buttonElement = new MockComponent("18", InstanceType.Command, {
301+
variant: "button",
302+
command: "https://example.com",
303+
});
304+
const rendered = renderElement(buttonElement, parser);
305+
expect((rendered.reply_markup!.inline_keyboard[0][0] as any).url).toEqual(
306+
"https://example.com",
307+
);
308+
});
309+
});
310+
311+
it("should render button with url in a row", () => {
312+
const buttonElement = new MockComponent("18", InstanceType.Command, {
313+
variant: "button",
314+
command: "https://example.com",
315+
});
316+
317+
const containerElement = new MockComponent(
318+
"19",
319+
InstanceType.Container,
320+
{},
321+
);
322+
323+
containerElement.appendChild(buttonElement);
324+
325+
const rendered = renderElement(containerElement, parser);
326+
expect((rendered.reply_markup!.inline_keyboard[0][0] as any).url).toEqual(
327+
"https://example.com",
328+
);
329+
});
330+
331+
it("should render button with url in a col", () => {
332+
const buttonElement = new MockComponent("18", InstanceType.Command, {
333+
variant: "button",
334+
command: "https://example.com",
335+
});
336+
337+
const containerElement = new MockComponent(
338+
"19",
339+
InstanceType.Container,
340+
{},
341+
);
342+
343+
const row1 = new MockComponent("20", InstanceType.Container, {});
344+
345+
row1.appendChild(buttonElement);
346+
containerElement.appendChild(row1);
347+
348+
const rendered = renderElement(containerElement, parser);
349+
expect((rendered.reply_markup!.inline_keyboard[0][0] as any).url).toEqual(
350+
"https://example.com",
351+
);
352+
});
297353
});

packages/telegram-adapter/src/renderer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ export const renderElement = (
164164
text: child.text,
165165
callback_data: child.callback_data,
166166
web_app: child.web_app,
167+
url: child.url,
167168
});
168169
} else {
169170
processResult(child, level + 1);
@@ -211,6 +212,7 @@ export const renderElement = (
211212
text: button.text,
212213
callback_data: button.callback_data,
213214
web_app: button.web_app,
215+
url: button.url,
214216
}));
215217
}
216218
return [];

packages/telegram-adapter/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"include": ["src/**/*"],
3-
"exclude": ["**/*.spec.ts"],
3+
"exclude": ["**/*.spec.ts", "**/*.spec.tsx"],
44
"extends": "../typescript-config/react-library.json",
55
"compilerOptions": {
66
"outDir": "dist",

tests/telegram-e2e-tests/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"esModuleInterop": true,
88
"module": "esnext",
99
"moduleResolution": "bundler",
10+
"inlineSourceMap": true,
1011
"target": "ES2020",
1112
"lib": ["DOM", "DOM.Iterable", "ESNext"],
1213
"skipLibCheck": true,

0 commit comments

Comments
 (0)