-
Notifications
You must be signed in to change notification settings - Fork 8.2k
feat: Improvements to Sticky Notes #11057
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
Open
deon-sanchez
wants to merge
7
commits into
main
Choose a base branch
from
lfoss-3085
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a5d0c62
added min size for sticky note
deon-sanchez c97202d
tests created
deon-sanchez 7dea444
Merge branch 'main' of https://github.com/langflow-ai/langflow into l…
deon-sanchez 2ee064d
Merge branch 'main' into lfoss-3085
deon-sanchez f1a878d
Merge branch 'main' into lfoss-3085
deon-sanchez b6957a4
Merge branch 'main' into lfoss-3085
deon-sanchez 1ecf21d
Merge branch 'main' into lfoss-3085
deon-sanchez 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
221 changes: 221 additions & 0 deletions
221
src/frontend/src/CustomNodes/NoteNode/__tests__/note-node-shrink.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,221 @@ | ||
| /** | ||
| * Unit tests for NoteNode shrink/resize behavior | ||
| * Validates that sticky notes can shrink to the correct minimum size | ||
| */ | ||
|
|
||
| import { render, screen } from "@testing-library/react"; | ||
| import { | ||
| DEFAULT_NOTE_SIZE, | ||
| NOTE_NODE_MIN_HEIGHT, | ||
| NOTE_NODE_MIN_WIDTH, | ||
| } from "@/constants/constants"; | ||
| import type { NoteDataType } from "@/types/flow"; | ||
|
|
||
| // Mock dependencies | ||
| const mockSetNode = jest.fn(); | ||
| const mockCurrentFlow = { | ||
| data: { | ||
| nodes: [] as Array<{ id: string; width?: number; height?: number }>, | ||
| }, | ||
| }; | ||
|
|
||
| jest.mock("@/stores/flowStore", () => ({ | ||
| __esModule: true, | ||
| default: (selector: (state: any) => any) => | ||
| selector({ | ||
| currentFlow: mockCurrentFlow, | ||
| setNode: mockSetNode, | ||
| }), | ||
| })); | ||
|
|
||
| jest.mock("@xyflow/react", () => ({ | ||
| NodeResizer: ({ | ||
| minWidth, | ||
| minHeight, | ||
| onResize, | ||
| isVisible, | ||
| }: { | ||
| minWidth: number; | ||
| minHeight: number; | ||
| onResize: (event: any, params: { width: number; height: number }) => void; | ||
| isVisible?: boolean; | ||
| }) => ( | ||
| <div | ||
| data-testid="node-resizer" | ||
| data-min-width={minWidth} | ||
| data-min-height={minHeight} | ||
| data-is-visible={isVisible} | ||
| /> | ||
| ), | ||
| })); | ||
|
|
||
| jest.mock("@/shared/hooks/use-alternate", () => ({ | ||
| useAlternate: (initial: boolean) => [initial, jest.fn()], | ||
| })); | ||
|
|
||
| jest.mock("../NoteToolbarComponent", () => ({ | ||
| __esModule: true, | ||
| default: () => <div data-testid="note-toolbar" />, | ||
| })); | ||
|
|
||
| jest.mock("../../GenericNode/components/NodeDescription", () => ({ | ||
| __esModule: true, | ||
| default: () => <div data-testid="node-description" />, | ||
| })); | ||
|
|
||
| jest.mock("@/utils/utils", () => ({ | ||
| cn: (...classes: any[]) => classes.filter(Boolean).join(" "), | ||
| })); | ||
|
|
||
| // Import component after mocks are set up | ||
| import NoteNode from "../index"; | ||
|
|
||
| describe("NoteNode Shrink Behavior", () => { | ||
| const createMockData = ( | ||
| id: string = "test-note", | ||
| backgroundColor: string = "amber", | ||
| ): NoteDataType => | ||
| ({ | ||
| id, | ||
| type: "noteNode", | ||
| node: { | ||
| description: "Test note content", | ||
| template: { backgroundColor }, | ||
| }, | ||
| }) as NoteDataType; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| mockCurrentFlow.data.nodes = []; | ||
| }); | ||
|
|
||
| describe("Minimum Size Constraints", () => { | ||
| it("should configure NodeResizer with correct minimum width", () => { | ||
| const data = createMockData(); | ||
| render(<NoteNode data={data} selected={true} />); | ||
|
|
||
| const resizer = screen.getByTestId("node-resizer"); | ||
| expect(Number(resizer.dataset.minWidth)).toBe(NOTE_NODE_MIN_WIDTH); | ||
| expect(NOTE_NODE_MIN_WIDTH).toBe(260); | ||
| }); | ||
|
|
||
| it("should configure NodeResizer with correct minimum height", () => { | ||
| const data = createMockData(); | ||
| render(<NoteNode data={data} selected={true} />); | ||
|
|
||
| const resizer = screen.getByTestId("node-resizer"); | ||
| expect(Number(resizer.dataset.minHeight)).toBe(NOTE_NODE_MIN_HEIGHT); | ||
| expect(NOTE_NODE_MIN_HEIGHT).toBe(100); | ||
| }); | ||
|
|
||
| it("should show resizer only when selected", () => { | ||
| const data = createMockData(); | ||
|
|
||
| // When selected | ||
| const { rerender } = render(<NoteNode data={data} selected={true} />); | ||
| let resizer = screen.getByTestId("node-resizer"); | ||
| expect(resizer.dataset.isVisible).toBe("true"); | ||
|
|
||
| // When not selected | ||
| rerender(<NoteNode data={data} selected={false} />); | ||
| resizer = screen.getByTestId("node-resizer"); | ||
| expect(resizer.dataset.isVisible).toBe("false"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("Default Size Behavior", () => { | ||
| it("should use DEFAULT_NOTE_SIZE when no dimensions are stored", () => { | ||
| const data = createMockData("note-1"); | ||
| mockCurrentFlow.data.nodes = []; | ||
|
|
||
| render(<NoteNode data={data} selected={false} />); | ||
|
|
||
| const noteNode = screen.getByTestId("note_node"); | ||
| expect(noteNode.style.width).toBe(`${DEFAULT_NOTE_SIZE}px`); | ||
| expect(noteNode.style.height).toBe(`${DEFAULT_NOTE_SIZE}px`); | ||
| expect(DEFAULT_NOTE_SIZE).toBe(324); | ||
| }); | ||
|
|
||
| it("should use stored dimensions from flow state", () => { | ||
| const data = createMockData("note-1"); | ||
| const customWidth = 400; | ||
| const customHeight = 300; | ||
|
|
||
| mockCurrentFlow.data.nodes = [ | ||
| { id: "note-1", width: customWidth, height: customHeight }, | ||
| ]; | ||
|
|
||
| render(<NoteNode data={data} selected={false} />); | ||
|
|
||
| const noteNode = screen.getByTestId("note_node"); | ||
| expect(noteNode.style.width).toBe(`${customWidth}px`); | ||
| expect(noteNode.style.height).toBe(`${customHeight}px`); | ||
| }); | ||
| }); | ||
|
|
||
| describe("Shrink to Minimum Size", () => { | ||
| it("should allow shrinking to minimum dimensions", () => { | ||
| const data = createMockData("note-1"); | ||
|
|
||
| // Simulate a note that has been shrunk to minimum size | ||
| mockCurrentFlow.data.nodes = [ | ||
| { | ||
| id: "note-1", | ||
| width: NOTE_NODE_MIN_WIDTH, | ||
| height: NOTE_NODE_MIN_HEIGHT, | ||
| }, | ||
| ]; | ||
|
|
||
| render(<NoteNode data={data} selected={true} />); | ||
|
|
||
| const noteNode = screen.getByTestId("note_node"); | ||
| expect(noteNode.style.width).toBe(`${NOTE_NODE_MIN_WIDTH}px`); | ||
| expect(noteNode.style.height).toBe(`${NOTE_NODE_MIN_HEIGHT}px`); | ||
| }); | ||
|
|
||
| it("should render correctly at minimum width", () => { | ||
| const data = createMockData("note-1"); | ||
| mockCurrentFlow.data.nodes = [ | ||
| { id: "note-1", width: NOTE_NODE_MIN_WIDTH, height: DEFAULT_NOTE_SIZE }, | ||
| ]; | ||
|
|
||
| render(<NoteNode data={data} selected={false} />); | ||
|
|
||
| const noteNode = screen.getByTestId("note_node"); | ||
| expect(noteNode.style.width).toBe(`${NOTE_NODE_MIN_WIDTH}px`); | ||
| }); | ||
|
|
||
| it("should render correctly at minimum height", () => { | ||
| const data = createMockData("note-1"); | ||
| mockCurrentFlow.data.nodes = [ | ||
| { | ||
| id: "note-1", | ||
| width: DEFAULT_NOTE_SIZE, | ||
| height: NOTE_NODE_MIN_HEIGHT, | ||
| }, | ||
| ]; | ||
|
|
||
| render(<NoteNode data={data} selected={false} />); | ||
|
|
||
| const noteNode = screen.getByTestId("note_node"); | ||
| expect(noteNode.style.height).toBe(`${NOTE_NODE_MIN_HEIGHT}px`); | ||
| }); | ||
| }); | ||
|
|
||
| describe("Size Constraints Validation", () => { | ||
| it("should have minimum width less than default size", () => { | ||
| expect(NOTE_NODE_MIN_WIDTH).toBeLessThan(DEFAULT_NOTE_SIZE); | ||
| }); | ||
|
|
||
| it("should have minimum height less than default size", () => { | ||
| expect(NOTE_NODE_MIN_HEIGHT).toBeLessThan(DEFAULT_NOTE_SIZE); | ||
| }); | ||
|
|
||
| it("should have reasonable minimum dimensions for usability", () => { | ||
| // Minimum width should be at least 200px for readability | ||
| expect(NOTE_NODE_MIN_WIDTH).toBeGreaterThanOrEqual(200); | ||
| // Minimum height should be at least 80px for content | ||
| expect(NOTE_NODE_MIN_HEIGHT).toBeGreaterThanOrEqual(80); | ||
| }); | ||
| }); | ||
| }); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these min numbers come from product.