-
Notifications
You must be signed in to change notification settings - Fork 0
feat(react): add shared markdown renderer for observer messages #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0c23b39
feat(react): add shared markdown message renderer
willwashburn ed2348c
test(e2e): include markdown channel messages
willwashburn 9ad8e2b
fix(react): address markdown review feedback
willwashburn 0f23d09
feat(react): add code highlighting and copy button
willwashburn 656381f
test(e2e): add typescript fenced code-block message
willwashburn fc11640
fix(observer): move member badge to channel header
willwashburn 807d131
fix(observer): show full participant list for DMs
willwashburn b9a1668
fix(observer): sort DM participant labels alphabetically
willwashburn 0337e90
feat(observer): track and display unread channel badges
willwashburn e70cbe7
fix(pr): address valid review feedback
willwashburn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,74 @@ | ||
| import { fireEvent, render, waitFor } from '@testing-library/react'; | ||
| import { describe, it, expect, vi } from 'vitest'; | ||
| import { MessageMarkdown } from '../components/MessageMarkdown.js'; | ||
|
|
||
| describe('MessageMarkdown', () => { | ||
| it('renders markdown with soft line breaks and list items', () => { | ||
| const { container } = render( | ||
| <MessageMarkdown text={'**bold** line\nsecond line\n\n- one\n- two'} />, | ||
| ); | ||
|
|
||
| const strong = container.querySelector('strong'); | ||
| expect(strong?.textContent).toBe('bold'); | ||
| expect(container.querySelectorAll('br')).toHaveLength(1); | ||
| expect(Array.from(container.querySelectorAll('li')).map((node) => node.textContent)).toEqual([ | ||
| 'one', | ||
| 'two', | ||
| ]); | ||
| }); | ||
|
|
||
| it('applies secure attributes to external links', () => { | ||
| const { container } = render( | ||
| <MessageMarkdown text={'[docs](https://example.com) and [local](/general)'} />, | ||
| ); | ||
|
|
||
| const links = Array.from(container.querySelectorAll('a')); | ||
| expect(links[0]?.getAttribute('href')).toBe('https://example.com'); | ||
| expect(links[0]?.getAttribute('target')).toBe('_blank'); | ||
| expect(links[0]?.getAttribute('rel')).toBe('noopener noreferrer nofollow'); | ||
| expect(links[1]?.getAttribute('href')).toBe('/general'); | ||
| expect(links[1]?.getAttribute('target')).toBeNull(); | ||
|
willwashburn marked this conversation as resolved.
|
||
| expect(links[1]?.getAttribute('rel')).toBeNull(); | ||
| }); | ||
|
|
||
| it('renders highlighted fenced code and supports copy button', async () => { | ||
| const writeText = vi.fn().mockResolvedValue(undefined); | ||
| Object.defineProperty(navigator, 'clipboard', { | ||
| value: { writeText }, | ||
| configurable: true, | ||
| }); | ||
|
|
||
| const { container, getByRole } = render( | ||
| <MessageMarkdown | ||
| text={'```ts\nconst answer: number = 42;\n```'} | ||
| showCodeCopyButton | ||
| />, | ||
| ); | ||
|
|
||
| const code = container.querySelector('pre code'); | ||
| expect(code).not.toBeNull(); | ||
| expect(code?.querySelectorAll('span').length ?? 0).toBeGreaterThan(2); | ||
|
|
||
| const copyButton = getByRole('button', { name: 'Copy code' }); | ||
| fireEvent.click(copyButton); | ||
|
|
||
| await waitFor(() => { | ||
| expect(writeText).toHaveBeenCalledWith('const answer: number = 42;'); | ||
| expect(copyButton.textContent).toBe('Copied'); | ||
| }); | ||
| }); | ||
|
|
||
| it('preserves GFM table column alignment styles', () => { | ||
| const { container } = render( | ||
| <MessageMarkdown text={'| left | right |\n| :--- | ---: |\n| a | b |'} />, | ||
| ); | ||
|
|
||
| const headerCells = container.querySelectorAll('th'); | ||
| expect(headerCells[0]?.getAttribute('style')).toContain('text-align: left'); | ||
| expect(headerCells[1]?.getAttribute('style')).toContain('text-align: right'); | ||
|
|
||
| const rowCells = container.querySelectorAll('td'); | ||
| expect(rowCells[0]?.getAttribute('style')).toContain('text-align: left'); | ||
| expect(rowCells[1]?.getAttribute('style')).toContain('text-align: right'); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.