Skip to content

Commit ea2ab49

Browse files
add waiter to avoid test flakiness
1 parent 8c3e2fe commit ea2ab49

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import type { IMessage, MessageAttachment } from '@rocket.chat/core-typings';
2+
3+
import { useKeepMountedMessages } from './useKeepMountedMessages';
4+
5+
const baseMessage = (overrides: Partial<IMessage> = {}): IMessage => ({
6+
_id: 'messageId',
7+
rid: 'roomId',
8+
msg: 'text',
9+
ts: new Date(),
10+
u: { _id: 'userId', username: 'userName' },
11+
_updatedAt: new Date(),
12+
...overrides,
13+
});
14+
15+
const fileAttachment: MessageAttachment = { type: 'file' } as MessageAttachment;
16+
17+
const quoteAttachment = (attachments?: MessageAttachment[]): MessageAttachment =>
18+
({
19+
author_name: 'author',
20+
author_icon: 'icon',
21+
message_link: 'https://example.com/msg',
22+
text: 'quoted text',
23+
attachments,
24+
}) as MessageAttachment;
25+
26+
it('should not keep a plain text message mounted', () => {
27+
const messages = [baseMessage()];
28+
expect(useKeepMountedMessages(messages)).toEqual([]);
29+
});
30+
31+
it('should keep a message with files mounted', () => {
32+
const messages = [baseMessage({ files: [{ _id: 'fileId', name: 'file', type: 'file' }] })];
33+
expect(useKeepMountedMessages(messages)).toEqual([0]);
34+
});
35+
36+
it('should keep a message with a URL preview mounted', () => {
37+
const messages = [baseMessage({ urls: [{ url: 'https://example.com', meta: { ogTitle: 'title' } }] })];
38+
expect(useKeepMountedMessages(messages)).toEqual([0]);
39+
});
40+
41+
it('should keep a message quoting a file attachment mounted', () => {
42+
const messages = [baseMessage({ attachments: [quoteAttachment([fileAttachment])] })];
43+
expect(useKeepMountedMessages(messages)).toEqual([0]);
44+
});
45+
46+
it('should keep a message quoting a quote of a file attachment mounted (recursive)', () => {
47+
const messages = [baseMessage({ attachments: [quoteAttachment([quoteAttachment([fileAttachment])])] })];
48+
expect(useKeepMountedMessages(messages)).toEqual([0]);
49+
});
50+
51+
it('should not keep a message quoting text (no nested file) mounted', () => {
52+
const messages = [baseMessage({ attachments: [quoteAttachment()] })];
53+
expect(useKeepMountedMessages(messages)).toEqual([]);
54+
});
55+
56+
it('should offset indexes by one when canPreview is true', () => {
57+
const messages = [baseMessage(), baseMessage({ files: [{ _id: 'fileId', name: 'file', type: 'file' }] })];
58+
expect(useKeepMountedMessages(messages, true)).toEqual([2]);
59+
});

apps/meteor/tests/e2e/message-attachment-collapse.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ test.describe.serial('Message Attachment Collapse', () => {
3737
});
3838
};
3939

40+
const waitForFloodToSettle = async (api: BaseTest['api'], channel: string): Promise<void> => {
41+
const marker = `flood settled ${faker.string.uuid()}`;
42+
await api.post('/chat.postMessage', { channel, text: marker });
43+
await expect(poHomeChannel.content.mainMessageList.getByText(marker)).toBeVisible();
44+
};
45+
4046
test.describe('Default preference (expanded by default)', () => {
4147
let targetChannel: string;
4248

@@ -88,6 +94,7 @@ test.describe.serial('Message Attachment Collapse', () => {
8894
await expect(poHomeChannel.content.mainMessageList.getByText(text)).toBeHidden();
8995

9096
await floodChannel(api, targetChannel, 30);
97+
await waitForFloodToSettle(api, targetChannel);
9198

9299
await scrollUp();
93100

@@ -130,6 +137,7 @@ test.describe.serial('Message Attachment Collapse', () => {
130137
await expect(poHomeChannel.content.mainMessageList.getByText(text)).toBeVisible();
131138

132139
await floodChannel(api, targetChannel, 30);
140+
await waitForFloodToSettle(api, targetChannel);
133141

134142
await scrollUp();
135143

0 commit comments

Comments
 (0)