mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-08-08 09:43:03 +02:00
Fix terminals on hash room parsing
This commit is contained in:
@@ -169,6 +169,32 @@ describe('MessageList channel sender rendering', () => {
|
|||||||
expect(onChannelReferenceClick).toHaveBeenCalledWith('#mesh-room');
|
expect(onChannelReferenceClick).toHaveBeenCalledWith('#mesh-room');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('links valid channel references when followed by clause punctuation', async () => {
|
||||||
|
const user = userEvent.setup();
|
||||||
|
const onChannelReferenceClick = vi.fn();
|
||||||
|
|
||||||
|
render(
|
||||||
|
<MessageList
|
||||||
|
messages={[
|
||||||
|
createMessage({
|
||||||
|
text: 'Alice: Check #mesh-room, then #ops-room; then #alpha-room.',
|
||||||
|
}),
|
||||||
|
]}
|
||||||
|
contacts={[]}
|
||||||
|
loading={false}
|
||||||
|
onChannelReferenceClick={onChannelReferenceClick}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
await user.click(screen.getByRole('button', { name: '#mesh-room' }));
|
||||||
|
await user.click(screen.getByRole('button', { name: '#ops-room' }));
|
||||||
|
await user.click(screen.getByRole('button', { name: '#alpha-room' }));
|
||||||
|
|
||||||
|
expect(onChannelReferenceClick).toHaveBeenNthCalledWith(1, '#mesh-room');
|
||||||
|
expect(onChannelReferenceClick).toHaveBeenNthCalledWith(2, '#ops-room');
|
||||||
|
expect(onChannelReferenceClick).toHaveBeenNthCalledWith(3, '#alpha-room');
|
||||||
|
});
|
||||||
|
|
||||||
it('links valid channel references in direct messages too', async () => {
|
it('links valid channel references in direct messages too', async () => {
|
||||||
const user = userEvent.setup();
|
const user = userEvent.setup();
|
||||||
const onChannelReferenceClick = vi.fn();
|
const onChannelReferenceClick = vi.fn();
|
||||||
|
|||||||
@@ -122,11 +122,21 @@ describe('linked channel references', () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('ignores invalid or embedded channel-like text', () => {
|
it('finds linked channel references terminated by clause punctuation', () => {
|
||||||
expect(
|
expect(
|
||||||
findLinkedChannelReferences(
|
findLinkedChannelReferences('Join #mesh-room, then #ops2; finally #alpha-room.')
|
||||||
'skip #Bad #bad--name abc#ops #ops- #opsRoom #ops_room #good-room,'
|
).toEqual([
|
||||||
)
|
{ label: '#mesh-room', start: 5, end: 15 },
|
||||||
).toEqual([]);
|
{ label: '#ops2', start: 22, end: 27 },
|
||||||
|
{ label: '#alpha-room', start: 37, end: 48 },
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ignores invalid or embedded channel-like text', () => {
|
||||||
|
const references = findLinkedChannelReferences(
|
||||||
|
'skip #Bad #bad--name abc#ops #ops- #opsRoom #ops_room #good-room,'
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(references.map((reference) => reference.label)).toEqual(['#good-room']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* Channel messages have format "sender: message".
|
* Channel messages have format "sender: message".
|
||||||
*/
|
*/
|
||||||
const HASHTAG_CHANNEL_NAME_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
const HASHTAG_CHANNEL_NAME_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
||||||
const HASHTAG_CHANNEL_REFERENCE_PATTERN = /(^|\s)(#[a-z0-9]+(?:-[a-z0-9]+)*)(?=$|\s)/g;
|
const HASHTAG_CHANNEL_REFERENCE_PATTERN = /(^|\s)(#[a-z0-9]+(?:-[a-z0-9]+)*)(?=$|[\s.,;:])/g;
|
||||||
|
|
||||||
export function parseSenderFromText(text: string): { sender: string | null; content: string } {
|
export function parseSenderFromText(text: string): { sender: string | null; content: string } {
|
||||||
const colonIndex = text.indexOf(': ');
|
const colonIndex = text.indexOf(': ');
|
||||||
|
|||||||
Reference in New Issue
Block a user