-
-
Notifications
You must be signed in to change notification settings - Fork 948
feat(x-markdown): 添加footer支持 #1348
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ba6a36b
feat(x-markdown): 添加footer支持
Samoy bb05983
feat(demo): 添加国际化支持
Samoy da6f2c7
style(x-markdown): 优化页脚样式和类名结构
Samoy f9debdd
refactor(x-markdown): 简化样式类名
Samoy aba9ffd
Merge branch 'next' into feat-markdown-footer
Samoy c536f3c
Merge branch 'next' into feat-markdown-footer
Samoy 76a925f
test(bubble): update test snapshot.
Samoy d9db4ce
style(x-markdown): 优化footer部分样式
Samoy 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
There are no files selected for viewing
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
141 changes: 141 additions & 0 deletions
141
packages/x-markdown/src/XMarkdown/__test__/footer.test.tsx
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,141 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import React from 'react'; | ||
| import XMarkdown from '../index'; | ||
|
|
||
| describe('XMarkdown Footer', () => { | ||
| it('should render footer when provided', () => { | ||
| const footerContent = <div data-testid="custom-footer">Loading...</div>; | ||
| render(<XMarkdown content="# Hello World" footer={footerContent} />); | ||
|
|
||
| expect(screen.getByTestId('custom-footer')).toBeInTheDocument(); | ||
| expect(screen.getByTestId('custom-footer')).toHaveTextContent('Loading...'); | ||
| }); | ||
|
|
||
| it('should render footer at the end of content', () => { | ||
| const footerContent = <div data-testid="footer">Footer Content</div>; | ||
| const { container } = render( | ||
| <XMarkdown content="# Hello World\n\nThis is content." footer={footerContent} />, | ||
| ); | ||
|
|
||
| const markdownContainer = container.firstChild; | ||
| expect(markdownContainer).toHaveClass('ant-x-markdown-container'); | ||
|
|
||
| const content = container.querySelector('.ant-x-markdown-content'); | ||
| const footer = container.querySelector('.ant-x-markdown-footer'); | ||
|
|
||
| expect(content).toBeInTheDocument(); | ||
| expect(footer).toBeInTheDocument(); | ||
| expect(footer).toContainElement(screen.getByTestId('footer')); | ||
| }); | ||
|
|
||
| it('should not render footer when not provided', () => { | ||
| const { container } = render(<XMarkdown content="# Hello World" />); | ||
|
|
||
| expect(container.querySelector('.ant-x-markdown-footer')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should render footer with empty content', () => { | ||
| const footerContent = <div data-testid="empty-footer">Empty Content Footer</div>; | ||
| render(<XMarkdown content="" footer={footerContent} />); | ||
|
|
||
| expect(screen.getByTestId('empty-footer')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should render footer with null content', () => { | ||
| const footerContent = <div data-testid="null-footer">Null Content Footer</div>; | ||
| render(<XMarkdown content={null as any} footer={footerContent} />); | ||
|
|
||
| expect(screen.getByTestId('null-footer')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should render footer with undefined content', () => { | ||
| const footerContent = <div data-testid="undefined-footer">Undefined Content Footer</div>; | ||
| render(<XMarkdown content={undefined} footer={footerContent} />); | ||
|
|
||
| expect(screen.getByTestId('undefined-footer')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should render footer with streaming content', () => { | ||
| const footerContent = <div data-testid="streaming-footer">Streaming...</div>; | ||
| const { rerender } = render( | ||
| <XMarkdown content="# Hello" footer={footerContent} streaming={{ hasNextChunk: true }} />, | ||
| ); | ||
|
|
||
| expect(screen.getByTestId('streaming-footer')).toBeInTheDocument(); | ||
| expect(screen.getByTestId('streaming-footer')).toHaveTextContent('Streaming...'); | ||
|
|
||
| // Update content to simulate streaming | ||
| rerender( | ||
| <XMarkdown | ||
| content="# Hello World\n\nUpdated content" | ||
| footer={footerContent} | ||
| streaming={{ hasNextChunk: true }} | ||
| />, | ||
| ); | ||
|
|
||
| // Footer should still be visible | ||
| expect(screen.getByTestId('streaming-footer')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should render footer with complex React components', () => { | ||
| const ComplexFooter = () => ( | ||
| <div> | ||
| <span>Loading</span> | ||
| <div className="spinner">⚡</div> | ||
| </div> | ||
| ); | ||
|
|
||
| render(<XMarkdown content="# Complex Content" footer={<ComplexFooter />} />); | ||
|
|
||
| expect(screen.getByText('Loading')).toBeInTheDocument(); | ||
| expect(screen.getByText('⚡')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should apply custom styles to footer container', () => { | ||
| const footerContent = <div style={{ color: 'red' }}>Styled Footer</div>; | ||
| const { container } = render(<XMarkdown content="# Test" footer={footerContent} />); | ||
|
|
||
| const footer = container.querySelector('.ant-x-markdown-footer'); | ||
| expect(footer).toBeInTheDocument(); | ||
| // Check CSS classes instead of computed styles | ||
| expect(footer).toHaveClass('ant-x-markdown-footer'); | ||
| }); | ||
|
|
||
| it('should work with custom prefixCls', () => { | ||
| const footerContent = <div data-testid="custom-prefix-footer">Custom Prefix</div>; | ||
| const { container } = render( | ||
| <XMarkdown content="# Test" footer={footerContent} prefixCls="custom-markdown" />, | ||
| ); | ||
|
|
||
| expect(container.querySelector('.custom-markdown-container')).toBeInTheDocument(); | ||
| expect(container.querySelector('.custom-markdown-content')).toBeInTheDocument(); | ||
| expect(container.querySelector('.custom-markdown-footer')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should not render anything when both content and footer are empty', () => { | ||
| const { container } = render(<XMarkdown content="" footer={null} />); | ||
| expect(container).toBeEmptyDOMElement(); | ||
| }); | ||
|
|
||
| it('should render footer with string content', () => { | ||
| render(<XMarkdown footer={<div>String Footer</div>}>{'# String Content'}</XMarkdown>); | ||
|
|
||
| expect(screen.getByText('String Footer')).toBeInTheDocument(); | ||
| expect(screen.getByText('String Content')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should memoize footer rendering for performance', () => { | ||
| const FooterComponent = jest.fn(() => <div>Memoized Footer</div>); | ||
| const footerElement = <FooterComponent />; | ||
|
|
||
| const { rerender } = render(<XMarkdown content="# Test" footer={footerElement} />); | ||
|
|
||
| expect(FooterComponent).toHaveBeenCalledTimes(1); | ||
|
|
||
| // Re-render with same footer element reference | ||
| rerender(<XMarkdown content="# Test Updated" footer={footerElement} />); | ||
|
|
||
| // Footer component should not re-render due to memoization | ||
| expect(FooterComponent).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); |
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
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.