Skip to content

Commit

Permalink
test(InfiniteGrid, visibile) : add testcase
Browse files Browse the repository at this point in the history
ref e-225
  • Loading branch information
sculove committed Dec 15, 2015
1 parent f9fc76f commit a810b5e
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/infiniteGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ eg.module("infiniteGrid", ["jQuery", eg, window, "Outlayer"], function($, ns, gl
}
this._prefix = _prefix || "";
this.core = new InfiniteGridCore(el, opts)
.on(this._prefix + EVENTS.layoutComplete, $.proxy(this._onlayoutComplete, this));
.on(EVENTS.layoutComplete, $.proxy(this._onlayoutComplete, this));
this.$global = $(global);
this._reset();
this.core.$element.children().length > 0 && this.layout();
Expand Down Expand Up @@ -499,6 +499,7 @@ eg.module("infiniteGrid", ["jQuery", eg, window, "Outlayer"], function($, ns, gl
* @param {Boolean} param.isAppend isAppend determine if append or prepend (value is true when call layout method)<ko>아이템이 append로 추가되었는지, prepend로 추가되었는지를 반한환다. (layout호출시에는 true)</ko>
* @param {Number} param.distance distance<ko>layout 전의 최상단 엘리먼트의 거리</ko>
*/
console.log("trigger", this._prefix + EVENTS.layoutComplete);
this.trigger(this._prefix + EVENTS.layoutComplete, {
target: e.concat(),
isAppend: isAppend,
Expand Down
2 changes: 1 addition & 1 deletion src/visible.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,4 @@ eg.module("visible", ["jQuery", eg, document], function($, ns, doc) {
this._wrapper = this._timer = null;
}
});
});
});
10 changes: 8 additions & 2 deletions tc/infiniteGrid.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,15 @@
</li>
</ul>
<script>
oinst = new eg.InfiniteGrid("#grid", {
itemSelector : ".item"
// var oinst = new eg.InfiniteGrid("#grid", {
// itemSelector : ".item"
// });
//
var $inst = $("#grid").infiniteGrid({
itemSelector : ".item"
});
var oinst = $inst.infiniteGrid("instance");

var HTML = '<li class="item"><div>테스트1</div></li><li class="item"><div>테스트2</div></li><li class="item"><div>테스트3</div></li><li class="item"><div>테스트4</div></li><li class="item"><div>테스트5</div></li><li class="item"><div>테스트6</div></li><li class="item"><div>테스트7</div></li>';

var tmpStatus = {};
Expand Down
17 changes: 17 additions & 0 deletions test/js/infiniteGrid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,4 +420,21 @@ test("Check public methods return", function () {
equal(this.inst.setStatus(beforeStatus), this.inst, "return instance");
equal(this.inst.layout(), this.inst, "return instance");
equal(this.inst.clear(), this.inst, "return instance");
});

asyncTest("Check prefixEvent", function () {
// Given
var isTriggered = false;
// When
this.inst = new eg.InfiniteGrid("#grid", {}, "TEST:");
this.inst.on("TEST:layoutComplete", function() {
isTriggered = true;
});
this.inst.layout();

// Then
setTimeout(function() {
equal(isTriggered, true, "check if prefixEvent trigger");
start();
},200);
});
30 changes: 30 additions & 0 deletions test/js/visible.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,34 @@ test("When a scroll position of the window was changed", function() {
// Then
equal(visible.length, 6, "visible element length (6)");
equal(invisible.length, 5, "invisible element length (5)");
});

module("Visible event Test", {
setup : function() {
$("#view").show();
},
teardown : function() {
$("#view").hide();
this.inst.destroy();
this.inst = null;
}
});
asyncTest("Check prefixEvent", function () {
// Given
var isTriggered = false;
// When
this.inst = new eg.Visible( "#view", {
targetClass : "check_visible"
}, "TEST:");
this.inst.on("TEST:change", function() {
isTriggered = true;
});
window.scrollTo(0,300);
this.inst.check();

// Then
setTimeout(function() {
equal(isTriggered, true, "check if prefixEvent trigger");
start();
},200);
});

0 comments on commit a810b5e

Please sign in to comment.