Skip to content
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

fix tests and newly found bug #2859

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion angular/projects/demo/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
</div>
} @else if (show===8) {
<div>
<p>delay loading of components</p>
<p>open console and scroll to see delay loading of components</p>
<div style="height: 120px; overflow-y: auto">
<gridstack [options]="gridOptionsDelay"></gridstack>
</div>
Expand Down
5 changes: 5 additions & 0 deletions doc/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Change log
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)*

- [11.0.1-dev (TBD)](#1101-dev-tbd)
- [11.0.1 (2024-10-21)](#1101-2024-10-21)
- [11.0.0 (2024-10-20)](#1100-2024-10-20)
- [10.3.1 (2024-07-21)](#1031-2024-07-21)
Expand Down Expand Up @@ -115,6 +116,10 @@ Change log

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## 11.0.1-dev (TBD)
* fix: [#2859](https://github.com/gridstack/gridstack.js/pull/2859) re-enabled tests and fix numerous issues found (see CL). Also thank you [lmartorella](https://github.com/lmartorella) for getting me going and starting it.
* fix: [#2851](https://github.com/gridstack/gridstack.js/pull/2851) added support for custom max layout saving - Thank you [lmartorella](https://github.com/lmartorella)

## 11.0.1 (2024-10-21)
* fix: [#2834](https://github.com/gridstack/gridstack.js/pull/2834) v11 angular missing package.json
* fix: [#2835](https://github.com/gridstack/gridstack.js/bug/2835) make sure we have unique USER id
Expand Down
5 changes: 3 additions & 2 deletions react/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ export const BREAKPOINTS = [
{ c: 6, w: 950 },
{ c: 8, w: 1100 },
];
const cellHeight = 50;

export const SUB_GRID_OPTIONS: GridStackOptions = {
acceptWidgets: true,
column: 12,
columnOpts: {
breakpoints: BREAKPOINTS,
layout: 'moveScale',
},
margin: 8,
minRow: 2,
cellHeight,
} as const;

export const GRID_OPTIONS: GridStackOptions = {
Expand All @@ -25,7 +26,7 @@ export const GRID_OPTIONS: GridStackOptions = {
breakpoints: BREAKPOINTS,
layout: 'moveScale',
},
float: false,
margin: 8,
cellHeight,
subGridOpts: SUB_GRID_OPTIONS,
} as const;
71 changes: 35 additions & 36 deletions spec/gridstack-engine-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ describe('gridstack engine:', function() {
'use strict';
let e: GridStackEngine;
let ePriv: any; // cast engine for private vars access

let findNode = function(e: GridStackEngine, id: string) {
let findNode = function(id: string) {
return e.nodes.find(n => n.id === id);
};

Expand Down Expand Up @@ -247,16 +246,16 @@ describe('gridstack engine:', function() {
e.prepareNode({x: 0, y: 0, w:1, h:1, id: '1'}),
];
ePriv._packNodes();
expect(findNode(e, '1')).toEqual(jasmine.objectContaining({x: 0, y: 0, h: 1}));
expect(findNode(e, '1')!._dirty).toBeFalsy();
expect(findNode('1')).toEqual(jasmine.objectContaining({x: 0, y: 0, h: 1}));
expect(findNode('1')!._dirty).toBeFalsy();
});

it('should pack one node correctly', function() {
e.nodes = [
e.prepareNode({x: 0, y: 1, w:1, h:1, id: '1'}),
];
ePriv._packNodes();
expect(findNode(e, '1')).toEqual(jasmine.objectContaining({x: 0, y: 0, _dirty: true}));
expect(findNode('1')).toEqual(jasmine.objectContaining({x: 0, y: 0, _dirty: true}));
});

it('should pack nodes correctly', function() {
Expand All @@ -265,8 +264,8 @@ describe('gridstack engine:', function() {
e.prepareNode({x: 0, y: 5, w:1, h:1, id: '2'}),
];
ePriv._packNodes();
expect(findNode(e, '1')).toEqual(jasmine.objectContaining({x: 0, y: 0, _dirty: true}));
expect(findNode(e, '2')).toEqual(jasmine.objectContaining({x: 0, y: 1, _dirty: true}));
expect(findNode('1')).toEqual(jasmine.objectContaining({x: 0, y: 0, _dirty: true}));
expect(findNode('2')).toEqual(jasmine.objectContaining({x: 0, y: 1, _dirty: true}));
});

it('should pack reverse nodes correctly', function() {
Expand All @@ -275,8 +274,8 @@ describe('gridstack engine:', function() {
e.prepareNode({x: 0, y: 1, w:1, h:1, id: '2'}),
];
ePriv._packNodes();
expect(findNode(e, '2')).toEqual(jasmine.objectContaining({x: 0, y: 0, _dirty: true}));
expect(findNode(e, '1')).toEqual(jasmine.objectContaining({x: 0, y: 1, _dirty: true}));
expect(findNode('2')).toEqual(jasmine.objectContaining({x: 0, y: 0, _dirty: true}));
expect(findNode('1')).toEqual(jasmine.objectContaining({x: 0, y: 1, _dirty: true}));
});

it('should respect locked nodes', function() {
Expand All @@ -285,9 +284,9 @@ describe('gridstack engine:', function() {
e.prepareNode({x: 0, y: 5, w:1, h:1, id: '2'}),
];
ePriv._packNodes();
expect(findNode(e, '1')).toEqual(jasmine.objectContaining({x: 0, y: 1, h: 1}));
expect(findNode(e, '1')!._dirty).toBeFalsy();
expect(findNode(e, '2')).toEqual(jasmine.objectContaining({x: 0, y: 2, _dirty: true}));
expect(findNode('1')).toEqual(jasmine.objectContaining({x: 0, y: 1, h: 1}));
expect(findNode('1')!._dirty).toBeFalsy();
expect(findNode('2')).toEqual(jasmine.objectContaining({x: 0, y: 2, _dirty: true}));
});
});
});
Expand Down Expand Up @@ -329,17 +328,17 @@ describe('gridstack engine:', function() {
];
// add locked item
e.addNode(nodes[0])
expect(findNode(e, '0')).toEqual(jasmine.objectContaining({x: 0, y: 1, w: 12, h: 1, locked: true}));
expect(findNode('0')).toEqual(jasmine.objectContaining({x: 0, y: 1, w: 12, h: 1, locked: true}));
// add item that moves past locked one
e.addNode(nodes[1])
expect(findNode(e, '0')).toEqual(jasmine.objectContaining({x: 0, y: 1, w: 12, h: 1, locked: true}));
expect(findNode(e, '1')).toEqual(jasmine.objectContaining({x: 1, y: 2, h: 3}));
expect(findNode('0')).toEqual(jasmine.objectContaining({x: 0, y: 1, w: 12, h: 1, locked: true}));
expect(findNode('1')).toEqual(jasmine.objectContaining({x: 1, y: 2, h: 3}));
// locked item can still be moved directly (what user does)
let node0 = findNode(e, '0');
let node0 = findNode('0');
expect(e.moveNode(node0!, {y:6})).toEqual(true);
expect(findNode(e, '0')).toEqual(jasmine.objectContaining({x: 0, y: 6, h: 1, locked: true}));
expect(findNode('0')).toEqual(jasmine.objectContaining({x: 0, y: 6, h: 1, locked: true}));
// but moves regular one past it
let node1 = findNode(e, '1');
let node1 = findNode('1');
expect(e.moveNode(node1!, {x:6, y:6})).toEqual(true);
expect(node1).toEqual(jasmine.objectContaining({x: 6, y: 7, w: 2, h: 3}));
// but moves regular one before (gravity ON)
Expand All @@ -361,42 +360,42 @@ describe('gridstack engine:', function() {
// Add two side-by-side components 6+6 = 12 columns
e.addNode({ x: 0, y: 0, w: 6, h: 1, id: 'left' });
e.addNode({ x: 6, y: 0, w: 6, h: 1, id: 'right' });
e.save().forEach(node => e.nodeBoundFix(findNode(e, node.id!)!));
expect(findNode(e, 'left')).toEqual(jasmine.objectContaining({x: 0, y: 0, w: 6, h: 1}));
expect(findNode(e, 'right')).toEqual(jasmine.objectContaining({x: 6, y: 0, w: 6, h: 1}));
e.save().forEach(node => e.nodeBoundFix(findNode(node.id!)!));
expect(findNode('left')).toEqual(jasmine.objectContaining({x: 0, y: 0, w: 6, h: 1}));
expect(findNode('right')).toEqual(jasmine.objectContaining({x: 6, y: 0, w: 6, h: 1}));
// Resize to 1 column
e.column = 1;
e.columnChanged(12, 1);
e.save().forEach(node => e.nodeBoundFix(findNode(e, node.id!)!));
expect(findNode(e, 'left')).toEqual(jasmine.objectContaining({x: 0, y: 0, w: 1, h: 1}));
expect(findNode(e, 'right')).toEqual(jasmine.objectContaining({x: 0, y: 1, w: 1, h: 1}));
e.save().forEach(node => e.nodeBoundFix(findNode(node.id!)!));
expect(findNode('left')).toEqual(jasmine.objectContaining({x: 0, y: 0, w: 1, h: 1}));
expect(findNode('right')).toEqual(jasmine.objectContaining({x: 0, y: 1, w: 1, h: 1}));
// Resize back to 12 column
e.column = 12;
e.columnChanged(1, 12);
e.save().forEach(node => e.nodeBoundFix(findNode(e, node.id!)!));
expect(findNode(e, 'left')).toEqual(jasmine.objectContaining({x: 0, y: 0, w: 6, h: 1}));
expect(findNode(e, 'right')).toEqual(jasmine.objectContaining({x: 6, y: 0, w: 6, h: 1}));
e.save().forEach(node => e.nodeBoundFix(findNode(node.id!)!));
expect(findNode('left')).toEqual(jasmine.objectContaining({x: 0, y: 0, w: 6, h: 1}));
expect(findNode('right')).toEqual(jasmine.objectContaining({x: 6, y: 0, w: 6, h: 1}));
});
it('wont\'t break layouts with more than 12 columns', function() {
ePriv = e = new GridStackEngine({ column: 24 });
// Add two side-by-side components 12+12 = 24 columns
e.addNode({ x: 0, y: 0, w: 12, h: 1, id: 'left' });
e.addNode({ x: 12, y: 0, w: 12, h: 1, id: 'right' });
e.save().forEach(node => e.nodeBoundFix(findNode(e, node.id!)!));
expect(findNode(e, 'left')).toEqual(jasmine.objectContaining({x: 0, y: 0, w: 12, h: 1}));
expect(findNode(e, 'right')).toEqual(jasmine.objectContaining({x: 12, y: 0, w: 12, h: 1}));
e.save().forEach(node => e.nodeBoundFix(findNode(node.id!)!));
expect(findNode('left')).toEqual(jasmine.objectContaining({x: 0, y: 0, w: 12, h: 1}));
expect(findNode('right')).toEqual(jasmine.objectContaining({x: 12, y: 0, w: 12, h: 1}));
// Resize to 1 column
e.column = 1;
e.columnChanged(24, 1);
e.save().forEach(node => e.nodeBoundFix(findNode(e, node.id!)!));
expect(findNode(e, 'left')).toEqual(jasmine.objectContaining({x: 0, y: 0, w: 1, h: 1}));
expect(findNode(e, 'right')).toEqual(jasmine.objectContaining({x: 0, y: 1, w: 1, h: 1}));
e.save().forEach(node => e.nodeBoundFix(findNode(node.id!)!));
expect(findNode('left')).toEqual(jasmine.objectContaining({x: 0, y: 0, w: 1, h: 1}));
expect(findNode('right')).toEqual(jasmine.objectContaining({x: 0, y: 1, w: 1, h: 1}));
// Resize back to 24 column
e.column = 24;
e.columnChanged(1, 24);
e.save().forEach(node => e.nodeBoundFix(findNode(e, node.id!)!));
expect(findNode(e, 'left')).toEqual(jasmine.objectContaining({x: 0, y: 0, w: 12, h: 1}));
expect(findNode(e, 'right')).toEqual(jasmine.objectContaining({x: 12, y: 0, w: 12, h: 1}));
e.save().forEach(node => e.nodeBoundFix(findNode(node.id!)!));
expect(findNode('left')).toEqual(jasmine.objectContaining({x: 0, y: 0, w: 12, h: 1}));
expect(findNode('right')).toEqual(jasmine.objectContaining({x: 12, y: 0, w: 12, h: 1}));
});
});

Expand Down
Loading