-
Notifications
You must be signed in to change notification settings - Fork 6
Add "Copy to clipboard" button for Output Data and Logs in test step panel #109
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
5 commits
Select commit
Hold shift + click to select a range
3ddf79f
Add "Copy to clipboard" button for Output Data and Logs in test step …
seslash 2eb0492
Potential fix for pull request finding
seslash d81816a
Potential fix for pull request finding
seslash 828c8ae
Apply suggestions from code review
seslash ec27edf
Resolve comments
atti92 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
117 changes: 117 additions & 0 deletions
117
web-editor/src/components/ScenarioEditor/__tests__/BottomPanel.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,117 @@ | ||
| import { render, screen, fireEvent, act } from '@testing-library/react'; | ||
| import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; | ||
| import { BottomPanel } from '../BottomPanel'; | ||
| import type { Node } from '@xyflow/react'; | ||
| import type { NodeData } from '../../../types/scenario'; | ||
|
|
||
| vi.mock('../../../hooks/useBottomPanelResize', () => ({ | ||
| useBottomPanelResize: () => ({ | ||
| panelHeight: 300, | ||
| isResizing: false, | ||
| startResizing: vi.fn(), | ||
| }), | ||
| })); | ||
|
|
||
| const makeNode = (overrides: Partial<NodeData> = {}): Node<NodeData> => ({ | ||
| id: '1', | ||
| position: { x: 0, y: 0 }, | ||
| data: { | ||
| label: 'Test Step', | ||
| status: 'success', | ||
| parameters: [], | ||
| ...overrides, | ||
| }, | ||
| }); | ||
|
|
||
| describe('BottomPanel', () => { | ||
| let writeTextMock: ReturnType<typeof vi.fn>; | ||
|
|
||
| beforeEach(() => { | ||
| vi.useFakeTimers(); | ||
| writeTextMock = vi.fn().mockResolvedValue(undefined); | ||
| Object.assign(navigator, { | ||
| clipboard: { writeText: writeTextMock }, | ||
| }); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.useRealTimers(); | ||
| vi.restoreAllMocks(); | ||
| }); | ||
|
|
||
| it('returns null when selectedNode is null', () => { | ||
| const { container } = render(<BottomPanel selectedNode={null} onClose={vi.fn()} />); | ||
| expect(container.innerHTML).toBe(''); | ||
| }); | ||
|
|
||
| it('shows copy button when output data exists', () => { | ||
| const node = makeNode({ result: { foo: 'bar' } }); | ||
| render(<BottomPanel selectedNode={node} onClose={vi.fn()} />); | ||
| expect(screen.getByLabelText('Copy to clipboard')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('hides copy button when no result on output tab', () => { | ||
| const node = makeNode({ result: undefined }); | ||
| render(<BottomPanel selectedNode={node} onClose={vi.fn()} />); | ||
| expect(screen.queryByLabelText('Copy to clipboard')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('shows copy button for falsy but defined result (e.g. 0)', () => { | ||
| const node = makeNode({ result: 0 }); | ||
| render(<BottomPanel selectedNode={node} onClose={vi.fn()} />); | ||
| expect(screen.getByLabelText('Copy to clipboard')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('copies output JSON to clipboard', async () => { | ||
| const node = makeNode({ result: { key: 'value' } }); | ||
| render(<BottomPanel selectedNode={node} onClose={vi.fn()} />); | ||
|
|
||
| await act(async () => { | ||
| fireEvent.click(screen.getByLabelText('Copy to clipboard')); | ||
| }); | ||
|
|
||
| expect(writeTextMock).toHaveBeenCalledWith(JSON.stringify({ key: 'value' }, null, 2)); | ||
| }); | ||
|
|
||
| it('copies filtered logs to clipboard on logs tab', async () => { | ||
| const node = makeNode({ | ||
| result: { | ||
| logs: [ | ||
| '12:00 | INFO | info message', | ||
| '12:01 | ERROR | error message', | ||
| ], | ||
| }, | ||
| }); | ||
| render(<BottomPanel selectedNode={node} onClose={vi.fn()} />); | ||
|
|
||
| fireEvent.click(screen.getByText('Logs (2)')); | ||
|
|
||
| // Filter to ERROR only | ||
| const select = screen.getByDisplayValue('All Levels'); | ||
| fireEvent.change(select, { target: { value: 'ERROR' } }); | ||
|
|
||
| await act(async () => { | ||
| fireEvent.click(screen.getByLabelText('Copy to clipboard')); | ||
| }); | ||
|
|
||
| expect(writeTextMock).toHaveBeenCalledWith('12:01 | ERROR | error message'); | ||
| }); | ||
|
|
||
| it('shows "Copied!" feedback and resets after 2 seconds', async () => { | ||
| const node = makeNode({ result: { data: 1 } }); | ||
| render(<BottomPanel selectedNode={node} onClose={vi.fn()} />); | ||
|
|
||
| await act(async () => { | ||
| fireEvent.click(screen.getByLabelText('Copy to clipboard')); | ||
| }); | ||
|
|
||
| expect(screen.getByText('Copied!')).toBeInTheDocument(); | ||
|
|
||
| act(() => { | ||
| vi.advanceTimersByTime(2000); | ||
| }); | ||
|
|
||
| expect(screen.queryByText('Copied!')).not.toBeInTheDocument(); | ||
| expect(screen.getByText('Copy')).toBeInTheDocument(); | ||
| }); | ||
| }); |
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.