|
1 | 1 | import TKUnit = require("./TKUnit"); |
| 2 | +import bindableModule = require("ui/core/bindable"); |
2 | 3 | require("globals"); |
3 | 4 |
|
4 | 5 | // <snippet module="data/observable-array" title="observable-array"> |
@@ -80,34 +81,6 @@ export var test_ObservableArray_concatShouldReturnNewArrayWithNewItemsAtTheEnd = |
80 | 81 | TKUnit.assert(result.length === 6 && result[4] === 5, "ObservableArray concat() should add items at the end!"); |
81 | 82 | }; |
82 | 83 |
|
83 | | -export var test_ObservableArray_concatShouldReturnNewArrayWithNewItemsAtTheEndAndRaiseChangeEventWithCorrectArgs = function () { |
84 | | - var result: observableArrayModule.ChangedData<number>; |
85 | | - // <snippet module="data/observable-array" title="observable-array"> |
86 | | - // ### Use concat() method to append array to ObservableArray and handle "change" event. |
87 | | - // ``` JavaScript |
88 | | - var array = new observableArrayModule.ObservableArray([1, 2, 3]); |
89 | | - |
90 | | - array.on(observableArrayModule.knownEvents.change, (args: observableArrayModule.ChangedData<number>) => { |
91 | | - //// Argument (args) is ChangedData<T>. |
92 | | - //// args.eventName is "change". |
93 | | - //// args.action is "add". |
94 | | - //// args.index is equal to the array length. |
95 | | - //// args.removed.length is 0. |
96 | | - //// args.addedCount is equal to number of added items. |
97 | | - |
98 | | - // <hide> |
99 | | - result = args; |
100 | | - // </hide> |
101 | | - }); |
102 | | - |
103 | | - array.concat([4, 5, 6]); |
104 | | - // ``` |
105 | | - // </snippet> |
106 | | - |
107 | | - TKUnit.assert(result.eventName === "change" && result.action === observableArrayModule.ChangeType.Add && |
108 | | - result.removed.length === 0 && result.index === 3 && result.addedCount === 3, "ObservableArray concat() should raise 'change' event with correct args!"); |
109 | | -}; |
110 | | - |
111 | 84 | export var test_ObservableArray_joinShouldReturnStringWithAllItemsSeparatedWithComma = function () { |
112 | 85 | // <snippet module="data/observable-array" title="observable-array"> |
113 | 86 | // ### Use join() method to convert ObservableArray to comma separated string. |
@@ -135,10 +108,16 @@ export var test_ObservableArray_popShouldRemoveTheLastElement = function () { |
135 | 108 | // ### Use pop() method to remove the last element. |
136 | 109 | // ``` JavaScript |
137 | 110 | var array = new observableArrayModule.ObservableArray([1, 2, 3]); |
| 111 | + // <hide> |
| 112 | + var bindable = new bindableModule.Bindable(); |
| 113 | + bindable.set("testProperty", 0); |
| 114 | + bindable.bind({ sourceProperty: "length", targetProperty: "testProperty" }, array); |
| 115 | + // </hide> |
138 | 116 | var result = array.pop(); |
139 | 117 | // ``` |
140 | 118 | // </snippet> |
141 | 119 | TKUnit.assert(result === 3 && array.length === 2, "ObservableArray pop() should remove last element!"); |
| 120 | + TKUnit.assert(bindable.get("testProperty") === array.length, "Expected: " + array.length + ", Actual: " + bindable.get("testProperty")); |
142 | 121 | }; |
143 | 122 |
|
144 | 123 | export var test_ObservableArray_popShouldRemoveTheLastElementAndRaiseChangeEventWithCorrectArgs = function () { |
@@ -176,10 +155,16 @@ export var test_ObservableArray_pushShouldAppendNewElement = function () { |
176 | 155 | // ### Use push() method to add single element to the array. |
177 | 156 | // ``` JavaScript |
178 | 157 | var array = new observableArrayModule.ObservableArray([1, 2, 3]); |
| 158 | + // <hide> |
| 159 | + var bindable = new bindableModule.Bindable(); |
| 160 | + bindable.set("testProperty", 0); |
| 161 | + bindable.bind({ sourceProperty: "length", targetProperty: "testProperty" }, array); |
| 162 | + // </hide> |
179 | 163 | var result = array.push(4); |
180 | 164 | // ``` |
181 | 165 | // </snippet> |
182 | 166 | TKUnit.assert(result === 4 && array.getItem(3) === 4, "ObservableArray push() should append new element!"); |
| 167 | + TKUnit.assert(bindable.get("testProperty") === array.length, "Expected: " + array.length + ", Actual: " + bindable.get("testProperty")); |
183 | 168 | }; |
184 | 169 |
|
185 | 170 | export var test_ObservableArray_pushShouldAppendNewElementAndRaiseChangeEventWithCorrectArgs = function () { |
@@ -215,10 +200,16 @@ export var test_ObservableArray_pushShouldAppendNewElements = function () { |
215 | 200 | // ### Use push() method to add multiple elements to the array. |
216 | 201 | // ``` JavaScript |
217 | 202 | var array = new observableArrayModule.ObservableArray([1, 2, 3]); |
| 203 | + // <hide> |
| 204 | + var bindable = new bindableModule.Bindable(); |
| 205 | + bindable.set("testProperty", 0); |
| 206 | + bindable.bind({ sourceProperty: "length", targetProperty: "testProperty" }, array); |
| 207 | + // </hide> |
218 | 208 | var result = array.push(4, 5, 6); |
219 | 209 | // ``` |
220 | 210 | // </snippet> |
221 | 211 | TKUnit.assert(result === 6 && array.getItem(5) === 6, "ObservableArray push() should append new elements!"); |
| 212 | + TKUnit.assert(bindable.get("testProperty") === array.length, "Expected: " + array.length + ", Actual: " + bindable.get("testProperty")); |
222 | 213 | }; |
223 | 214 |
|
224 | 215 | export var test_ObservableArray_pushShouldAppendNewElementsAndRaiseChangeEventWithCorrectArgs = function () { |
@@ -254,10 +245,16 @@ export var test_ObservableArray_pushShouldAppendNewElementsFromSourceArray = fun |
254 | 245 | // ### Use push() method to add multiple elements from source array to the ObservableArray. |
255 | 246 | // ``` JavaScript |
256 | 247 | var array = new observableArrayModule.ObservableArray([1, 2, 3]); |
| 248 | + // <hide> |
| 249 | + var bindable = new bindableModule.Bindable(); |
| 250 | + bindable.set("testProperty", 0); |
| 251 | + bindable.bind({ sourceProperty: "length", targetProperty: "testProperty" }, array); |
| 252 | + // </hide> |
257 | 253 | var result = array.push([4, 5, 6]); |
258 | 254 | // ``` |
259 | 255 | // </snippet> |
260 | 256 | TKUnit.assert(result === 6 && array.getItem(5) === 6, "ObservableArray push() should append new elements from source array!"); |
| 257 | + TKUnit.assert(bindable.get("testProperty") === array.length, "Expected: " + array.length + ", Actual: " + bindable.get("testProperty")); |
261 | 258 | }; |
262 | 259 |
|
263 | 260 | export var test_ObservableArray_pushShouldAppendNewElementsFromSourceArrayAndRaiseChangeEventWithCorrectArgs = function () { |
@@ -304,10 +301,16 @@ export var test_ObservableArray_shiftShouldRemoveTheFirstElement = function () { |
304 | 301 | // ### Use shift() method to remove the first element of the array. |
305 | 302 | // ``` JavaScript |
306 | 303 | var array = new observableArrayModule.ObservableArray([1, 2, 3]); |
| 304 | + // <hide> |
| 305 | + var bindable = new bindableModule.Bindable(); |
| 306 | + bindable.set("testProperty", 0); |
| 307 | + bindable.bind({ sourceProperty: "length", targetProperty: "testProperty" }, array); |
| 308 | + // </hide> |
307 | 309 | var result = array.shift(); |
308 | 310 | // ``` |
309 | 311 | // </snippet> |
310 | 312 | TKUnit.assert(result === 1 && array.length === 2, "ObservableArray shift() should remove first element!"); |
| 313 | + TKUnit.assert(bindable.get("testProperty") === array.length, "Expected: " + array.length + ", Actual: " + bindable.get("testProperty")); |
311 | 314 | }; |
312 | 315 |
|
313 | 316 | export var test_ObservableArray_shiftShouldRemoveTheFirstElementAndRaiseChangeEventWithCorrectArgs = function () { |
@@ -388,11 +391,17 @@ export var test_ObservableArray_spliceShouldRemoveSpecifiedNumberOfElementsStart |
388 | 391 | // ### Use splice(start, deleteCount) method to delete elements in the array. |
389 | 392 | // ``` JavaScript |
390 | 393 | var array = new observableArrayModule.ObservableArray(["one", "two", "three"]); |
| 394 | + // <hide> |
| 395 | + var bindable = new bindableModule.Bindable(); |
| 396 | + bindable.set("testProperty", 0); |
| 397 | + bindable.bind({ sourceProperty: "length", targetProperty: "testProperty" }, array); |
| 398 | + // </hide> |
391 | 399 | var result = array.splice(1, 2); |
392 | 400 | // ``` |
393 | 401 | // </snippet> |
394 | 402 | TKUnit.assert(result.length === 2 && result[0] === "two" && array.length === 1 && array.getItem(0) === "one", |
395 | 403 | "ObservableArray splice() should remove specified number of elements starting from specified index!"); |
| 404 | + TKUnit.assert(bindable.get("testProperty") === array.length, "Expected: " + array.length + ", Actual: " + bindable.get("testProperty")); |
396 | 405 | }; |
397 | 406 |
|
398 | 407 | export var test_ObservableArray_spliceShouldRemoveSpecifiedNumberOfElementsStartingFromSpecifiedIndexAndRaiseChangeEventWithCorrectArgs = function () { |
@@ -470,11 +479,17 @@ export var test_ObservableArray_unshiftShouldInsertNewElementsFromTheStart = fun |
470 | 479 | // ### Use unshift(item1, item2... itemN) method to insert elements from the start of the array. |
471 | 480 | // ``` JavaScript |
472 | 481 | var array = new observableArrayModule.ObservableArray([1, 2, 3]); |
| 482 | + // <hide> |
| 483 | + var bindable = new bindableModule.Bindable(); |
| 484 | + bindable.set("testProperty", 0); |
| 485 | + bindable.bind({ sourceProperty: "length", targetProperty: "testProperty" }, array); |
| 486 | + // </hide> |
473 | 487 | var result = array.unshift(4, 5); |
474 | 488 | // ``` |
475 | 489 | // </snippet> |
476 | 490 |
|
477 | 491 | TKUnit.assert(array.getItem(0) === 4 && result === 5 && array.length === 5, "ObservableArray unshift() should insert new elements from the start!"); |
| 492 | + TKUnit.assert(bindable.get("testProperty") === array.length, "Expected: " + array.length + ", Actual: " + bindable.get("testProperty")); |
478 | 493 | }; |
479 | 494 |
|
480 | 495 | export var test_ObservableArray_unshiftShouldInsertNewElementsFromTheStartAndRaiseChangeEventWithCorrectArgs = function () { |
|
0 commit comments