Comparing version 1.3.2 to 1.3.3
@@ -79,3 +79,3 @@ export default class Sheet { | ||
this._eventBus.fire('row.add', { row }); | ||
return row; | ||
@@ -163,3 +163,3 @@ } | ||
const root = this.getRoot(); | ||
if (typeof col === 'string') { | ||
@@ -184,3 +184,3 @@ col = this._elementRegistry.get(col); | ||
cell.row = undefined; | ||
removeAtIndex(index, root.rows[idx].cells); | ||
@@ -201,3 +201,3 @@ }); | ||
* Insert value | ||
* | ||
* | ||
* @param {number} index - Index to insert value at. | ||
@@ -212,3 +212,3 @@ * @param {Array} array - Array to insert value into. | ||
/** | ||
* | ||
* | ||
* @param {number} index - Index to remove. | ||
@@ -215,0 +215,0 @@ * @param {Array} array - Array to remove from. |
@@ -32,3 +32,3 @@ | ||
/** | ||
* | ||
* | ||
* @param {Object} position - Position of context menu. Can either be point or box. | ||
@@ -89,3 +89,3 @@ * Context Menu will figure out best position. | ||
* event target was not context menu itself and removes itself afterwards. | ||
* | ||
* | ||
* @param {string} id - ID of context menu that will be closed by this listener. | ||
@@ -106,6 +106,6 @@ */ | ||
} | ||
if (!this.node.contains(target)) { | ||
this._eventBus.fire('contextMenu.close'); | ||
window.removeEventListener('click', listener); | ||
@@ -119,3 +119,3 @@ } | ||
} | ||
}; | ||
@@ -128,3 +128,3 @@ | ||
const { injector } = this.context; | ||
this._components = injector.get('components'); | ||
@@ -180,38 +180,52 @@ | ||
const contextMenuPosition = {}; | ||
const style = {}; | ||
if (position.x + (position.width / 2) > containerBounds.width / 2) { | ||
contextMenuPosition.left = | ||
(position.x | ||
let left = position.x | ||
- containerBounds.left | ||
- bounds.width | ||
+ scrollLeft) | ||
+ 'px'; | ||
+ scrollLeft; | ||
left = clampNumber(left, 0, containerBounds.width - bounds.width); | ||
style.left = left + 'px'; | ||
} else { | ||
contextMenuPosition.left = | ||
(window.scrollX | ||
let left = window.scrollX | ||
- containerBounds.left | ||
+ position.x | ||
+ position.width | ||
+ scrollLeft) | ||
+ 'px'; | ||
+ scrollLeft; | ||
left = clampNumber(left, 0, containerBounds.width - bounds.width); | ||
style.left = left + 'px'; | ||
} | ||
let top; | ||
if (position.y + (position.height / 2) > containerBounds.height / 2) { | ||
contextMenuPosition.top = | ||
(position.y | ||
top = position.y | ||
- containerBounds.top | ||
- bounds.height | ||
+ scrollTop) | ||
+ 'px'; | ||
+ scrollTop; | ||
top = clampNumber(top, 0, containerBounds.height - bounds.height); | ||
style.top = top + 'px'; | ||
} else { | ||
contextMenuPosition.top = | ||
(window.scrollY | ||
top = window.scrollY | ||
- containerBounds.top | ||
+ position.y | ||
+ scrollTop) | ||
+ 'px'; | ||
+ scrollTop; | ||
top = clampNumber(top, 0, containerBounds.height - bounds.height); | ||
style.top = top + 'px'; | ||
} | ||
assign(this.node.style, contextMenuPosition); | ||
// ensure context menu will always be accessible | ||
style.overflowY = 'auto'; | ||
style.maxHeight = (containerBounds.height - top) + 'px'; | ||
assign(this.node.style, style); | ||
} | ||
@@ -226,3 +240,3 @@ | ||
return null; | ||
} | ||
} | ||
@@ -235,5 +249,7 @@ return ( | ||
className="context-menu no-deselect"> | ||
{ | ||
contextMenuComponents && | ||
contextMenuComponents.map((Component, index) => <Component key={ index } context={ context } />) | ||
{ | ||
contextMenuComponents && | ||
contextMenuComponents.map( | ||
(Component, index) => <Component key={ index } context={ context } /> | ||
) | ||
} | ||
@@ -243,2 +259,8 @@ </div> | ||
} | ||
} | ||
////////// helpers ////////// | ||
function clampNumber(number, min, max) { | ||
return Math.max(min, Math.min(max, number)); | ||
} |
@@ -44,3 +44,3 @@ import { Row, Col } from '../../../model'; | ||
let index = root.cols.indexOf(element); | ||
if (index === -1) { | ||
@@ -58,3 +58,3 @@ return; | ||
context.oldElement = this._clipBoard.getElement(); | ||
this._clipBoard.clear(); | ||
@@ -61,0 +61,0 @@ |
@@ -17,3 +17,3 @@ import forEach from 'lodash/forEach'; | ||
constructor(commandStack, cutPaste, eventBus, modeling, selection) { | ||
this._actions = { | ||
@@ -120,4 +120,4 @@ undo() { | ||
} | ||
/** | ||
@@ -124,0 +124,0 @@ * Checks wether the given action is registered |
@@ -78,5 +78,9 @@ import { closest as domClosest } from 'min-dom'; | ||
function findClosestCell(element) { | ||
const closest = domClosest(element, 'th') || domClosest(element, 'td'), | ||
isCell = element.tagName.toLowerCase() === 'th' || element.tagName.toLowerCase() === 'td'; | ||
const closest = domClosest(element, 'th') || domClosest(element, 'td'); | ||
const isCell = ( | ||
element.tagName.toLowerCase() === 'th' || | ||
element.tagName.toLowerCase() === 'td' | ||
); | ||
if (isCell) { | ||
@@ -83,0 +87,0 @@ return element; |
@@ -6,3 +6,3 @@ | ||
export default class MoveColHandler { | ||
constructor(modeling) { | ||
@@ -9,0 +9,0 @@ this._modeling = modeling; |
@@ -1,2 +0,5 @@ | ||
import { classes as domClasses, closest as domClosest } from 'min-dom'; | ||
import { | ||
classes as domClasses, | ||
closest as domClosest | ||
} from 'min-dom'; | ||
@@ -99,5 +102,9 @@ /** | ||
function findClosestCell(element) { | ||
const closest = domClosest(element, 'th') || domClosest(element, 'td'), | ||
isCell = element.tagName.toLowerCase() === 'th' || element.tagName.toLowerCase() === 'td'; | ||
const closest = domClosest(element, 'th') || domClosest(element, 'td'); | ||
const isCell = ( | ||
element.tagName.toLowerCase() === 'th' || | ||
element.tagName.toLowerCase() === 'td' | ||
); | ||
if (isCell) { | ||
@@ -104,0 +111,0 @@ return element; |
export default class ChangeSupport { | ||
constructor(eventBus) { | ||
constructor(eventBus) { | ||
this._listeners = {}; | ||
@@ -11,3 +11,3 @@ | ||
const oldRootId = context.root.id; | ||
if (this._listeners[oldRootId]) { | ||
@@ -22,11 +22,11 @@ | ||
}); | ||
} | ||
}); | ||
} | ||
elementsChanged(elements) { | ||
const invoked = {}; | ||
const elementsLength = elements.length; | ||
@@ -36,9 +36,9 @@ | ||
const { id } = elements[i]; | ||
if (invoked[id]) { | ||
return; | ||
} | ||
invoked[id] = true; | ||
const listenersLength = this._listeners[id] && this._listeners[id].length; | ||
@@ -48,3 +48,3 @@ | ||
for (let j = 0; j < listenersLength; j++) { | ||
// listeners might remove themselves before they get called | ||
@@ -56,3 +56,3 @@ this._listeners[id][j] && this._listeners[id][j](); | ||
} | ||
onElementsChanged(id, listener) { | ||
@@ -62,7 +62,7 @@ if (!this._listeners[id]) { | ||
} | ||
// avoid push for better performance | ||
this._listeners[id][this._listeners[id].length] = listener; | ||
} | ||
offElementsChanged(id, listener) { | ||
@@ -75,3 +75,3 @@ if (!this._listeners[id]) { | ||
const idx = this._listeners[id].indexOf(listener); | ||
if (idx !== -1) { | ||
@@ -78,0 +78,0 @@ this._listeners[id].splice(idx, 1); |
@@ -8,10 +8,10 @@ import isFunction from 'lodash/isFunction'; | ||
export default class Components { | ||
constructor() { | ||
this._listeners = {}; | ||
} | ||
getComponent(type, context) { | ||
getComponent(type, context) { | ||
const listeners = this._listeners[type]; | ||
if (!listeners) { | ||
@@ -33,10 +33,10 @@ return; | ||
} | ||
getComponents(type, context) { | ||
const listeners = this._listeners[type]; | ||
if (!listeners) { | ||
return; | ||
} | ||
const components = []; | ||
@@ -51,3 +51,3 @@ | ||
} | ||
if (!components.length) { | ||
@@ -59,3 +59,3 @@ return; | ||
} | ||
onGetComponent(type, priority, callback) { | ||
@@ -66,3 +66,3 @@ if (isFunction(priority)) { | ||
} | ||
if (!isNumber(priority)) { | ||
@@ -73,3 +73,3 @@ throw new Error('priority must be a number'); | ||
const listeners = this._getListeners(type); | ||
let existingListener, | ||
@@ -94,3 +94,3 @@ idx; | ||
const listeners = this._getListeners(type); | ||
let listener, | ||
@@ -116,3 +116,3 @@ listenerCallback, | ||
} | ||
_getListeners(type) { | ||
@@ -119,0 +119,0 @@ let listeners = this._listeners[type]; |
@@ -56,3 +56,6 @@ | ||
<div className="tjs-container"> | ||
{ beforeTableComponents && beforeTableComponents.map((Component, index) => <Component key={ index } />) } | ||
{ | ||
beforeTableComponents && | ||
beforeTableComponents.map((Component, index) => <Component key={ index } />) | ||
} | ||
<table className="tjs-table"> | ||
@@ -63,3 +66,6 @@ { Head && <Head rows={ rows } cols={ cols } /> } | ||
</table> | ||
{ afterTableComponents && afterTableComponents.map((Component, index) => <Component key={ index } />) } | ||
{ | ||
afterTableComponents && | ||
afterTableComponents.map((Component, index) => <Component key={ index } />) | ||
} | ||
</div> | ||
@@ -66,0 +72,0 @@ ); |
@@ -57,3 +57,3 @@ import di from 'didi'; | ||
const eventBus = this.get('eventBus'); | ||
eventBus.fire('table.clear'); | ||
@@ -60,0 +60,0 @@ eventBus.fire('diagram.clear'); |
{ | ||
"name": "table-js", | ||
"version": "1.3.2", | ||
"version": "1.3.3", | ||
"scripts": { | ||
"all": "npm run lint && npm run test", | ||
"dev": "karma start test/config/karma.unit.js --log-level debug", | ||
"lint": "eslint lib test", | ||
"test": "karma start test/config/karma.unit.js --single-run --no-auto-watch" | ||
"dev": "karma start --no-single-run --auto-watch --log-level debug", | ||
"lint": "eslint .", | ||
"test": "karma start" | ||
}, | ||
@@ -26,3 +26,2 @@ "module": "lib/Table.js", | ||
"karma-browserify": "^5.0.1", | ||
"karma-chai": "^0.1.0", | ||
"karma-chrome-launcher": "^2.2.0", | ||
@@ -29,0 +28,0 @@ "karma-firefox-launcher": "^1.0.0", |
@@ -10,3 +10,3 @@ import { inject, bootstrap } from 'test/TestHelper'; | ||
it('root', inject(function(elementFactory) { | ||
// when | ||
@@ -27,3 +27,3 @@ const root = elementFactory.createRoot({ | ||
it('row', inject(function(elementFactory) { | ||
// when | ||
@@ -43,3 +43,3 @@ const row = elementFactory.createRow({ | ||
it('col', inject(function(elementFactory) { | ||
// when | ||
@@ -46,0 +46,0 @@ const col = elementFactory.createCol({ |
@@ -10,3 +10,3 @@ import { inject, bootstrap } from 'test/TestHelper'; | ||
it('add', inject(function(elementRegistry) { | ||
// when | ||
@@ -22,3 +22,3 @@ elementRegistry.add({ id: 'foo' }); | ||
it('remove', inject(function(elementRegistry) { | ||
// given | ||
@@ -37,3 +37,3 @@ elementRegistry.add({ id: 'foo' }); | ||
it('get', inject(function(elementRegistry) { | ||
// given | ||
@@ -51,3 +51,3 @@ elementRegistry.add({ id: 'foo' }); | ||
it('getAll', inject(function(elementRegistry) { | ||
// given | ||
@@ -69,3 +69,3 @@ elementRegistry.add({ id: 'foo' }); | ||
it('forEach', inject(function(elementRegistry) { | ||
// given | ||
@@ -93,3 +93,3 @@ elementRegistry.add({ id: 'foo' }); | ||
it('filter', inject(function(elementRegistry) { | ||
// given | ||
@@ -111,3 +111,3 @@ elementRegistry.add({ id: 'foo' }); | ||
it('clear', inject(function(elementRegistry) { | ||
// given | ||
@@ -126,3 +126,3 @@ elementRegistry.add({ id: 'foo' }); | ||
it('clear on table.clear', inject(function(elementRegistry, eventBus) { | ||
// given | ||
@@ -129,0 +129,0 @@ elementRegistry.add({ id: 'foo' }); |
@@ -14,38 +14,38 @@ /* global sinon */ | ||
it('set root', inject(function(sheet) { | ||
// given | ||
const root = { id: 'foo' }; | ||
// when | ||
sheet.setRoot(root); | ||
// then | ||
expect(sheet._root).to.eql(root); | ||
})); | ||
it('setting root should fire events', inject(function(eventBus, sheet) { | ||
// given | ||
const oldRoot = { id: 'foo' }; | ||
const newRoot = { id: 'bar' }; | ||
sheet._root = oldRoot; | ||
const removeSpy = sinon.spy(function(e) { | ||
expect(e.root).to.eql(oldRoot); | ||
}); | ||
const removedSpy = sinon.spy(function(e) { | ||
expect(e.root).to.eql(oldRoot); | ||
}); | ||
const addSpy = sinon.spy(function(e) { | ||
expect(e.root).to.eql(newRoot); | ||
}); | ||
const addedSpy = sinon.spy(function(e) { | ||
expect(e.root).to.eql(newRoot); | ||
}); | ||
eventBus.on('root.remove', removeSpy); | ||
@@ -55,15 +55,15 @@ eventBus.on('root.removed', removedSpy); | ||
eventBus.on('root.added', addedSpy); | ||
// when | ||
sheet.setRoot(newRoot); | ||
})); | ||
it('get root should return set root', inject(function(sheet) { | ||
// given | ||
const root = { id: 'foo' }; | ||
sheet._root = root; | ||
// when | ||
@@ -73,6 +73,6 @@ // then | ||
})); | ||
it('get root should return implicit root', inject(function(sheet) { | ||
// when | ||
@@ -86,17 +86,17 @@ // then | ||
})); | ||
it('should remove root on table.clear', inject(function(eventBus, sheet) { | ||
// given | ||
const root = { id: 'foo' }; | ||
sheet._root = root; | ||
// when | ||
eventBus.fire('table.clear'); | ||
// then | ||
expect(sheet._root).to.be.null; | ||
})); | ||
})); | ||
@@ -123,3 +123,3 @@ }); | ||
it('should fire row.add', inject(function(elementRegistry, eventBus, sheet) { | ||
// given | ||
@@ -137,4 +137,4 @@ const row = { id: 'row', cells: [] }; | ||
})); | ||
it('add row with cells', inject(function(elementRegistry, sheet) { | ||
@@ -161,3 +161,3 @@ | ||
it('add row at index', inject(function(elementRegistry, sheet) { | ||
@@ -174,3 +174,3 @@ | ||
}; | ||
const row2 = { | ||
@@ -182,3 +182,3 @@ id: 'row2', | ||
}; | ||
sheet.addRow(row1); | ||
@@ -202,3 +202,3 @@ | ||
it('remove row with given row', inject(function(elementRegistry, sheet) { | ||
// given | ||
@@ -208,3 +208,3 @@ const row = { id: 'row', cells: [] }; | ||
sheet.addRow(row); | ||
// when | ||
@@ -220,3 +220,3 @@ sheet.removeRow(row); | ||
it('remove row with given row id', inject(function(elementRegistry, sheet) { | ||
// given | ||
@@ -226,3 +226,3 @@ const row = { id: 'row', cells: [] }; | ||
sheet.addRow(row); | ||
// when | ||
@@ -239,3 +239,3 @@ sheet.removeRow(row.id); | ||
it('should fire row.remove', inject(function(elementRegistry, eventBus, sheet) { | ||
// given | ||
@@ -255,3 +255,3 @@ const row = { id: 'row', cells: [] }; | ||
})); | ||
}); | ||
@@ -277,3 +277,3 @@ | ||
it('should fire col.add', inject(function(elementRegistry, eventBus, sheet) { | ||
// given | ||
@@ -291,4 +291,4 @@ const col = { id: 'col', cells: [] }; | ||
})); | ||
it('add col with cells', inject(function(elementRegistry, sheet) { | ||
@@ -315,3 +315,3 @@ | ||
it('add col at index', inject(function(elementRegistry, sheet) { | ||
@@ -328,3 +328,3 @@ | ||
}; | ||
const col2 = { | ||
@@ -336,3 +336,3 @@ id: 'col2', | ||
}; | ||
sheet.addCol(col1); | ||
@@ -356,3 +356,3 @@ | ||
it('remove col with given col', inject(function(elementRegistry, sheet) { | ||
// given | ||
@@ -362,3 +362,3 @@ const col = { id: 'col', cells: [] }; | ||
sheet.addCol(col); | ||
// when | ||
@@ -374,3 +374,3 @@ sheet.removeCol(col); | ||
it('remove col with given col id', inject(function(elementRegistry, sheet) { | ||
// given | ||
@@ -380,3 +380,3 @@ const col = { id: 'col', cells: [] }; | ||
sheet.addCol(col); | ||
// when | ||
@@ -393,3 +393,3 @@ sheet.removeCol(col.id); | ||
it('should fire col.remove', inject(function(elementRegistry, eventBus, sheet) { | ||
// given | ||
@@ -409,5 +409,5 @@ const col = { id: 'col', cells: [] }; | ||
})); | ||
}); | ||
}); |
@@ -13,3 +13,4 @@ | ||
import ContextMenuModule from 'lib/features/context-menu'; | ||
import ContextMenuComponent from 'lib/features/context-menu/components/ContextMenuComponent'; | ||
import ContextMenuComponent | ||
from 'lib/features/context-menu/components/ContextMenuComponent'; | ||
@@ -33,3 +34,3 @@ | ||
describe('ContextMenuComponent', function() { | ||
beforeEach(bootstrap({ | ||
@@ -40,93 +41,101 @@ modules: [ ContextMenuModule ] | ||
it('should render context menu on contextMenu.open', inject(function(components, contextMenu, eventBus, injector) { | ||
it('should render context menu on contextMenu.open', inject( | ||
function(components, contextMenu, eventBus, injector) { | ||
// given | ||
const WithContext = withContext(ContextMenuComponent, { | ||
injector, | ||
eventBus | ||
}); | ||
// given | ||
const WithContext = withContext(ContextMenuComponent, { | ||
injector, | ||
eventBus | ||
}); | ||
const renderedTree = renderIntoDocument(<WithContext />); | ||
const renderedTree = renderIntoDocument(<WithContext />); | ||
components.onGetComponent('context-menu', () => () => <div className="foo"></div>); | ||
// when | ||
contextMenu.open(); | ||
components.onGetComponent('context-menu', () => () => <div className="foo"></div>); | ||
// then | ||
expect(findRenderedDOMElementWithClass(renderedTree, 'context-menu')).to.exist; | ||
expect(findRenderedDOMElementWithClass(renderedTree, 'foo')).to.exist; | ||
})); | ||
// when | ||
contextMenu.open(); | ||
// then | ||
expect(findRenderedDOMElementWithClass(renderedTree, 'context-menu')).to.exist; | ||
expect(findRenderedDOMElementWithClass(renderedTree, 'foo')).to.exist; | ||
} | ||
)); | ||
// TODO(philippfromme): fix | ||
it.skip('should render context menu at position', inject(function(components, contextMenu, eventBus, injector) { | ||
// given | ||
const WithContext = withContext(ContextMenuComponent, { | ||
injector, | ||
eventBus | ||
}); | ||
it.skip('should render context menu at position', inject( | ||
function(components, contextMenu, eventBus, injector) { | ||
const renderedTree = renderIntoDocument(<WithContext />); | ||
// given | ||
const WithContext = withContext(ContextMenuComponent, { | ||
injector, | ||
eventBus | ||
}); | ||
components.onGetComponent('context-menu', () => () => <div></div>); | ||
// when | ||
contextMenu.open({ | ||
x: 100, | ||
y: 100 | ||
}); | ||
const renderedTree = renderIntoDocument(<WithContext />); | ||
// then | ||
const node = findRenderedDOMElementWithClass(renderedTree, 'context-menu'); | ||
components.onGetComponent('context-menu', () => () => <div></div>); | ||
expect(node).to.exist; | ||
expect(node.style.top).to.equal('100px'); | ||
expect(node.style.left).to.equal('100px'); | ||
})); | ||
// when | ||
contextMenu.open({ | ||
x: 100, | ||
y: 100 | ||
}); | ||
// then | ||
const node = findRenderedDOMElementWithClass(renderedTree, 'context-menu'); | ||
it('should not render context menu on contextMenu.open if no components', inject(function(contextMenu, eventBus, injector) { | ||
expect(node).to.exist; | ||
expect(node.style.top).to.equal('100px'); | ||
expect(node.style.left).to.equal('100px'); | ||
} | ||
)); | ||
// given | ||
const WithContext = withContext(ContextMenuComponent, { | ||
injector, | ||
eventBus | ||
}); | ||
const renderedTree = renderIntoDocument(<WithContext />); | ||
// when | ||
contextMenu.open(); | ||
it('should ignore contextMenu.open if no components', inject( | ||
function(contextMenu, eventBus, injector) { | ||
// then | ||
const node = findRenderedDOMElementWithClass(renderedTree, 'context-menu'); | ||
// given | ||
const WithContext = withContext(ContextMenuComponent, { | ||
injector, | ||
eventBus | ||
}); | ||
expect(node).to.not.exist; | ||
})); | ||
const renderedTree = renderIntoDocument(<WithContext />); | ||
// when | ||
contextMenu.open(); | ||
it('should not render context menu on contextMenu.close', inject(function(components, contextMenu, eventBus, injector) { | ||
// given | ||
const WithContext = withContext(ContextMenuComponent, { | ||
injector, | ||
eventBus | ||
}); | ||
// then | ||
const node = findRenderedDOMElementWithClass(renderedTree, 'context-menu'); | ||
const renderedTree = renderIntoDocument(<WithContext />); | ||
expect(node).to.not.exist; | ||
} | ||
)); | ||
components.onGetComponent('context-menu', () => () => <div></div>); | ||
contextMenu.open(); | ||
// when | ||
contextMenu.close(); | ||
it('should not render context menu on contextMenu.close', inject( | ||
function(components, contextMenu, eventBus, injector) { | ||
// then | ||
const node = findRenderedDOMElementWithClass(renderedTree, 'context-menu'); | ||
// given | ||
const WithContext = withContext(ContextMenuComponent, { | ||
injector, | ||
eventBus | ||
}); | ||
expect(node).to.not.exist; | ||
})); | ||
const renderedTree = renderIntoDocument(<WithContext />); | ||
components.onGetComponent('context-menu', () => () => <div></div>); | ||
contextMenu.open(); | ||
// when | ||
contextMenu.close(); | ||
// then | ||
const node = findRenderedDOMElementWithClass(renderedTree, 'context-menu'); | ||
expect(node).to.not.exist; | ||
} | ||
)); | ||
}); |
@@ -22,3 +22,3 @@ | ||
beforeEach(function() { | ||
beforeEach(function() { | ||
testContainer = TestContainer.get(this); | ||
@@ -46,3 +46,3 @@ }); | ||
it('should close', inject(function(components, contextMenu) { | ||
// given | ||
@@ -58,3 +58,3 @@ components.onGetComponent('context-menu', () => () => 'FOO'); | ||
})); | ||
}); |
@@ -46,3 +46,3 @@ import { inject, bootstrap } from 'test/TestHelper'; | ||
it('paste row before', inject(function(clipBoard, cutPaste, sheet) { | ||
// given | ||
@@ -63,3 +63,3 @@ cutPaste.cut(row1); | ||
it('paste row after', inject(function(clipBoard, cutPaste, sheet) { | ||
// given | ||
@@ -93,3 +93,3 @@ cutPaste.cut(row1); | ||
it('paste col before', inject(function(clipBoard, cutPaste, sheet) { | ||
// given | ||
@@ -110,3 +110,3 @@ cutPaste.cut(col1); | ||
it('paste col after', inject(function(clipBoard, cutPaste, sheet) { | ||
// given | ||
@@ -113,0 +113,0 @@ cutPaste.cut(col1); |
@@ -34,3 +34,3 @@ import { inject, bootstrap } from 'test/TestHelper'; | ||
editorActions.unregister('foo', listener); | ||
// then | ||
@@ -42,3 +42,3 @@ expect(editorActions._actions['foo']).to.not.exist; | ||
it('should trigger', inject(function(editorActions) { | ||
// given | ||
@@ -58,7 +58,7 @@ const spy = sinon.spy(); | ||
it('should check if registered', inject(function(editorActions) { | ||
// given | ||
editorActions.register('foo', () => {}); | ||
// when | ||
// when | ||
// then | ||
@@ -81,29 +81,29 @@ expect(editorActions.isRegistered('foo')).to.be.true; | ||
it('redo', expectRegistered('redo')); | ||
it('select', expectRegistered('select')); | ||
it('deselect', expectRegistered('deselect')); | ||
it('addRow', expectRegistered('addRow')); | ||
it('removeRow', expectRegistered('removeRow')); | ||
it('moveRow', expectRegistered('moveRow')); | ||
it('addCol', expectRegistered('addCol')); | ||
it('removeCol', expectRegistered('removeCol')); | ||
it('moveCol', expectRegistered('moveCol')); | ||
}); | ||
}); |
@@ -15,3 +15,7 @@ import Inferno from 'inferno'; | ||
if (e.initMouseEvent) { | ||
e.initMouseEvent(event, true, true, window, 0, 0, 0, clientX, clientY, false, false, false, false, 0, null); | ||
e.initMouseEvent( | ||
event, true, true, window, | ||
0, 0, 0, clientX, clientY, | ||
false, false, false, false, 0, null | ||
); | ||
} | ||
@@ -51,10 +55,10 @@ | ||
function expectInteractionEvent(event) { | ||
return inject(function(eventBus) { | ||
return inject(function(eventBus) { | ||
const spy = sinon.spy(); | ||
eventBus.on(`cell.${event}`, spy); | ||
// when | ||
triggerMouseEvent(nodeWithElementId, event); | ||
// then | ||
@@ -66,10 +70,10 @@ expect(spy).to.have.been.called; | ||
function expectNoInteractionEvent(event) { | ||
return inject(function(eventBus) { | ||
return inject(function(eventBus) { | ||
const spy = sinon.spy(); | ||
eventBus.on(`cell.${event}`, spy); | ||
// when | ||
triggerMouseEvent(nodeWithoutElementId, event); | ||
// then | ||
@@ -109,3 +113,3 @@ expect(spy).to.not.have.been.called; | ||
it('should not fire cell.mouseup', expectNoInteractionEvent('mouseup')); | ||
}); |
@@ -65,5 +65,5 @@ import { inject, bootstrap } from 'test/TestHelper'; | ||
describe('with existing rows', function() { | ||
beforeEach(inject(function(sheet) { | ||
sheet.addCol({ id: 'row1', cells: [] }); | ||
@@ -76,8 +76,8 @@ sheet.addCol({ id: 'row2', cells: [] }); | ||
it('should execute', inject(function(elementRegistry, modeling, sheet) { | ||
// when | ||
modeling.addCol(); | ||
const root = sheet.getRoot(); | ||
// then | ||
@@ -89,13 +89,13 @@ root.rows.forEach(row => { | ||
it('should revert', inject(function(commandStack, elementRegistry, modeling, sheet) { | ||
// given | ||
modeling.addCol(); | ||
const root = sheet.getRoot(); | ||
// when | ||
commandStack.undo(); | ||
// then | ||
@@ -109,3 +109,3 @@ root.rows.forEach(row => { | ||
it('should redo', inject(function(commandStack, elementRegistry, modeling, sheet) { | ||
// given | ||
@@ -115,3 +115,3 @@ modeling.addCol(); | ||
const root = sheet.getRoot(); | ||
// when | ||
@@ -118,0 +118,0 @@ commandStack.undo(); |
@@ -67,3 +67,3 @@ import { inject, bootstrap } from 'test/TestHelper'; | ||
beforeEach(inject(function(sheet) { | ||
sheet.addCol({ id: 'col1', cells: [] }); | ||
@@ -76,3 +76,3 @@ sheet.addCol({ id: 'col2', cells: [] }); | ||
it('should execute', inject(function(elementRegistry, modeling, sheet) { | ||
// when | ||
@@ -82,3 +82,3 @@ modeling.addRow(); | ||
const root = sheet.getRoot(); | ||
// then | ||
@@ -90,5 +90,5 @@ root.cols.forEach(col => { | ||
it('should revert', inject(function(commandStack, elementRegistry, modeling, sheet) { | ||
// given | ||
@@ -98,6 +98,6 @@ modeling.addRow(); | ||
const root = sheet.getRoot(); | ||
// when | ||
commandStack.undo(); | ||
// then | ||
@@ -111,3 +111,3 @@ root.cols.forEach(col => { | ||
it('should redo', inject(function(commandStack, elementRegistry, modeling, sheet) { | ||
// given | ||
@@ -117,3 +117,3 @@ modeling.addRow(); | ||
const root = sheet.getRoot(); | ||
// when | ||
@@ -120,0 +120,0 @@ commandStack.undo(); |
@@ -88,18 +88,20 @@ /* global sinon */ | ||
})); | ||
it('should provide extension point for external change handlers', inject(function(eventBus, interceptor, modeling) { | ||
eventBus.on('elements.changed', () => { | ||
// then | ||
expect(cell.foo).to.eql('foo'); | ||
}); | ||
// when | ||
modeling.editCell(cell); | ||
})); | ||
it('should provide extension point for external change handlers', inject( | ||
function(eventBus, interceptor, modeling) { | ||
eventBus.on('elements.changed', () => { | ||
// then | ||
expect(cell.foo).to.eql('foo'); | ||
}); | ||
// when | ||
modeling.editCell(cell); | ||
} | ||
)); | ||
}); | ||
}); |
@@ -61,3 +61,3 @@ import { inject, bootstrap } from 'test/TestHelper'; | ||
modeling.moveCol(col3, 1); | ||
const root = sheet.getRoot(); | ||
@@ -72,3 +72,3 @@ | ||
})); | ||
}); |
@@ -20,3 +20,3 @@ import { inject, bootstrap } from 'test/TestHelper'; | ||
beforeEach(inject(function(sheet) { | ||
col1 = sheet.addCol({ id: 'col1', cells: [] }); | ||
@@ -64,3 +64,3 @@ col2 = sheet.addCol({ id: 'col2', cells: [] }); | ||
modeling.removeCol(col2); | ||
commandStack.undo(); | ||
@@ -67,0 +67,0 @@ |
@@ -11,3 +11,7 @@ import Inferno from 'inferno'; | ||
if (e.initMouseEvent) { | ||
e.initMouseEvent(event, true, true, window, 0, 0, 0, clientX, clientY, false, false, false, false, 0, null); | ||
e.initMouseEvent( | ||
event, true, true, window, | ||
0, 0, 0, clientX, clientY, | ||
false, false, false, false, 0, null | ||
); | ||
} | ||
@@ -54,3 +58,3 @@ | ||
it('should select on click', inject(function(elementRegistry, eventBus, selection) { | ||
// when | ||
@@ -75,33 +79,37 @@ eventBus.fire('cell.click', { id: 'cell' }); | ||
})); | ||
it('should unselect on row.remove', inject(function(elementRegistry, eventBus, selection) { | ||
// given | ||
selection.select('cell'); | ||
// when | ||
eventBus.fire('row.remove', { | ||
row: elementRegistry.get('row') | ||
}); | ||
it('should unselect on row.remove', inject( | ||
function(elementRegistry, eventBus, selection) { | ||
// then | ||
expect(selection.get()).to.not.exist; | ||
})); | ||
// given | ||
selection.select('cell'); | ||
// when | ||
eventBus.fire('row.remove', { | ||
row: elementRegistry.get('row') | ||
}); | ||
it('should unselect on col.remove', inject(function(elementRegistry, eventBus, selection) { | ||
// given | ||
selection.select('cell'); | ||
// then | ||
expect(selection.get()).to.not.exist; | ||
} | ||
)); | ||
// when | ||
eventBus.fire('col.remove', { | ||
col: elementRegistry.get('col') | ||
}); | ||
// then | ||
expect(selection.get()).to.not.exist; | ||
})); | ||
it('should unselect on col.remove', inject( | ||
function(elementRegistry, eventBus, selection) { | ||
// given | ||
selection.select('cell'); | ||
// when | ||
eventBus.fire('col.remove', { | ||
col: elementRegistry.get('col') | ||
}); | ||
// then | ||
expect(selection.get()).to.not.exist; | ||
} | ||
)); | ||
}); |
@@ -26,3 +26,3 @@ import Inferno from 'inferno'; | ||
beforeEach(function() { | ||
beforeEach(function() { | ||
testContainer = TestContainer.get(this); | ||
@@ -67,6 +67,6 @@ }); | ||
it('should select by element ID', inject(function(selection) { | ||
// when | ||
selection.select(cell1.id); | ||
// then | ||
@@ -107,3 +107,3 @@ expect(selection._selection).to.eql(cell1); | ||
selection.select(cell1); | ||
// when | ||
@@ -113,3 +113,3 @@ selection.freeze(); | ||
selection.select(cell2); | ||
// then | ||
@@ -128,3 +128,3 @@ expect(selection._selection).to.eql(cell1); | ||
selection.freeze(); | ||
// when | ||
@@ -134,3 +134,3 @@ selection.unfreeze(); | ||
selection.select(cell2); | ||
// then | ||
@@ -141,3 +141,3 @@ expect(selection._selection).to.eql(cell2); | ||
})); | ||
}); |
@@ -17,3 +17,3 @@ import { create } from 'lib/model'; | ||
it('should create <row>', function() { | ||
// when | ||
@@ -28,3 +28,3 @@ const row = create('row'); | ||
it('should create <col>', function() { | ||
// when | ||
@@ -31,0 +31,0 @@ const col = create('col'); |
@@ -11,3 +11,3 @@ import { bootstrap, inject } from 'test/TestHelper'; | ||
it('should add listener', inject(function(changeSupport) { | ||
// given | ||
@@ -33,3 +33,3 @@ const listener = () => {}; | ||
changeSupport.onElementsChanged('foo', listener); | ||
// when | ||
@@ -49,3 +49,3 @@ changeSupport.offElementsChanged('foo', listener); | ||
changeSupport.onElementsChanged('foo', () => {}); | ||
// when | ||
@@ -87,3 +87,3 @@ changeSupport.offElementsChanged('foo'); | ||
it('should not call listener', inject(function(eventBus) { | ||
// when | ||
@@ -106,3 +106,3 @@ eventBus.fire('elements.changed', { | ||
let spy; | ||
beforeEach(inject(function(changeSupport, sheet) { | ||
@@ -120,3 +120,3 @@ spy = sinon.spy(); | ||
it('should update on root change', inject(function(sheet, eventBus) { | ||
// when | ||
@@ -126,3 +126,3 @@ const root = { | ||
}; | ||
sheet.setRoot(root); | ||
@@ -129,0 +129,0 @@ |
@@ -16,3 +16,3 @@ | ||
describe('TableComponent', function() { | ||
beforeEach(bootstrap({})); | ||
@@ -64,3 +64,3 @@ | ||
it('should render after table', inject(function(components, injector) { | ||
// given | ||
@@ -78,3 +78,3 @@ components.onGetComponent('table.after', () => () => <div className="after"></div>); | ||
it('should provide child context', inject(function(components, injector) { | ||
// given | ||
@@ -81,0 +81,0 @@ class Body extends Component { |
@@ -12,3 +12,3 @@ import { bootstrap, inject } from 'test/TestHelper'; | ||
const listener = () => {}; | ||
// when | ||
@@ -30,3 +30,3 @@ components.onGetComponent('foo', 1000, listener); | ||
it('should remove listener', inject(function(components) { | ||
// given | ||
@@ -48,3 +48,3 @@ const listener = () => {}; | ||
it('should remove all listeners', inject(function(components) { | ||
// given | ||
@@ -82,3 +82,3 @@ components.onGetComponent('foo', () => {}); | ||
it('should get all components', inject(function(components) { | ||
// when | ||
@@ -91,5 +91,5 @@ // then | ||
})); | ||
}); | ||
}); |
@@ -24,3 +24,3 @@ | ||
it('should render', function() { | ||
// then | ||
@@ -69,3 +69,3 @@ expect(domQuery('.tjs-container')).to.exist; | ||
it('should return container', inject(function(renderer) { | ||
// when | ||
@@ -72,0 +72,0 @@ const container = renderer.getContainer(); |
@@ -51,29 +51,29 @@ import Table from 'lib/Table'; | ||
it('#destroy', function() { | ||
// when | ||
const table = new Table({ | ||
it('#destroy', function() { | ||
// when | ||
const table = new Table({ | ||
renderer: { | ||
container | ||
} | ||
}); | ||
container | ||
} | ||
}); | ||
// then | ||
expect(table.destroy).to.be.a('function'); | ||
}); | ||
// then | ||
expect(table.destroy).to.be.a('function'); | ||
}); | ||
it('#clear', function() { | ||
// when | ||
const table = new Table({ | ||
renderer: { | ||
container | ||
} | ||
}); | ||
it('#clear', function() { | ||
// then | ||
expect(table.clear).to.be.a('function'); | ||
// when | ||
const table = new Table({ | ||
renderer: { | ||
container | ||
} | ||
}); | ||
// then | ||
expect(table.clear).to.be.a('function'); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
27
506342
74
7907