|
| 1 | +import { Telegram, Utils } from "@rx-lab/testing"; |
| 2 | + |
| 3 | +const { |
| 4 | + PORT, |
| 5 | + Api, |
| 6 | + initialize, |
| 7 | + TestingEnvironment, |
| 8 | + MessageType, |
| 9 | + DEFAULT_RENDERING_WAIT_TIME, |
| 10 | +} = Telegram; |
| 11 | +const { sleep } = Utils; |
| 12 | + |
| 13 | +const chatroomId = 2104; |
| 14 | + |
| 15 | +describe("error page with redirect", () => { |
| 16 | + let api: Telegram.Api<any>; |
| 17 | + let coreApi: any; |
| 18 | + |
| 19 | + beforeAll(async () => { |
| 20 | + api = new Api({ |
| 21 | + baseUrl: `http://0.0.0.0:${PORT}`, |
| 22 | + }); |
| 23 | + }); |
| 24 | + |
| 25 | + it("should render the error page using the default one", async () => { |
| 26 | + const { core } = await initialize({ |
| 27 | + filename: import.meta.url, |
| 28 | + environment: TestingEnvironment.LongPolling, |
| 29 | + api, |
| 30 | + chatroomId, |
| 31 | + }); |
| 32 | + coreApi = core; |
| 33 | + |
| 34 | + await api.chatroom.sendMessageToChatroom(chatroomId, { |
| 35 | + content: "Hello", |
| 36 | + type: MessageType.Text, |
| 37 | + }); |
| 38 | + await sleep(DEFAULT_RENDERING_WAIT_TIME); |
| 39 | + let messages = await api.chatroom.getMessagesByChatroom(chatroomId); |
| 40 | + expect(messages.data.count).toBe(2); |
| 41 | + let currentMessage = messages.data.messages[1]; |
| 42 | + expect(currentMessage!.text).toContain("Home"); |
| 43 | + |
| 44 | + // click on the error button |
| 45 | + await api.chatroom.clickOnMessageInChatroom( |
| 46 | + chatroomId, |
| 47 | + currentMessage!.message_id, |
| 48 | + { |
| 49 | + text: "Go to error", |
| 50 | + }, |
| 51 | + ); |
| 52 | + await sleep(DEFAULT_RENDERING_WAIT_TIME); |
| 53 | + messages = await api.chatroom.getMessagesByChatroom(chatroomId); |
| 54 | + currentMessage = messages.data.messages[1]; |
| 55 | + expect(currentMessage!.text).toContain("Enter something"); |
| 56 | + |
| 57 | + // enter a text |
| 58 | + await api.chatroom.sendMessageToChatroom(chatroomId, { |
| 59 | + content: "error", |
| 60 | + type: MessageType.Text, |
| 61 | + }); |
| 62 | + await sleep(DEFAULT_RENDERING_WAIT_TIME); |
| 63 | + messages = await api.chatroom.getMessagesByChatroom(chatroomId); |
| 64 | + currentMessage = messages.data.messages[3]; |
| 65 | + expect(currentMessage!.text).toContain("500"); |
| 66 | + |
| 67 | + // enter a text again |
| 68 | + await api.chatroom.sendMessageToChatroom(chatroomId, { |
| 69 | + content: "hi", |
| 70 | + type: MessageType.Text, |
| 71 | + }); |
| 72 | + |
| 73 | + await sleep(DEFAULT_RENDERING_WAIT_TIME); |
| 74 | + messages = await api.chatroom.getMessagesByChatroom(chatroomId); |
| 75 | + currentMessage = messages.data.messages[5]; |
| 76 | + expect(currentMessage!.text).toContain("Home"); |
| 77 | + }); |
| 78 | + |
| 79 | + afterEach(async () => { |
| 80 | + await coreApi?.onDestroy(); |
| 81 | + }); |
| 82 | +}); |
0 commit comments