diff --git a/lib/arrow-list/arrow-list.js b/lib/arrow-list/arrow-list.js index d67f626..6cd1709 100644 --- a/lib/arrow-list/arrow-list.js +++ b/lib/arrow-list/arrow-list.js @@ -83,6 +83,10 @@ zb.ui.ArrowList.prototype._updateArrows = function() { showHide(prevArr, false); showHide(nextArr, false); return; + } else if (this._buffer.isCyclical()) { + showHide(prevArr, true); + showHide(nextArr, true); + return; } var itemsSkipped = this._buffer.getLocalStart(); diff --git a/lib/base-list/base-list-buffer.js b/lib/base-list/base-list-buffer.js index 072ea3d..b582341 100644 --- a/lib/base-list/base-list-buffer.js +++ b/lib/base-list/base-list-buffer.js @@ -348,15 +348,24 @@ zb.ui.BaseListBuffer.prototype.getLineByIndex = function(index) { zb.ui.BaseListBuffer.prototype.selectNextLine = function() { var currGlobalIndex = this.getGlobalIndex(); var nextGlobalIndex = zb.ui.BaseListUtils.getNextLine(currGlobalIndex, this._options.lineSize); + var lastGlobalIndex = this.getGlobalEnd(); + + // Воркэраунд для циклических списков + if (this.isCyclical() && nextGlobalIndex > lastGlobalIndex) { + var firstGlobalIndex = this.getGlobalStart(); + var firstGlobalLineEnd = zb.ui.BaseListUtils.getLineEnd(firstGlobalIndex, this._options.lineSize); + var nextGlobalLineEnd = zb.ui.BaseListUtils.getLineEnd(nextGlobalIndex, this._options.lineSize); + + nextGlobalIndex = firstGlobalLineEnd - (nextGlobalLineEnd - nextGlobalIndex); // Воркэраунд для последней неполной строки элементов: // Если на сервере больше нет данных и новый индекс выходит за пределы, // То попробуем выбрать не строку, а элемент со следующим индексом - if (this.isGlobalEnd() && !this.isLocalIndex(nextGlobalIndex)) { - var possibleGlobalIndex = zb.ui.BaseListUtils.getNextIndex(currGlobalIndex); + } else if (this.isGlobalEnd() && !this.isLocalIndex(nextGlobalIndex)) { + var possibleNextGlobalIndex = zb.ui.BaseListUtils.getNextIndex(currGlobalIndex); - if (this.isLocalIndex(possibleGlobalIndex)) { - nextGlobalIndex = possibleGlobalIndex; + if (this.isLocalIndex(possibleNextGlobalIndex)) { + nextGlobalIndex = possibleNextGlobalIndex; } } @@ -368,8 +377,22 @@ zb.ui.BaseListBuffer.prototype.selectNextLine = function() { * @return {boolean} */ zb.ui.BaseListBuffer.prototype.selectPrevLine = function() { - var index = zb.ui.BaseListUtils.getPrevLine(this.getGlobalIndex(), this._options.lineSize); - return this.setGlobalIndex(index); + var currGlobalIndex = this.getGlobalIndex(); + var prevGlobalIndex = zb.ui.BaseListUtils.getPrevLine(currGlobalIndex, this._options.lineSize); + + if (this.isCyclical() && prevGlobalIndex < 0) { + var lastGlobalIndex = this.getGlobalEnd(); + var lastGlobalLineEnd = zb.ui.BaseListUtils.getLineEnd(lastGlobalIndex, this._options.lineSize); + var prevGlobalLineEnd = zb.ui.BaseListUtils.getLineEnd(prevGlobalIndex, this._options.lineSize); + + prevGlobalIndex = lastGlobalLineEnd - (prevGlobalLineEnd - prevGlobalIndex); + + if (prevGlobalIndex > lastGlobalIndex) { + prevGlobalIndex = zb.ui.BaseListUtils.getPrevLine(prevGlobalIndex, this._options.lineSize); + } + } + + return this.setGlobalIndex(prevGlobalIndex); }; @@ -381,8 +404,17 @@ zb.ui.BaseListBuffer.prototype.selectNextIndex = function() { return false; } - var index = zb.ui.BaseListUtils.getNextIndex(this.getGlobalIndex()); - return this.setGlobalIndex(index); + var currGlobalIndex = this.getGlobalIndex(); + var lastGlobalIndex = this.getGlobalEnd(); + var nextGlobalIndex; + + if (this.isCyclical() && currGlobalIndex === lastGlobalIndex) { + nextGlobalIndex = 0; + } else { + nextGlobalIndex = zb.ui.BaseListUtils.getNextIndex(currGlobalIndex); + } + + return this.setGlobalIndex(nextGlobalIndex); }; @@ -394,8 +426,17 @@ zb.ui.BaseListBuffer.prototype.selectPrevIndex = function() { return false; } - var index = zb.ui.BaseListUtils.getPrevIndex(this.getGlobalIndex()); - return this.setGlobalIndex(index); + var currGlobalIndex = this.getGlobalIndex(); + var lastGlobalIndex = this.getGlobalEnd(); + var prevGlobalIndex; + + if (this.isCyclical() && currGlobalIndex === 0) { + prevGlobalIndex = lastGlobalIndex; + } else { + prevGlobalIndex = zb.ui.BaseListUtils.getPrevIndex(currGlobalIndex); + } + + return this.setGlobalIndex(prevGlobalIndex); }; @@ -428,8 +469,9 @@ zb.ui.BaseListBuffer.prototype.setGlobalIndex = function(globalIndex) { var isSelected = false; - // Чтобы выделялся существующий в DOM элемент. - if (this.isLocalIndex(globalIndex)) { + // Выбрать NaN можно только программно через source, + // пользовательские действия не могут привести к выбору NaN + if (!isNaN(globalIndex)) { var sourceIndex = globalIndex - this.getSourceStart(); isSelected = this._setSourceIndex(sourceIndex); } diff --git a/lib/base-list/base-list-data-list.js b/lib/base-list/base-list-data-list.js index fe36114..5ae5ae4 100644 --- a/lib/base-list/base-list-data-list.js +++ b/lib/base-list/base-list-data-list.js @@ -9,6 +9,7 @@ goog.provide('zb.ui.BaseListDataList'); goog.require('zb.ui.BaseListBuffer'); goog.require('zb.ui.DynamicList'); +goog.require('zb.ui.CyclicalDataList'); @@ -149,6 +150,14 @@ zb.ui.BaseListDataList.prototype.isDynamic = function() { }; +/** + * @return {boolean} + */ +zb.ui.BaseListDataList.prototype.isCyclical = function() { + return this._source instanceof zb.ui.CyclicalDataList; +}; + + /** * @inheritDoc */ diff --git a/lib/base-list/base-list-utils.js b/lib/base-list/base-list-utils.js index 1bcacbe..6b5056c 100644 --- a/lib/base-list/base-list-utils.js +++ b/lib/base-list/base-list-utils.js @@ -140,12 +140,7 @@ zb.ui.BaseListUtils.getPrevLine = function(currIndex, lineSize) { */ zb.ui.BaseListUtils.getNextIndex = function(currIndex) { var nextIndex = currIndex + 1; - - if (!zb.ui.BaseListUtils.isValidIndex(nextIndex)) { - return NaN; - } - - return nextIndex; + return zb.ui.BaseListUtils.isValidIndex(nextIndex) ? nextIndex : NaN; }; @@ -155,12 +150,7 @@ zb.ui.BaseListUtils.getNextIndex = function(currIndex) { */ zb.ui.BaseListUtils.getPrevIndex = function(currIndex) { var prevIndex = currIndex - 1; - - if (!zb.ui.BaseListUtils.isValidIndex(prevIndex)) { - return NaN; - } - - return prevIndex; + return zb.ui.BaseListUtils.isValidIndex(prevIndex) ? prevIndex : NaN; }; diff --git a/lib/data-list.js b/lib/data-list.js index cc5fadc..ca62844 100644 --- a/lib/data-list.js +++ b/lib/data-list.js @@ -44,7 +44,7 @@ zb.ui.DataList.prototype.isLoading = function() { * @inheritDoc */ zb.ui.DataList.prototype.preload = function() { - return Promise.resolve(); + return /** @type {IThenable.} */(Promise.resolve(this)); }; diff --git a/lib/dynamic-list.js b/lib/dynamic-list.js index 0141ae8..b888e1e 100644 --- a/lib/dynamic-list.js +++ b/lib/dynamic-list.js @@ -80,7 +80,7 @@ zb.ui.DynamicList.prototype.getFrameSize = function() { /** - * @return {IThenable.} + * @inheritDoc */ zb.ui.DynamicList.prototype.preload = function() { if (!this._preloadQuery) { @@ -90,7 +90,7 @@ zb.ui.DynamicList.prototype.preload = function() { this._preloadQuery = this.loadItems(from, to, false); } - return this._preloadQuery; + return /** @type {IThenable.} */(this._preloadQuery); }; diff --git a/lib/i-data-list.js b/lib/i-data-list.js index e962141..63e7ea7 100644 --- a/lib/i-data-list.js +++ b/lib/i-data-list.js @@ -27,7 +27,7 @@ zb.ui.IDataList.prototype.isLoading = function() {}; /** - * @return {IThenable} + * @return {IThenable.} */ zb.ui.IDataList.prototype.preload = function() {}; diff --git a/lib/input/native-input.js b/lib/input/native-input.js index 454ee15..f623171 100644 --- a/lib/input/native-input.js +++ b/lib/input/native-input.js @@ -19,7 +19,7 @@ goog.require('zb.ui.IInputWidget'); * @constructor */ zb.ui.NativeInput = function(container, opt_params) { - this._onFocus = this._onFocus.bind(this); + this._onFocusInput = this._onFocusInput.bind(this); this._onKeyDown = this._onKeyDown.bind(this); this._internalFocus = false; @@ -137,12 +137,12 @@ zb.ui.NativeInput.prototype._setupInput = function() { var input = /** @type {HTMLInputElement} */(this._container); if (this._input) { - this._input.removeEventListener('focus', this._onFocus); + this._input.removeEventListener('focus', this._onFocusInput); this._input.removeEventListener('keydown', this._onKeyDown); } this._input = input; - this._input.addEventListener('focus', this._onFocus, false); + this._input.addEventListener('focus', this._onFocusInput, false); this._input.addEventListener('keydown', this._onKeyDown, false); clearInterval(this._detectChangeIntervalId); @@ -155,7 +155,7 @@ zb.ui.NativeInput.prototype._setupInput = function() { /** * @protected */ -zb.ui.NativeInput.prototype._onFocus = function() { +zb.ui.NativeInput.prototype._onFocusInput = function() { if (this._internalFocus) { this._internalFocus = false; } else if (!this.isFocused()) { diff --git a/package.json b/package.json index f4e27b0..39b4660 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zombiebox-extension-ui", - "version": "0.1.3", + "version": "0.1.4", "main": "zombiebox-extension.js", "scripts": { "test": "karma start karma.components.conf.js --single-run" @@ -22,6 +22,6 @@ "mocha-test-steps": "^0.1.0", "sinon": "^1.14.1", "sinon-chai": "^2.7.0", - "zombiebox": "0.0.192" + "zombiebox": "0.0.197" } } diff --git a/test/base-list/integration/support/helper.js b/test/base-list/integration/support/helper.js index dec650e..d443245 100644 --- a/test/base-list/integration/support/helper.js +++ b/test/base-list/integration/support/helper.js @@ -17,11 +17,21 @@ zb.ui.test.support.Helper.defaultOptions = { loadOnLeft: 1 }; +/** + * @param {Array.} array + * @return {zb.ui.DataList.} + */ zb.ui.test.support.Helper.createDataList = function(array) { return new zb.ui.DataList(array); }; -zb.ui.test.support.Helper.createBuffer = function(dataList) { + +/** + * @param {zb.ui.DataList.} dataList + * @param {zb.ui.BaseListBuffer.Options=} opt_options + * @return {IThenable.} + */ +zb.ui.test.support.Helper.createBuffer = function(dataList, opt_options) { var helper = zb.ui.test.support.Helper; var buffer = new zb.ui.BaseListDataList(function() { helper.changeCallback.apply(helper, arguments); @@ -29,13 +39,20 @@ zb.ui.test.support.Helper.createBuffer = function(dataList) { helper.selectCallback.apply(helper, arguments); }); - buffer.setSource(dataList, helper.defaultOptions); + buffer.setSource(dataList, opt_options || helper.defaultOptions); - return dataList.preload(); + return dataList + .preload() + .then(function() { + return buffer; + }); }; // Default +/** + * @return {Array.} + */ zb.ui.test.support.Helper.createDefaultArray = function() { return [ 'A', 'B', 'C', @@ -50,11 +67,19 @@ zb.ui.test.support.Helper.createDefaultArray = function() { ]; }; + +/** + * @return {zb.ui.DataList.} + */ zb.ui.test.support.Helper.createDefaultDataList = function() { var array = zb.ui.test.support.Helper.createDefaultArray(); return zb.ui.test.support.Helper.createDataList(array); }; + +/** + * @return {IThenable.} + */ zb.ui.test.support.Helper.createDefaultBuffer = function() { var dataList = zb.ui.test.support.Helper.createDefaultDataList(); return zb.ui.test.support.Helper.createBuffer(dataList); @@ -62,6 +87,9 @@ zb.ui.test.support.Helper.createDefaultBuffer = function() { // Other +/** + * @return {Array.} + */ zb.ui.test.support.Helper.createOtherArray = function() { return [ 'alpha', 'beta', 'gamma', @@ -75,11 +103,19 @@ zb.ui.test.support.Helper.createOtherArray = function() { ]; }; + +/** + * @return {zb.ui.DataList.} + */ zb.ui.test.support.Helper.createOtherDataList = function() { var array = zb.ui.test.support.Helper.createOtherArray(); return zb.ui.test.support.Helper.createDataList(array); }; + +/** + * @return {IThenable.} + */ zb.ui.test.support.Helper.createOtherBuffer = function() { var dataList = zb.ui.test.support.Helper.createOtherDataList(); return zb.ui.test.support.Helper.createBuffer(dataList); @@ -87,15 +123,26 @@ zb.ui.test.support.Helper.createOtherBuffer = function() { // Empty +/** + * @return {Array.} + */ zb.ui.test.support.Helper.createEmptyArray = function() { return []; }; + +/** + * @return {zb.ui.DataList.} + */ zb.ui.test.support.Helper.createEmptyDataList = function() { var array = zb.ui.test.support.Helper.createEmptyArray(); return zb.ui.test.support.Helper.createDataList(array); }; + +/** + * @return {IThenable.} + */ zb.ui.test.support.Helper.createEmptyBuffer = function() { var dataList = zb.ui.test.support.Helper.createEmptyDataList(); return zb.ui.test.support.Helper.createBuffer(dataList); diff --git a/test/base-list/integration/with-cyclical-data-list-select-next.mocha.js b/test/base-list/integration/with-cyclical-data-list-select-next.mocha.js new file mode 100644 index 0000000..5c396f6 --- /dev/null +++ b/test/base-list/integration/with-cyclical-data-list-select-next.mocha.js @@ -0,0 +1,501 @@ +describe('zb.ui.BaseListDataList with zb.ui.CyclicalDataList: select next', function() { + var expect = chai.expect; + var given = mochaTestSteps.given; + var when = mochaTestSteps.when; + var then = mochaTestSteps.then; + + var dataList, buffer, bufferPromise, spyChange, spySelect; + var helper = zb.ui.test.support.Helper; + + beforeEach(function() { + dataList = new zb.ui.CyclicalDataList(helper.createDefaultArray()); + bufferPromise = helper + .createBuffer(dataList) + .then(function(result) { + spySelect.reset(); + spyChange.reset(); + + buffer = result; + + return result; + }); + + spySelect = sinon.spy(helper, 'selectCallback'); + spyChange = sinon.spy(helper, 'changeCallback'); + }); + afterEach(function() { + spySelect.restore(); + spyChange.restore(); + }); + + it('Selecting next item', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select next item', function() { + dataList.selectNextItem(); + }); + // THEN + then('selectCallback is called once with new item and old item', function() { + expect(spySelect) + .calledWith('B', 1, 'A', 0) + .callCount(1); + }); + then('changeCallback is not called', function() { + expect(spyChange) + .callCount(0); + }); + // DONE + return then('done'); + }); + + it('Selecting next next item', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select next next item', function() { + dataList.selectNextItem(); + dataList.selectNextItem(); + }); + // THEN + then('selectCallback is called twice with new item and old item', function() { + expect(spySelect.withArgs('B', 1, 'A', 0)) + .callCount(1); + expect(spySelect.withArgs('C', 2, 'B', 1)) + .callCount(1); + }); + then('changeCallback is not called', function() { + expect(spyChange) + .callCount(0); + }); + // DONE + return then('done'); + }); + + it('Selecting last but one and last item', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select last but one and next item', function() { + dataList.selectAt(dataList.size() - 2); + dataList.selectNextItem(); + }); + // THEN + then('selectCallback is called twice with new item and old item', function() { + expect(spySelect.withArgs('Y', 6, null, NaN)) + .callCount(1); + expect(spySelect.withArgs('Z', 7, 'Y', 6)) + .callCount(1); + }); + then('changeCallback is called once with new buffer contents', function() { + expect(spyChange) + .calledWith([ + 'S', 'T', 'U', + 'V', 'W', 'X', + 'Y', 'Z' + ]) + .callCount(1); + }); + // DONE + return then('done'); + }); + + it('Selecting next after last item', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select last and next item', function() { + dataList.selectLast(); + dataList.selectNextItem(); + }); + // THEN + then('selectCallback is called twice with new item and old item', function() { + expect(spySelect.withArgs('Z', 7, null, NaN)) + .callCount(1); + expect(spySelect.withArgs('A', 0, null, NaN)) + .callCount(1); + }); + then('changeCallback is called twice with new buffer contents', function() { + expect(spyChange.withArgs([ + 'S', 'T', 'U', + 'V', 'W', 'X', + 'Y', 'Z' + ])) + .callCount(1); + expect(spyChange.withArgs([ + 'A', 'B', 'C', + 'D', 'E', 'F', + 'G', 'H', 'I' + ])) + .callCount(1); + }); + // DONE + return then('done'); + }); + + it('Selecting next index via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select next index', function() { + buffer.selectNextIndex(); + }); + // THEN + then('selectCallback is called once with new item and old item', function() { + expect(spySelect) + .calledWith('B', 1, 'A', 0) + .callCount(1); + }); + then('changeCallback is not called', function() { + expect(spyChange) + .callCount(0); + }); + // DONE + return then('done'); + }); + + it('Selecting next next index via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select next next index', function() { + buffer.selectNextIndex(); + buffer.selectNextIndex(); + }); + // THEN + then('selectCallback is called twice with new item and old item', function() { + expect(spySelect.withArgs('B', 1, 'A', 0)) + .callCount(1); + expect(spySelect.withArgs('C', 2, 'B', 1)) + .callCount(1); + }); + then('changeCallback is not called', function() { + expect(spyChange) + .callCount(0); + }); + // DONE + return then('done'); + }); + + it('Selecting last but one item and next index via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select last item and next index', function() { + dataList.selectAt(dataList.size() - 2); + buffer.selectNextIndex(); + }); + // THEN + then('selectCallback is called twice with new item and old item', function() { + expect(spySelect.withArgs('Y', 6, null, NaN)) + .callCount(1); + expect(spySelect.withArgs('Z', 7, 'Y', 6)) + .callCount(1); + }); + then('changeCallback is called once with new buffer contents', function() { + expect(spyChange) + .calledWith([ + 'S', 'T', 'U', + 'V', 'W', 'X', + 'Y', 'Z' + ]) + .callCount(1); + }); + // DONE + return then('done'); + }); + + it('Selecting last item and next index via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select last item and next line', function() { + dataList.selectLast(); + buffer.selectNextIndex(); + }); + // THEN + then('selectCallback is called twice with new item and old item', function() { + expect(spySelect.withArgs('Z', 7, null, NaN)) + .callCount(1); + expect(spySelect.withArgs('A', 0, null, NaN)) + .callCount(1); + }); + then('changeCallback is called twice with new buffer contents', function() { + expect(spyChange.withArgs([ + 'S', 'T', 'U', + 'V', 'W', 'X', + 'Y', 'Z' + ])) + .callCount(1); + expect(spyChange.withArgs([ + 'A', 'B', 'C', + 'D', 'E', 'F', + 'G', 'H', 'I' + ])) + .callCount(1); + }); + // DONE + return then('done'); + }); + + it('Selecting next line via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select next line', function() { + buffer.selectNextLine(); + }); + // THEN + then('selectCallback is called once with new item and old item', function() { + expect(spySelect) + .calledWith('D', 3, 'A', 0) + .callCount(1); + }); + then('changeCallback is not called', function() { + expect(spyChange) + .callCount(0); + }); + // DONE + return then('done'); + }); + + it('Selecting next next line via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select next next line', function() { + buffer.selectNextLine(); + buffer.selectNextLine(); + }); + // THEN + then('selectCallback is called twice with new item and old item', function() { + expect(spySelect.withArgs('D', 3, 'A', 0)) + .callCount(1); + expect(spySelect.withArgs('G', 6, 'D', 3)) + .callCount(1); + }); + then('changeCallback is called once with new buffer contents', function() { + expect(spyChange) + .calledWith([ + 'A', 'B', 'C', + 'D', 'E', 'F', + 'G', 'H', 'I', + 'J', 'K', 'L', + 'M', 'N', 'O' + ]) + .callCount(1); + }); + // DONE + return then('done'); + }); + + it('Selecting next item and next line via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select next item and next line', function() { + dataList.selectNextItem(); + buffer.selectNextLine(); + }); + // THEN + then('selectCallback is called twice with new item and old item', function() { + expect(spySelect.withArgs('B', 1, 'A', 0)) + .callCount(1); + expect(spySelect.withArgs('E', 4, 'B', 1)) + .callCount(1); + }); + then('changeCallback is not called', function() { + expect(spyChange) + .callCount(0); + }); + // DONE + return then('done'); + }); + + it('Selecting next next item and next line via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select next item and next line', function() { + dataList.selectNextItem(); + dataList.selectNextItem(); + buffer.selectNextLine(); + }); + // THEN + then('selectCallback is called twice with new item and old item', function() { + expect(spySelect.withArgs('B', 1, 'A', 0)) + .callCount(1); + expect(spySelect.withArgs('C', 2, 'B', 1)) + .callCount(1); + expect(spySelect.withArgs('F', 5, 'C', 2)) + .callCount(1); + }); + then('changeCallback is not called', function() { + expect(spyChange) + .callCount(0); + }); + // DONE + return then('done'); + }); + + it('Selecting last but one line and next line via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select last but one line and next line', function() { + dataList.selectAt(dataList.size() - 5); + buffer.selectNextLine(); + }); + // THEN + then('selectCallback is called twice with new item and old item', function() { + expect(spySelect.withArgs('V', 6, null, NaN)) + .callCount(1); + expect(spySelect.withArgs('Y', 9, 'V', 6)) + .callCount(1); + }); + then('changeCallback is called once with new buffer contents', function() { + expect(spyChange) + .calledWith([ + 'P', 'Q', 'R', + 'S', 'T', 'U', + 'V', 'W', 'X', + 'Y', 'Z' + ]) + .callCount(1); + }); + // DONE + return then('done'); + }); + + it('Selecting last but one item and next line via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select last but one item and next line', function() { + dataList.selectAt(dataList.size() - 2); + buffer.selectNextLine(); + }); + // THEN + then('selectCallback is called twice with new item and old item', function() { + expect(spySelect.withArgs('Y', 6, null, NaN)) + .callCount(1); + expect(spySelect.withArgs('A', 0, null, NaN)) + .callCount(1); + }); + then('changeCallback is called twice with new buffer contents', function() { + expect(spyChange.withArgs([ + 'S', 'T', 'U', + 'V', 'W', 'X', + 'Y', 'Z' + ])) + .callCount(1); + expect(spyChange.withArgs([ + 'A', 'B', 'C', + 'D', 'E', 'F', + 'G', 'H', 'I' + ])) + .callCount(1); + }); + // DONE + return then('done'); + }); + + it('Selecting last but two item and next line via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select last but two item and next line', function() { + dataList.selectAt(dataList.size() - 3); + buffer.selectNextLine(); + }); + // THEN + then('selectCallback is called twice with new item and old item', function() { + expect(spySelect.withArgs('X', 8, null, NaN)) + .callCount(1); + expect(spySelect.withArgs('C', 2, null, NaN)) + .callCount(1); + }); + then('changeCallback is called twice with new buffer contents', function() { + expect(spyChange.withArgs([ + 'P', 'Q', 'R', + 'S', 'T', 'U', + 'V', 'W', 'X', + 'Y', 'Z' + ])) + .callCount(1); + expect(spyChange.withArgs([ + 'A', 'B', 'C', + 'D', 'E', 'F', + 'G', 'H', 'I' + ])) + .callCount(1); + }); + // DONE + return then('done'); + }); + + it('Selecting last item and next line via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select last item and next line', function() { + dataList.selectLast(); + buffer.selectNextLine(); + }); + // THEN + then('selectCallback is called twice with new item and old item', function() { + expect(spySelect.withArgs('Z', 7, null, NaN)) + .callCount(1); + expect(spySelect.withArgs('B', 1, null, NaN)) + .callCount(1); + }); + then('changeCallback is called twice with new buffer contents', function() { + expect(spyChange.withArgs([ + 'S', 'T', 'U', + 'V', 'W', 'X', + 'Y', 'Z' + ])) + .callCount(1); + expect(spyChange.withArgs([ + 'A', 'B', 'C', + 'D', 'E', 'F', + 'G', 'H', 'I' + ])) + .callCount(1); + }); + // DONE + return then('done'); + }); +}); diff --git a/test/base-list/integration/with-cyclical-data-list-select-prev.mocha.js b/test/base-list/integration/with-cyclical-data-list-select-prev.mocha.js new file mode 100644 index 0000000..d97bc55 --- /dev/null +++ b/test/base-list/integration/with-cyclical-data-list-select-prev.mocha.js @@ -0,0 +1,340 @@ +describe('zb.ui.BaseListDataList with zb.ui.CyclicalDataList: select prev', function() { + var expect = chai.expect; + var given = mochaTestSteps.given; + var when = mochaTestSteps.when; + var then = mochaTestSteps.then; + + var dataList, buffer, bufferPromise, spyChange, spySelect; + var helper = zb.ui.test.support.Helper; + + beforeEach(function() { + dataList = new zb.ui.CyclicalDataList(helper.createDefaultArray()); + bufferPromise = helper + .createBuffer(dataList) + .then(function(result) { + spySelect.reset(); + spyChange.reset(); + + buffer = result; + + return result; + }); + + spySelect = sinon.spy(helper, 'selectCallback'); + spyChange = sinon.spy(helper, 'changeCallback'); + }); + afterEach(function() { + spySelect.restore(); + spyChange.restore(); + }); + + it('Selecting prev item', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select prev item', function() { + dataList.selectPrevItem(); + }); + // THEN + then('selectCallback is called once with new item and old item', function() { + expect(spySelect) + .calledWith('Z', 7, null, NaN) + .callCount(1); + }); + then('changeCallback is called once with new buffer contents', function() { + expect(spyChange) + .calledWith([ + 'S', 'T', 'U', + 'V', 'W', 'X', + 'Y', 'Z' + ]) + .callCount(1); + }); + // DONE + return then('done'); + }); + + it('Selecting prev prev item', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select prev prev item', function() { + dataList.selectPrevItem(); + dataList.selectPrevItem(); + }); + // THEN + then('selectCallback is called twice with new item and old item', function() { + expect(spySelect.withArgs('Z', 7, null, NaN)) + .callCount(1); + expect(spySelect.withArgs('Y', 6, 'Z', 7)) + .callCount(1); + }); + then('changeCallback is called twice with new item and old item', function() { + expect(spyChange) + .calledWith([ + 'S', 'T', 'U', + 'V', 'W', 'X', + 'Y', 'Z' + ]) + .callCount(1); + }); + // DONE + return then('done'); + }); + + it('Selecting second and prev item', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select second and prev item', function() { + dataList.selectAt(1); + dataList.selectPrevItem(); + }); + // THEN + then('selectCallback is called twice with new item and old item', function() { + expect(spySelect.withArgs('B', 1, 'A', 0)) + .callCount(1); + expect(spySelect.withArgs('A', 0, 'B', 1)) + .callCount(1); + }); + then('changeCallback is not called', function() { + expect(spyChange) + .callCount(0); + }); + // DONE + return then('done'); + }); + + it('Selecting prev index via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select prev index', function() { + buffer.selectPrevIndex(); + }); + // THEN + then('selectCallback is called once with new item and old item', function() { + expect(spySelect) + .calledWith('Z', 7, null, NaN) + .callCount(1); + }); + then('changeCallback is called once with new buffer contents', function() { + expect(spyChange) + .calledWith([ + 'S', 'T', 'U', + 'V', 'W', 'X', + 'Y', 'Z' + ]) + .callCount(1); + }); + // DONE + return then('done'); + }); + + it('Selecting prev prev index via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select prev prev index', function() { + buffer.selectPrevIndex(); + buffer.selectPrevIndex(); + }); + // THEN + then('selectCallback is called twice with new item and old item', function() { + expect(spySelect.withArgs('Z', 7, null, NaN)) + .callCount(1); + expect(spySelect.withArgs('Y', 6, 'Z', 7)) + .callCount(1); + }); + then('changeCallback is called once with new item and old item', function() { + expect(spyChange) + .calledWith([ + 'S', 'T', 'U', + 'V', 'W', 'X', + 'Y', 'Z' + ]) + .callCount(1); + }); + // DONE + return then('done'); + }); + + it('Selecting second item and prev index via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select last item and prev index', function() { + dataList.selectAt(1); + buffer.selectPrevIndex(); + }); + // THEN + then('selectCallback is called twice with new item and old item', function() { + expect(spySelect.withArgs('B', 1, 'A', 0)) + .callCount(1); + expect(spySelect.withArgs('A', 0, 'B', 1)) + .callCount(1); + }); + then('changeCallback is not called', function() { + expect(spyChange) + .callCount(0); + }); + // DONE + return then('done'); + }); + + it('Selecting prev line via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select prev index', function() { + buffer.selectPrevLine(); + }); + // THEN + then('selectCallback is called once with new item and old item', function() { + expect(spySelect) + .calledWith('Y', 6, null, NaN) + .callCount(1); + }); + then('changeCallback is called once with new buffer contents', function() { + expect(spyChange) + .calledWith([ + 'S', 'T', 'U', + 'V', 'W', 'X', + 'Y', 'Z' + ]) + .callCount(1); + }); + // DONE + return then('done'); + }); + + it('Selecting prev prev line via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select prev prev line', function() { + buffer.selectPrevLine(); + buffer.selectPrevLine(); + }); + // THEN + then('selectCallback is called twice with new item and old item', function() { + expect(spySelect.withArgs('Y', 6, null, NaN)) + .callCount(1); + expect(spySelect.withArgs('V', 3, 'Y', 6)) + .callCount(1); + }); + then('changeCallback is called once with new item and old item', function() { + expect(spyChange) + .calledWith([ + 'S', 'T', 'U', + 'V', 'W', 'X', + 'Y', 'Z' + ]) + .callCount(1); + }); + // DONE + return then('done'); + }); + + it('Selecting second item and prev line via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select second item and prev line', function() { + dataList.selectAt(1); + buffer.selectPrevLine(); + }); + // THEN + then('selectCallback is called twice with new item and old item', function() { + expect(spySelect.withArgs('B', 1, 'A', 0)) + .callCount(1); + expect(spySelect.withArgs('Z', 7, null, NaN)) + .callCount(1); + }); + then('changeCallback is called once with new item and old item', function() { + expect(spyChange) + .calledWith([ + 'S', 'T', 'U', + 'V', 'W', 'X', + 'Y', 'Z' + ]) + .callCount(1); + }); + // DONE + return then('done'); + }); + + it('Selecting third item and prev line via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select third item and prev line', function() { + dataList.selectAt(2); + buffer.selectPrevLine(); + }); + // THEN + then('selectCallback is called twice with new item and old item', function() { + expect(spySelect.withArgs('C', 2, 'A', 0)) + .callCount(1); + expect(spySelect.withArgs('X', 8, null, NaN)) + .callCount(1); + }); + then('changeCallback is called once with new item and old item', function() { + expect(spyChange) + .calledWith([ + 'P', 'Q', 'R', + 'S', 'T', 'U', + 'V', 'W', 'X', + 'Y', 'Z' + ]) + .callCount(1); + }); + // DONE + return then('done'); + }); + + it('Selecting second line and prev line via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select second line and prev line', function() { + buffer.selectNextLine(); + buffer.selectPrevLine(); + }); + // THEN + then('selectCallback is called twice with new item and old item', function() { + expect(spySelect.withArgs('D', 3, 'A', 0)) + .callCount(1); + expect(spySelect.withArgs('A', 0, 'D', 3)) + .callCount(1); + }); + then('changeCallback is not called', function() { + expect(spyChange) + .callCount(0); + }); + // DONE + return then('done'); + }); +}); diff --git a/test/base-list/integration/with-data-list-select-next.mocha.js b/test/base-list/integration/with-data-list-select-next.mocha.js new file mode 100644 index 0000000..df05b1f --- /dev/null +++ b/test/base-list/integration/with-data-list-select-next.mocha.js @@ -0,0 +1,359 @@ +describe('zb.ui.BaseListDataList: select next', function() { + var expect = chai.expect; + var given = mochaTestSteps.given; + var when = mochaTestSteps.when; + var then = mochaTestSteps.then; + + var dataList, buffer, bufferPromise, spyChange, spySelect; + var helper = zb.ui.test.support.Helper; + + beforeEach(function() { + dataList = helper.createDefaultDataList(); + bufferPromise = helper + .createBuffer(dataList) + .then(function(result) { + spySelect.reset(); + spyChange.reset(); + + buffer = result; + + return result; + }); + + spySelect = sinon.spy(helper, 'selectCallback'); + spyChange = sinon.spy(helper, 'changeCallback'); + }); + afterEach(function() { + spySelect.restore(); + spyChange.restore(); + }); + + it('Selecting next item', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select next item', function() { + dataList.selectNextItem(); + }); + // THEN + then('selectCallback is called once with new item and old item', function() { + expect(spySelect) + .calledWith('B', 1, 'A', 0) + .callCount(1); + }); + then('changeCallback is not called', function() { + expect(spyChange) + .callCount(0); + }); + // DONE + return then('done'); + }); + + it('Selecting next next item', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select next next item', function() { + dataList.selectNextItem(); + dataList.selectNextItem(); + }); + // THEN + then('selectCallback is called twice with new item and old item', function() { + expect(spySelect.withArgs('B', 1, 'A', 0)) + .callCount(1); + expect(spySelect.withArgs('C', 2, 'B', 1)) + .callCount(1); + }); + then('changeCallback is not called', function() { + expect(spyChange) + .callCount(0); + }); + // DONE + return then('done'); + }); + + it('Selecting last but one and last item', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select last but one and next item', function() { + dataList.selectAt(dataList.size() - 2); + dataList.selectNextItem(); + }); + // THEN + then('selectCallback is called twice with new item and old item', function() { + expect(spySelect.withArgs('Y', 6, null, NaN)) + .callCount(1); + expect(spySelect.withArgs('Z', 7, 'Y', 6)) + .callCount(1); + }); + then('changeCallback is called once with new buffer contents', function() { + expect(spyChange) + .calledWith([ + 'S', 'T', 'U', + 'V', 'W', 'X', + 'Y', 'Z' + ]) + .callCount(1); + }); + // DONE + return then('done'); + }); + + it('Selecting next after last item', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select last and next item', function() { + dataList.selectLast(); + dataList.selectNextItem(); + }); + // THEN + then('selectCallback is called once with new item and old item', function() { + expect(spySelect) + .calledWith('Z', 7, null, NaN) + .callCount(1); + }); + then('changeCallback is called once with new buffer contents', function() { + expect(spyChange) + .calledWith([ + 'S', 'T', 'U', + 'V', 'W', 'X', + 'Y', 'Z' + ]) + .callCount(1); + }); + // DONE + return then('done'); + }); + + it('Selecting next index via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select next index', function() { + buffer.selectNextIndex(); + }); + // THEN + then('selectCallback is called once with new item and old item', function() { + expect(spySelect) + .calledWith('B', 1, 'A', 0) + .callCount(1); + }); + then('changeCallback is not called', function() { + expect(spyChange) + .callCount(0); + }); + // DONE + return then('done'); + }); + + it('Selecting next next index via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select next next index', function() { + buffer.selectNextIndex(); + buffer.selectNextIndex(); + }); + // THEN + then('selectCallback is called twice with new item and old item', function() { + expect(spySelect.withArgs('B', 1, 'A', 0)) + .callCount(1); + expect(spySelect.withArgs('C', 2, 'B', 1)) + .callCount(1); + }); + then('changeCallback is not called', function() { + expect(spyChange) + .callCount(0); + }); + // DONE + return then('done'); + }); + + it('Selecting last but one item and next index via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select last item and next index', function() { + dataList.selectAt(dataList.size() - 2); + buffer.selectNextIndex(); + }); + // THEN + then('selectCallback is called twice with new item and old item', function() { + expect(spySelect.withArgs('Y', 6, null, NaN)) + .callCount(1); + expect(spySelect.withArgs('Z', 7, 'Y', 6)) + .callCount(1); + }); + then('changeCallback is called once with new buffer contents', function() { + expect(spyChange) + .calledWith([ + 'S', 'T', 'U', + 'V', 'W', 'X', + 'Y', 'Z' + ]) + .callCount(1); + }); + // DONE + return then('done'); + }); + + it('Selecting last item and next index via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select last item and next line', function() { + dataList.selectLast(); + buffer.selectNextIndex(); + }); + // THEN + then('selectCallback is called once with new item and old item', function() { + expect(spySelect) + .calledWith('Z', 7, null, NaN) + .callCount(1); + }); + then('changeCallback is called once with new buffer contents', function() { + expect(spyChange) + .calledWith([ + 'S', 'T', 'U', + 'V', 'W', 'X', + 'Y', 'Z' + ]) + .callCount(1); + }); + // DONE + return then('done'); + }); + + it('Selecting next line via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select next line', function() { + buffer.selectNextLine(); + }); + // THEN + then('selectCallback is called once with new item and old item', function() { + expect(spySelect) + .calledWith('D', 3, 'A', 0) + .callCount(1); + }); + then('changeCallback is not called', function() { + expect(spyChange) + .callCount(0); + }); + // DONE + return then('done'); + }); + + it('Selecting next next line via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select next next line', function() { + buffer.selectNextLine(); + buffer.selectNextLine(); + }); + // THEN + then('selectCallback is called twice with new item and old item', function() { + expect(spySelect.withArgs('D', 3, 'A', 0)) + .callCount(1); + expect(spySelect.withArgs('G', 6, 'D', 3)) + .callCount(1); + }); + then('changeCallback is called once with new buffer contents', function() { + expect(spyChange) + .calledWith([ + 'A', 'B', 'C', + 'D', 'E', 'F', + 'G', 'H', 'I', + 'J', 'K', 'L', + 'M', 'N', 'O' + ]) + .callCount(1); + }); + // DONE + return then('done'); + }); + + it('Selecting last but one line and next line via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select last but one item and next line', function() { + dataList.selectAt(dataList.size() - 5); + buffer.selectNextLine(); + }); + // THEN + then('selectCallback is called twice with new item and old item', function() { + expect(spySelect.withArgs('V', 6, null, NaN)) + .callCount(1); + expect(spySelect.withArgs('Y', 9, 'V', 6)) + .callCount(1); + }); + then('changeCallback is called once with new buffer contents', function() { + expect(spyChange) + .calledWith([ + 'P', 'Q', 'R', + 'S', 'T', 'U', + 'V', 'W', 'X', + 'Y', 'Z' + ]) + .callCount(1); + }); + // DONE + return then('done'); + }); + + it('Selecting last item and next line via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select last item and next line', function() { + dataList.selectLast(); + buffer.selectNextLine(); + }); + // THEN + then('selectCallback is called once with new item and old item', function() { + expect(spySelect) + .calledWith('Z', 7, null, NaN) + .callCount(1); + }); + then('changeCallback is called once with new buffer contents', function() { + expect(spyChange) + .calledWith([ + 'S', 'T', 'U', + 'V', 'W', 'X', + 'Y', 'Z' + ]) + .callCount(1); + }); + // DONE + return then('done'); + }); +}); diff --git a/test/base-list/integration/with-data-list-select-prev.mocha.js b/test/base-list/integration/with-data-list-select-prev.mocha.js new file mode 100644 index 0000000..5168652 --- /dev/null +++ b/test/base-list/integration/with-data-list-select-prev.mocha.js @@ -0,0 +1,240 @@ +describe('zb.ui.BaseListDataList: select prev', function() { + var expect = chai.expect; + var given = mochaTestSteps.given; + var when = mochaTestSteps.when; + var then = mochaTestSteps.then; + + var dataList, buffer, bufferPromise, spyChange, spySelect; + var helper = zb.ui.test.support.Helper; + + beforeEach(function() { + dataList = helper.createDefaultDataList(); + bufferPromise = helper + .createBuffer(dataList) + .then(function(result) { + spySelect.reset(); + spyChange.reset(); + + buffer = result; + + return result; + }); + + spySelect = sinon.spy(helper, 'selectCallback'); + spyChange = sinon.spy(helper, 'changeCallback'); + }); + afterEach(function() { + spySelect.restore(); + spyChange.restore(); + }); + + it('Selecting prev item', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select prev item', function() { + dataList.selectPrevItem(); + }); + // THEN + then('selectCallback is not called', function() { + expect(spySelect) + .callCount(0); + }); + then('changeCallback is not called', function() { + expect(spyChange) + .callCount(0); + }); + // DONE + return then('done'); + }); + + it('Selecting prev prev item', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select prev prev item', function() { + dataList.selectPrevItem(); + dataList.selectPrevItem(); + }); + // THEN + then('selectCallback is not called', function() { + expect(spySelect) + .callCount(0); + }); + then('changeCallback is not called', function() { + expect(spyChange) + .callCount(0); + }); + // DONE + return then('done'); + }); + + it('Selecting second and prev item', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select second and prev item', function() { + dataList.selectAt(1); + dataList.selectPrevItem(); + }); + // THEN + then('selectCallback is called twice with new item and old item', function() { + expect(spySelect.withArgs('B', 1, 'A', 0)) + .callCount(1); + expect(spySelect.withArgs('A', 0, 'B', 1)) + .callCount(1); + }); + then('changeCallback is not called', function() { + expect(spyChange) + .callCount(0); + }); + // DONE + return then('done'); + }); + + it('Selecting prev index via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select prev index', function() { + buffer.selectPrevIndex(); + }); + // THEN + then('selectCallback is not called', function() { + expect(spySelect) + .callCount(0); + }); + then('changeCallback is not called', function() { + expect(spyChange) + .callCount(0); + }); + // DONE + return then('done'); + }); + + it('Selecting prev prev index via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select prev prev index', function() { + buffer.selectPrevIndex(); + buffer.selectPrevIndex(); + }); + // THEN + then('selectCallback is not called', function() { + expect(spySelect) + .callCount(0); + }); + then('changeCallback is not called', function() { + expect(spyChange) + .callCount(0); + }); + // DONE + return then('done'); + }); + + it('Selecting second item and prev index via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select second item and prev index', function() { + dataList.selectAt(1); + buffer.selectPrevIndex(); + }); + // THEN + then('selectCallback is called twice with new item and old item', function() { + expect(spySelect.withArgs('B', 1, 'A', 0)) + .callCount(1); + expect(spySelect.withArgs('A', 0, 'B', 1)) + .callCount(1); + }); + then('changeCallback is not called', function() { + expect(spyChange) + .callCount(0); + }); + // DONE + return then('done'); + }); + + it('Selecting prev line via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select prev index', function() { + buffer.selectPrevLine(); + }); + // THEN + then('selectCallback is not called', function() { + expect(spySelect) + .callCount(0); + }); + then('changeCallback is not called', function() { + expect(spyChange) + .callCount(0); + }); + // DONE + return then('done'); + }); + + it('Selecting prev prev line via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select prev prev line', function() { + buffer.selectPrevLine(); + buffer.selectPrevLine(); + }); + // THEN + then('selectCallback is not called', function() { + expect(spySelect) + .callCount(0); + }); + then('changeCallback is not called', function() { + expect(spyChange) + .callCount(0); + }); + // DONE + return then('done'); + }); + + it('Selecting second line and prev line via buffer', function() { + // GIVEN + given('created baselist-datalist', function() { + return bufferPromise; + }); + // WHEN + when('select second line and prev line', function() { + buffer.selectNextLine(); + buffer.selectPrevLine(); + }); + // THEN + then('selectCallback is called twice with new item and old item', function() { + expect(spySelect.withArgs('D', 3, 'A', 0)) + .callCount(1); + expect(spySelect.withArgs('A', 0, 'D', 3)) + .callCount(1); + }); + then('changeCallback is not called', function() { + expect(spyChange) + .callCount(0); + }); + // DONE + return then('done'); + }); +});