-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMPROVE] Add message name container component to message name header…
… and system message (#27184)
- Loading branch information
1 parent
0e92ee0
commit ff3e5b9
Showing
15 changed files
with
248 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 3 additions & 11 deletions
14
apps/meteor/client/views/room/MessageList/hooks/useParentMessage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,7 @@ | ||
import { IMessage } from '@rocket.chat/core-typings'; | ||
import { useEffect } from 'react'; | ||
import { useQuery, UseQueryResult } from '@tanstack/react-query'; | ||
|
||
import { findParentMessage } from '../../../../../app/ui-message/client/messageThread'; | ||
import { AsyncState, useAsyncState } from '../../../../hooks/useAsyncState'; | ||
|
||
export const useParentMessage = (mid: IMessage['_id']): AsyncState<IMessage> => { | ||
const { resolve, reject, error, phase, value } = useAsyncState<IMessage>(); | ||
|
||
useEffect(() => { | ||
findParentMessage(mid).then(resolve).catch(reject); | ||
}, [mid, reject, resolve]); | ||
|
||
return { phase, value, error } as AsyncState<IMessage>; | ||
}; | ||
export const useParentMessage = (mid: IMessage['_id']): UseQueryResult<IMessage> => | ||
useQuery(['parent-message', { mid }], async () => findParentMessage(mid)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
apps/meteor/tests/unit/client/views/room/MessageList/ThreadMessagePreview.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { expect } from 'chai'; | ||
import proxyquire from 'proxyquire'; | ||
import React from 'react'; | ||
|
||
const date = new Date('2021-10-27T00:00:00.000Z'); | ||
const baseMessage = { | ||
ts: date, | ||
u: { | ||
_id: 'userId', | ||
name: 'userName', | ||
username: 'userName', | ||
}, | ||
msg: 'message', | ||
md: [ | ||
{ | ||
type: 'PARAGRAPH', | ||
value: [ | ||
{ | ||
type: 'PLAIN_TEXT', | ||
value: 'message', | ||
}, | ||
], | ||
}, | ||
], | ||
rid: 'roomId', | ||
_id: 'messageId', | ||
_updatedAt: date, | ||
urls: [], | ||
}; | ||
const COMPONENT_PATH = '../../../../../../client/views/room/MessageList/components/ThreadMessagePreview'; | ||
const defaultConfig = { | ||
'../../contexts/MessageContext': { | ||
useMessageActions: () => ({ | ||
actions: { | ||
openThread: () => () => '', | ||
}, | ||
}), | ||
}, | ||
'../hooks/useParentMessage': { | ||
useParentMessage: () => '', | ||
}, | ||
'../hooks/useMessageBody': { | ||
useMessageBody: () => <p>Parent Message</p>, | ||
}, | ||
'../../../../../app/ui-utils/client': { | ||
MessageTypes: { | ||
getType: () => false, | ||
}, | ||
}, | ||
'./ThreadMessagePreviewBody': ({ message }: { message: any }) => <span>{message.msg}</span>, | ||
}; | ||
|
||
describe('ThreadMessagePreview', () => { | ||
it('should render the message when exists', () => { | ||
const ThreadMessagePreview = proxyquire.noCallThru().load(COMPONENT_PATH, defaultConfig).default; | ||
|
||
render(<ThreadMessagePreview message={baseMessage} sequential={true} />); | ||
|
||
expect(screen.getByText(baseMessage.msg)).to.exist; | ||
}); | ||
|
||
it('should render ignored message', () => { | ||
const ThreadMessagePreview = proxyquire.noCallThru().load(COMPONENT_PATH, defaultConfig).default; | ||
|
||
const message = { ...baseMessage, ignored: true }; | ||
render(<ThreadMessagePreview message={message} sequential={true} />); | ||
|
||
expect(screen.getByText('Message_Ignored')).to.exist; | ||
}); | ||
|
||
it('should render parent message', () => { | ||
const ThreadMessagePreview = proxyquire.noCallThru().load(COMPONENT_PATH, { | ||
...defaultConfig, | ||
'../hooks/useParentMessage': { | ||
useParentMessage: () => ({ | ||
isSuccess: true, | ||
}), | ||
}, | ||
}).default; | ||
|
||
render(<ThreadMessagePreview message={baseMessage} sequential={false} />); | ||
|
||
expect(screen.getByText('Parent Message')).to.exist; | ||
}); | ||
|
||
it('should render parent system message', () => { | ||
const ThreadMessagePreview = proxyquire.noCallThru().load(COMPONENT_PATH, { | ||
...defaultConfig, | ||
'../hooks/useParentMessage': { | ||
useParentMessage: () => ({ | ||
isSuccess: true, | ||
}), | ||
}, | ||
'../../../../../app/ui-utils/client': { | ||
MessageTypes: { | ||
getType: () => ({ | ||
message: 'System Message', | ||
}), | ||
}, | ||
}, | ||
}).default; | ||
|
||
render(<ThreadMessagePreview message={baseMessage} sequential={false} />); | ||
|
||
expect(screen.getByText('System Message')).to.exist; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.