Skip to content

Commit 951864b

Browse files
authored
fix: Edit message not fetching image description (#6570)
1 parent e589735 commit 951864b

File tree

4 files changed

+44
-34
lines changed

4 files changed

+44
-34
lines changed

app/containers/MessageComposer/MessageComposer.test.tsx

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,31 @@ jest.mock('./hooks/useSubscription', () => ({
4747
useSubscription: jest.fn(() => ({
4848
rid: 'rid',
4949
t: 'd',
50-
name: 'Room Name',
51-
fname: 'Room Name',
50+
tmid: undefined,
51+
name: 'Rocket Chat',
52+
fname: 'Rocket Chat',
5253
usernames: ['user1', 'user2'],
5354
prid: undefined,
5455
federated: false
5556
}))
5657
}));
5758

59+
jest.mock('../../lib/database/services/Message', () => ({
60+
getMessageById: (messageId: any) => ({
61+
id: messageId,
62+
rid: 'rid',
63+
msg: messageId !== 'image' ? `Message ${messageId}` : undefined,
64+
attachments:
65+
messageId === 'image'
66+
? [
67+
{
68+
description: `Attachment description for ${messageId}`
69+
}
70+
]
71+
: []
72+
})
73+
}));
74+
5875
const initialContext = {
5976
rid: 'rid',
6077
tmid: undefined,
@@ -131,16 +148,6 @@ beforeEach(() => {
131148
keyboardHeightSharedValue.value = 0;
132149
});
133150

134-
jest.mock('./hooks/useSubscription', () => ({
135-
useSubscription: jest.fn().mockReturnValue({
136-
t: 'd',
137-
rid: 'rid',
138-
tmid: undefined,
139-
fname: 'Rocket Chat',
140-
name: 'Rocket Chat'
141-
})
142-
}));
143-
144151
describe('MessageComposer', () => {
145152
describe('Toolbar', () => {
146153
test('tap actions', async () => {
@@ -414,6 +421,17 @@ describe('MessageComposer', () => {
414421
});
415422
});
416423

424+
describe('edit image description', () => {
425+
const editRequest = jest.fn();
426+
const id = 'image';
427+
test('edit image', async () => {
428+
render(<Render context={{ rid: 'rid', selectedMessages: [id], action: 'edit', editRequest }} />);
429+
await screen.findByTestId('message-composer');
430+
await user.press(screen.getByTestId('message-composer-send'));
431+
expect(editRequest).toHaveBeenCalledWith({ id, msg: `Attachment description for ${id}`, rid: 'rid' });
432+
});
433+
});
434+
417435
const messageIds = ['abc', 'def'];
418436
jest.mock('./hooks/useMessage', () => ({
419437
useMessage: (messageId: string) => {

app/containers/MessageComposer/__snapshots__/MessageComposer.test.tsx.snap

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ exports[`MessageComposer Audio tap record 1`] = `
8282
borderless={true}
8383
collapsable={false}
8484
delayLongPress={600}
85-
handlerTag={203}
85+
handlerTag={206}
8686
handlerType="NativeViewGestureHandler"
8787
hitSlop={
8888
{
@@ -177,7 +177,7 @@ exports[`MessageComposer Audio tap record 1`] = `
177177
borderless={true}
178178
collapsable={false}
179179
delayLongPress={600}
180-
handlerTag={204}
180+
handlerTag={207}
181181
handlerType="NativeViewGestureHandler"
182182
hitSlop={
183183
{
@@ -299,7 +299,7 @@ exports[`MessageComposer Quote Add quote \`abc\` 1`] = `
299299
borderless={true}
300300
collapsable={false}
301301
delayLongPress={600}
302-
handlerTag={190}
302+
handlerTag={193}
303303
handlerType="NativeViewGestureHandler"
304304
hitSlop={
305305
{
@@ -414,7 +414,7 @@ exports[`MessageComposer Quote Add quote \`abc\` 1`] = `
414414
borderless={true}
415415
collapsable={false}
416416
delayLongPress={600}
417-
handlerTag={191}
417+
handlerTag={194}
418418
handlerType="NativeViewGestureHandler"
419419
hitSlop={
420420
{
@@ -586,7 +586,7 @@ exports[`MessageComposer Quote Add quote \`abc\` 1`] = `
586586
borderless={true}
587587
collapsable={false}
588588
delayLongPress={600}
589-
handlerTag={192}
589+
handlerTag={195}
590590
handlerType="NativeViewGestureHandler"
591591
hitSlop={
592592
{
@@ -743,7 +743,7 @@ exports[`MessageComposer Quote Add quote \`def\` 1`] = `
743743
borderless={true}
744744
collapsable={false}
745745
delayLongPress={600}
746-
handlerTag={193}
746+
handlerTag={196}
747747
handlerType="NativeViewGestureHandler"
748748
hitSlop={
749749
{
@@ -858,7 +858,7 @@ exports[`MessageComposer Quote Add quote \`def\` 1`] = `
858858
borderless={true}
859859
collapsable={false}
860860
delayLongPress={600}
861-
handlerTag={194}
861+
handlerTag={197}
862862
handlerType="NativeViewGestureHandler"
863863
hitSlop={
864864
{
@@ -1031,7 +1031,7 @@ exports[`MessageComposer Quote Add quote \`def\` 1`] = `
10311031
borderless={true}
10321032
collapsable={false}
10331033
delayLongPress={600}
1034-
handlerTag={195}
1034+
handlerTag={198}
10351035
handlerType="NativeViewGestureHandler"
10361036
hitSlop={
10371037
{
@@ -1212,7 +1212,7 @@ exports[`MessageComposer Quote Add quote \`def\` 1`] = `
12121212
borderless={true}
12131213
collapsable={false}
12141214
delayLongPress={600}
1215-
handlerTag={196}
1215+
handlerTag={199}
12161216
handlerType="NativeViewGestureHandler"
12171217
hitSlop={
12181218
{
@@ -1369,7 +1369,7 @@ exports[`MessageComposer Quote Remove a quote 1`] = `
13691369
borderless={true}
13701370
collapsable={false}
13711371
delayLongPress={600}
1372-
handlerTag={197}
1372+
handlerTag={200}
13731373
handlerType="NativeViewGestureHandler"
13741374
hitSlop={
13751375
{
@@ -1484,7 +1484,7 @@ exports[`MessageComposer Quote Remove a quote 1`] = `
14841484
borderless={true}
14851485
collapsable={false}
14861486
delayLongPress={600}
1487-
handlerTag={198}
1487+
handlerTag={201}
14881488
handlerType="NativeViewGestureHandler"
14891489
hitSlop={
14901490
{
@@ -1657,7 +1657,7 @@ exports[`MessageComposer Quote Remove a quote 1`] = `
16571657
borderless={true}
16581658
collapsable={false}
16591659
delayLongPress={600}
1660-
handlerTag={199}
1660+
handlerTag={202}
16611661
handlerType="NativeViewGestureHandler"
16621662
hitSlop={
16631663
{
@@ -1838,7 +1838,7 @@ exports[`MessageComposer Quote Remove a quote 1`] = `
18381838
borderless={true}
18391839
collapsable={false}
18401840
delayLongPress={600}
1841-
handlerTag={200}
1841+
handlerTag={203}
18421842
handlerType="NativeViewGestureHandler"
18431843
hitSlop={
18441844
{

app/containers/MessageComposer/components/ComposerInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const ComposerInput = memo(
9090
const fetchMessageAndSetInput = async () => {
9191
const message = await getMessageById(selectedMessages[0]);
9292
if (message) {
93-
setInput(message?.msg || '');
93+
setInput(message?.msg || message?.attachments?.[0]?.description || '');
9494
}
9595
};
9696

jest.setup.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,6 @@ jest.mock('./app/lib/hooks/useFrequentlyUsedEmoji', () => ({
8484
})
8585
}));
8686

87-
jest.mock('./app/lib/database/services/Message', () => ({
88-
getMessageById: messageId => ({
89-
id: messageId,
90-
rid: 'rid',
91-
msg: `Message ${messageId}`
92-
})
93-
}));
94-
9587
jest.mock('react-native/Libraries/Utilities/useWindowDimensions', () => ({
9688
__esModule: true,
9789
default: jest.fn(() => ({

0 commit comments

Comments
 (0)