Skip to content

Commit 53b224b

Browse files
committed
test: randomize generateMessage timestamp
1 parent aadc74a commit 53b224b

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

src/components/MessageList/__tests__/MessageList.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,10 @@ describe('MessageList', () => {
240240
fireEvent.scroll(getByTestId('message-flat-list'), eventDataUp);
241241

242242
act(() => {
243-
const newMessage = generateMessage({ user: user2 });
243+
const newMessage = generateMessage({
244+
timestamp: new Date(),
245+
user: user2,
246+
});
244247
dispatchMessageNewEvent(chatClient, newMessage, mockedChannel.channel);
245248
});
246249

src/mock-builders/generator/message.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@ import { v4 as uuidv4, v5 as uuidv5 } from 'uuid';
22

33
import { generateUser } from './user';
44

5-
export const generateMessage = (options) => ({
6-
attachments: [],
7-
created_at: new Date().toString(),
8-
html: '<p>regular</p>',
9-
id: uuidv4(),
10-
text: uuidv4(),
11-
type: 'regular',
12-
updated_at: new Date().toString(),
13-
user: generateUser(),
14-
...options,
15-
});
5+
export const generateMessage = (options = {}) => {
6+
const timestamp =
7+
options.timestamp ||
8+
new Date(new Date().getTime() - Math.floor(Math.random() * 100000));
9+
10+
return {
11+
attachments: [],
12+
created_at: timestamp.toString(),
13+
html: '<p>regular</p>',
14+
id: uuidv4(),
15+
text: uuidv4(),
16+
type: 'regular',
17+
updated_at: timestamp.toString(),
18+
user: generateUser(),
19+
...options,
20+
};
21+
};
1622

1723
const StreamReactNativeNamespace = '9b244ee4-7d69-4d7b-ae23-cf89e9f7b035';
1824
export const generateStaticMessage = (seed, options, date) =>

0 commit comments

Comments
 (0)