-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added new and cloned panel at the bottom of the page (#6993)
* feat: added new and cloned panel at the bottom of the page * feat: added common util and took possible space available in last row in account * feat: added changes for empty layout * feat: added different test cases * feat: remove console.log * feat: added default value to widgetWidth
- Loading branch information
1 parent
9a75e27
commit 02c2b55
Showing
5 changed files
with
171 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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
92 changes: 92 additions & 0 deletions
92
frontend/src/container/NewWidget/__test__/NewWidget.test.tsx
This file contains 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,92 @@ | ||
// This test suite covers several important scenarios: | ||
// - Empty layout - widget should be placed at origin (0,0) | ||
// - Empty layout with custom dimensions | ||
// - Placing widget next to an existing widget when there's space in the last row | ||
// - Placing widget at bottom when the last row is full | ||
// - Handling multiple rows correctly | ||
// - Handling widgets with different heights | ||
|
||
import { placeWidgetAtBottom } from '../utils'; | ||
|
||
describe('placeWidgetAtBottom', () => { | ||
it('should place widget at (0,0) when layout is empty', () => { | ||
const result = placeWidgetAtBottom('widget1', []); | ||
expect(result).toEqual({ | ||
i: 'widget1', | ||
x: 0, | ||
y: 0, | ||
w: 6, | ||
h: 6, | ||
}); | ||
}); | ||
|
||
it('should place widget at (0,0) with custom dimensions when layout is empty', () => { | ||
const result = placeWidgetAtBottom('widget1', [], 4, 8); | ||
expect(result).toEqual({ | ||
i: 'widget1', | ||
x: 0, | ||
y: 0, | ||
w: 4, | ||
h: 8, | ||
}); | ||
}); | ||
|
||
it('should place widget next to existing widget in last row if space available', () => { | ||
const existingLayout = [{ i: 'widget1', x: 0, y: 0, w: 6, h: 6 }]; | ||
const result = placeWidgetAtBottom('widget2', existingLayout); | ||
expect(result).toEqual({ | ||
i: 'widget2', | ||
x: 6, | ||
y: 0, | ||
w: 6, | ||
h: 6, | ||
}); | ||
}); | ||
|
||
it('should place widget at bottom when last row is full', () => { | ||
const existingLayout = [ | ||
{ i: 'widget1', x: 0, y: 0, w: 6, h: 6 }, | ||
{ i: 'widget2', x: 6, y: 0, w: 6, h: 6 }, | ||
]; | ||
const result = placeWidgetAtBottom('widget3', existingLayout); | ||
expect(result).toEqual({ | ||
i: 'widget3', | ||
x: 0, | ||
y: 6, | ||
w: 6, | ||
h: 6, | ||
}); | ||
}); | ||
|
||
it('should handle multiple rows correctly', () => { | ||
const existingLayout = [ | ||
{ i: 'widget1', x: 0, y: 0, w: 6, h: 6 }, | ||
{ i: 'widget2', x: 6, y: 0, w: 6, h: 6 }, | ||
{ i: 'widget3', x: 0, y: 6, w: 6, h: 6 }, | ||
]; | ||
const result = placeWidgetAtBottom('widget4', existingLayout); | ||
expect(result).toEqual({ | ||
i: 'widget4', | ||
x: 6, | ||
y: 6, | ||
w: 6, | ||
h: 6, | ||
}); | ||
}); | ||
|
||
it('should handle widgets with different heights', () => { | ||
const existingLayout = [ | ||
{ i: 'widget1', x: 0, y: 0, w: 6, h: 8 }, | ||
{ i: 'widget2', x: 6, y: 0, w: 6, h: 4 }, | ||
]; | ||
const result = placeWidgetAtBottom('widget3', existingLayout); | ||
// y = 2 here as later the react-grid-layout will add 2px to the y value while adjusting the layout | ||
expect(result).toEqual({ | ||
i: 'widget3', | ||
x: 6, | ||
y: 2, | ||
w: 6, | ||
h: 6, | ||
}); | ||
}); | ||
}); |
This file contains 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 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 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