|
| 1 | +import { GridItemHTMLElement, GridStack, GridStackWidget } from '../src/gridstack'; |
| 2 | + |
| 3 | +describe('regression >', function() { |
| 4 | + 'use strict'; |
| 5 | + |
| 6 | + let grid: GridStack; |
| 7 | + let findEl = function(id: string): GridItemHTMLElement { |
| 8 | + return grid.engine.nodes.find(n => n.id === id)!.el!; |
| 9 | + }; |
| 10 | + |
| 11 | + // empty grid |
| 12 | + let gridstackEmptyHTML = |
| 13 | + '<div style="width: 800px; height: 600px" id="gs-cont">' + |
| 14 | + ' <div class="grid-stack"></div>' + |
| 15 | + '</div>'; |
| 16 | + |
| 17 | + describe('2492 load() twice >', function() { |
| 18 | + beforeEach(function() { |
| 19 | + document.body.insertAdjacentHTML('afterbegin', gridstackEmptyHTML); |
| 20 | + }); |
| 21 | + afterEach(function() { |
| 22 | + document.body.removeChild(document.getElementById('gs-cont')); |
| 23 | + }); |
| 24 | + it('', function() { |
| 25 | + let items: GridStackWidget[] = [ |
| 26 | + {x: 0, y: 0, w:2, content: '0 wide'}, |
| 27 | + {x: 1, y: 0, content: '1 over'}, |
| 28 | + {x: 2, y: 1, content: '2 float'}, |
| 29 | + ]; |
| 30 | + let count = 0; |
| 31 | + items.forEach(n => n.id = String(count++)); |
| 32 | + grid = GridStack.init({cellHeight: 70, margin: 5}).load(items); |
| 33 | + |
| 34 | + let el0 = findEl('0'); |
| 35 | + let el1 = findEl('1'); |
| 36 | + let el2 = findEl('2'); |
| 37 | + |
| 38 | + expect(parseInt(el0.getAttribute('gs-x'), 10)).toBe(0); |
| 39 | + expect(parseInt(el0.getAttribute('gs-y'), 10)).toBe(0); |
| 40 | + expect(el0.children[0].innerHTML).toBe(items[0].content!); |
| 41 | + expect(parseInt(el1.getAttribute('gs-x'), 10)).toBe(1); |
| 42 | + expect(parseInt(el1.getAttribute('gs-y'), 10)).toBe(1); |
| 43 | + expect(parseInt(el2.getAttribute('gs-x'), 10)).toBe(2); |
| 44 | + expect(parseInt(el2.getAttribute('gs-y'), 10)).toBe(0); |
| 45 | + |
| 46 | + // loading with changed content should be same positions |
| 47 | + items.forEach(n => n.content += '*') |
| 48 | + grid.load(items); |
| 49 | + expect(parseInt(el0.getAttribute('gs-x'), 10)).toBe(0); |
| 50 | + expect(parseInt(el0.getAttribute('gs-y'), 10)).toBe(0); |
| 51 | + expect(el0.children[0].innerHTML).toBe(items[0].content!); |
| 52 | + expect(parseInt(el1.getAttribute('gs-x'), 10)).toBe(1); |
| 53 | + expect(parseInt(el1.getAttribute('gs-y'), 10)).toBe(1); |
| 54 | + expect(parseInt(el2.getAttribute('gs-x'), 10)).toBe(2); |
| 55 | + expect(parseInt(el2.getAttribute('gs-y'), 10)).toBe(0); |
| 56 | + }); |
| 57 | + }); |
| 58 | +}); |
0 commit comments