MCPcopy
hub / github.com/winjs/winjs / test

Method test

tests/ListViewComponents/LayoutTest.ts:110–167  ·  view source on GitHub ↗
(layoutName)

Source from the content-addressed store, hash-verified

108
109 testFirstVisibleInConstructor = function (complete) {
110 function test(layoutName) {
111 var element = document.createElement("div");
112 element.style.width = "200px";
113 element.style.height = "200px";
114 testRootEl.appendChild(element);
115
116 var data = [];
117 for (var i = 0; i < 100; i++) {
118 data.push({
119 label: "Item" + i
120 });
121 }
122
123 var requests = [];
124
125 var listView = new ListView(element, {
126 itemDataSource: createDataSource(data, requests),
127 layout: new WinJS.UI[layoutName](),
128 pagesToLoad: 10,
129 itemTemplate: function (itemPromise) {
130 return itemPromise.then(function (item) {
131 var element = document.createElement("div");
132 element.style.width = "100px";
133 element.style.height = "100px";
134 element.textContent = item.data.label;
135 return element;
136 });
137 },
138 indexOfFirstVisible: 24
139 });
140
141 return new WinJS.Promise(function (complete) {
142 function checkAndExecute() {
143 if (listView.loadingState === "complete") {
144 if (layoutName.indexOf("GridLayout") == 0) {
145 LiveUnit.Assert.areEqual(1200, listView.scrollPosition);
146 }
147 else {
148 LiveUnit.Assert.areEqual(2400, listView.scrollPosition);
149 }
150 LiveUnit.Assert.areEqual(24, listView.indexOfFirstVisible);
151
152 LiveUnit.Assert.areEqual(-1, requests.indexOf(2));
153 LiveUnit.Assert.areEqual(-1, requests.indexOf(3));
154
155 var offsetFromSurface = listView._horizontal() ? Helper.ListView.offsetLeftFromSurface : Helper.ListView.offsetTopFromSurface;
156 LiveUnit.Assert.areEqual(listView.scrollPosition, offsetFromSurface(listView, Helper.ListView.containerFrom(listView.elementFromIndex(24))));
157
158 listView.removeEventListener("loadingstatechanged", checkAndExecute, false);
159 testRootEl.removeChild(element);
160 complete();
161 }
162 }
163
164 listView.addEventListener("loadingstatechanged", checkAndExecute, false);
165 checkAndExecute();
166 });
167 }

Callers

nothing calls this directly

Calls 14

setTimeoutFunction · 0.85
createElementMethod · 0.80
appendChildMethod · 0.80
removeChildMethod · 0.80
_horizontalMethod · 0.80
createDataSourceFunction · 0.70
checkTileFunction · 0.70
pushMethod · 0.65
thenMethod · 0.65
addEventListenerMethod · 0.65
addClassMethod · 0.65
checkAndExecuteFunction · 0.50

Tested by

no test coverage detected