mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00

* chore: move tns-core-modules to nativescript-core * chore: preparing compat generate script * chore: add missing definitions * chore: no need for http-request to be private * chore: packages chore * test: generate tests for tns-core-modules * chore: add anroid module for consistency * chore: add .npmignore * chore: added privateModulesWhitelist * chore(webpack): added bundle-entry-points * chore: scripts * chore: tests changed to use @ns/core * test: add scoped-packages test project * test: fix types * test: update test project * chore: build scripts * chore: update build script * chore: npm scripts cleanup * chore: make the compat pgk work with old wp config * test: generate diff friendly tests * chore: create barrel exports * chore: move files after rebase * chore: typedoc config * chore: compat mode * chore: review of barrels * chore: remove tns-core-modules import after rebase * chore: dev workflow setup * chore: update developer-workflow * docs: experiment with API extractor * chore: api-extractor and barrel exports * chore: api-extractor configs * chore: generate d.ts rollup with api-extractor * refactor: move methods inside Frame * chore: fic tests to use Frame static methods * refactor: create Builder class * refactor: use Builder class in tests * refactor: include Style in ui barrel * chore: separate compat build script * chore: fix tslint errors * chore: update NATIVESCRIPT_CORE_ARGS * chore: fix compat pack * chore: fix ui-test-app build with linked modules * chore: Application, ApplicationSettings, Connectivity and Http * chore: export Trace, Profiling and Utils * refactor: Static create methods for ImageSource * chore: fix deprecated usages of ImageSource * chore: move Span and FormattedString to ui * chore: add events-args and ImageSource to index files * chore: check for CLI >= 6.2 when building for IOS * chore: update travis build * chore: copy Pod file to compat package * chore: update error msg ui-tests-app * refactor: Apply suggestions from code review Co-Authored-By: Martin Yankov <m.i.yankov@gmail.com> * chore: typings and refs * chore: add missing d.ts files for public API * chore: adress code review FB * chore: update api-report * chore: dev-workflow for other apps * chore: api update * chore: update api-report
185 lines
7.8 KiB
TypeScript
185 lines
7.8 KiB
TypeScript
import * as TKUnit from "../tk-unit";
|
|
import * as types from "@nativescript/core/utils/types";
|
|
import * as virtualArrayModule from "@nativescript/core/data/virtual-array";
|
|
|
|
export var test_VirtualArray_shouldCreateArrayFromSpecifiedLength = function () {
|
|
var array = new virtualArrayModule.VirtualArray<number>(100);
|
|
|
|
TKUnit.assert(array.length === 100, "VirtualArray<T> should create array from specified length!");
|
|
};
|
|
|
|
export var test_VirtualArray_setItemShouldSetCorrectItem = function () {
|
|
var array = new virtualArrayModule.VirtualArray<number>(100);
|
|
array.setItem(0, 0);
|
|
TKUnit.assert(array.getItem(0) === 0, "VirtualArray<T> setItem() should set correct item!");
|
|
};
|
|
|
|
export var test_VirtualArray_setItemShouldRaiseChangeEventWhenYouSetDifferentItem = function () {
|
|
var array = new virtualArrayModule.VirtualArray<number>(100);
|
|
array.loadSize = 15;
|
|
|
|
var result: virtualArrayModule.ChangedData<number>;
|
|
var index = 0;
|
|
|
|
array.on(virtualArrayModule.VirtualArray.changeEvent, (args: virtualArrayModule.ChangedData<number>) => {
|
|
result = args;
|
|
});
|
|
|
|
array.setItem(index, 0);
|
|
|
|
TKUnit.assert(result && result.eventName === "change" && result.action === virtualArrayModule.ChangeType.Update &&
|
|
result.removed.length === 1 && result.index === index && result.addedCount === 1, "VirtualArray<T> setItem() should raise 'change' event with correct args!");
|
|
|
|
result = undefined;
|
|
|
|
array.setItem(index, 1);
|
|
|
|
TKUnit.assert(result && result.eventName === "change" && result.action === virtualArrayModule.ChangeType.Update &&
|
|
result.removed.length === 1 && result.index === index && result.addedCount === 1, "VirtualArray<T> setItem() should raise 'change' event with correct args!");
|
|
|
|
array.on(virtualArrayModule.VirtualArray.itemsLoadingEvent, (args: virtualArrayModule.ItemsLoading) => {
|
|
// Argument (args) is ItemsLoading.
|
|
// args.index is start index of the page where the requested index is located.
|
|
// args.count number of requested items.
|
|
//
|
|
// Note: Virtual array will divide total number of items to pages using "loadSize" property value. When you request an
|
|
// item at specific index the array will raise "itemsLoading" event with "ItemsLoading" argument index set to the first index of the requested page
|
|
// and count set to number of items in this page.
|
|
//
|
|
// Important: If you have already loaded items in the requested page the array will raise multiple times "itemsLoading" event to request
|
|
// all ranges of still not loaded items in this page.
|
|
|
|
var itemsToLoad = new Array<number>();
|
|
for (var i = 0; i < args.count; i++) {
|
|
itemsToLoad.push(i + args.index);
|
|
}
|
|
|
|
array.load(args.index, itemsToLoad);
|
|
});
|
|
};
|
|
|
|
export var test_VirtualArray_loadShouldRaiseChangeEventWithCorrectArgs = function () {
|
|
var array = new virtualArrayModule.VirtualArray<number>(100);
|
|
array.loadSize = 15;
|
|
|
|
var result: virtualArrayModule.ChangedData<number>;
|
|
var index = 0;
|
|
|
|
array.on(virtualArrayModule.VirtualArray.changeEvent, (args: virtualArrayModule.ChangedData<number>) => {
|
|
// Argument (args) is ChangedData<T>.
|
|
// args.eventName is "change".
|
|
// args.action is "update".
|
|
// args.removed.length and result.addedCount are equal to number of loaded items with load() method.
|
|
|
|
result = args;
|
|
});
|
|
|
|
var itemsToLoad = [0, 1, 2];
|
|
|
|
array.load(index, itemsToLoad);
|
|
|
|
TKUnit.assert(result && result.eventName === "change" && result.action === virtualArrayModule.ChangeType.Update &&
|
|
result.removed.length === itemsToLoad.length && result.index === index && result.addedCount === itemsToLoad.length,
|
|
"VirtualArray<T> load() should raise 'change' event with correct args!");
|
|
};
|
|
|
|
export var test_VirtualArray_lengthIncreaseShouldRaiseChangeEventWithCorrectArgs = function () {
|
|
var array = new virtualArrayModule.VirtualArray<number>(100);
|
|
array.loadSize = 15;
|
|
|
|
var result: virtualArrayModule.ChangedData<number>;
|
|
var index = array.length;
|
|
|
|
array.on(virtualArrayModule.VirtualArray.changeEvent, (args: virtualArrayModule.ChangedData<number>) => {
|
|
// Argument (args) is ChangedData<T>.
|
|
// args.eventName is "change".
|
|
// args.action is "add".
|
|
// args.removed.length is 0, result.addedCount is equal to the delta between new and old "length" property values.
|
|
|
|
result = args;
|
|
});
|
|
|
|
array.length += array.loadSize;
|
|
|
|
TKUnit.assert(result && result.eventName === "change" && result.action === virtualArrayModule.ChangeType.Add
|
|
&& result.index === index && result.addedCount === array.loadSize && result.removed.length === 0,
|
|
"VirtualArray<T> length++ should raise 'change' event with correct args!");
|
|
};
|
|
|
|
export var test_VirtualArray_lengthDecreaseShouldRaiseChangeEventWithCorrectArgs = function () {
|
|
var array = new virtualArrayModule.VirtualArray<number>(100);
|
|
array.loadSize = 15;
|
|
|
|
var result: virtualArrayModule.ChangedData<number>;
|
|
var index = array.length;
|
|
|
|
array.on(virtualArrayModule.VirtualArray.changeEvent, (args: virtualArrayModule.ChangedData<number>) => {
|
|
// Argument (args) is ChangedData<T>.
|
|
// args.eventName is "change".
|
|
// args.action is "remove".
|
|
// result.addedCount is 0, args.removed.length is equal to the delta between new and old "length" property values.
|
|
|
|
result = args;
|
|
});
|
|
|
|
array.length -= array.loadSize;
|
|
|
|
TKUnit.assert(result && result.eventName === "change" && result.action === virtualArrayModule.ChangeType.Delete
|
|
&& result.index === index && result.removed.length === array.loadSize && result.addedCount === 0,
|
|
"VirtualArray<T> length++ should raise 'change' event with correct args!");
|
|
};
|
|
|
|
export var test_VirtualArray_shouldRaiseItemsLoadingIfIndexIsNotLoadedAndGetItemIsCalled = function () {
|
|
var array = new virtualArrayModule.VirtualArray<number>(100);
|
|
array.loadSize = 15;
|
|
|
|
var result: virtualArrayModule.ItemsLoading;
|
|
|
|
array.on(virtualArrayModule.VirtualArray.itemsLoadingEvent, (args: virtualArrayModule.ItemsLoading) => {
|
|
result = args;
|
|
});
|
|
|
|
array.getItem(0);
|
|
|
|
TKUnit.assert(result.eventName === virtualArrayModule.VirtualArray.itemsLoadingEvent && result.index === 0 &&
|
|
result.count === array.loadSize, "VirtualArray<T> getItem() should raise 'itemsLoading' event with correct args if item is not loaded!");
|
|
};
|
|
|
|
export var test_VirtualArray_shouldNotRaiseItemsLoadingIfIndexIsLoadedAndGetItemIsCalled = function () {
|
|
var array = new virtualArrayModule.VirtualArray<number>(100);
|
|
array.setItem(0, 0);
|
|
array.loadSize = 15;
|
|
|
|
var result: virtualArrayModule.ItemsLoading;
|
|
|
|
array.on(virtualArrayModule.VirtualArray.itemsLoadingEvent, (args: virtualArrayModule.ItemsLoading) => {
|
|
result = args;
|
|
});
|
|
|
|
array.getItem(0);
|
|
|
|
TKUnit.assert(types.isUndefined(result), "VirtualArray<T> getItem() should not raise 'itemsLoading' event if item is loaded!");
|
|
};
|
|
|
|
export var test_VirtualArray_shouldRaiseItemsLoadingIfIndexIsNotLoadedAndGetItemIsCalledCorrectNumberOfTimesWithCorrectArgs = function () {
|
|
var array = new virtualArrayModule.VirtualArray<number>(100);
|
|
array.loadSize = 15;
|
|
|
|
array.setItem(0, 0);
|
|
|
|
array.setItem(5, 5);
|
|
|
|
var result = new Array<virtualArrayModule.ItemsLoading>();
|
|
|
|
array.on(virtualArrayModule.VirtualArray.itemsLoadingEvent, (args: virtualArrayModule.ItemsLoading) => {
|
|
result.push(args);
|
|
});
|
|
|
|
array.getItem(1);
|
|
|
|
TKUnit.assert(result.length === 2 &&
|
|
result[0].eventName === virtualArrayModule.VirtualArray.itemsLoadingEvent && result[0].index === 1 && result[0].count === 4 &&
|
|
result[1].eventName === virtualArrayModule.VirtualArray.itemsLoadingEvent && result[1].index === 6 && result[1].count === 9,
|
|
"VirtualArray<T> getItem() should raise 'itemsLoading' event with correct args!");
|
|
};
|