Skip to content

Commit

Permalink
add flag to uicommon for unitest
Browse files Browse the repository at this point in the history
  • Loading branch information
wsky committed Aug 9, 2012
1 parent 2caa68a commit dfe1996
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
10 changes: 7 additions & 3 deletions src/Cooper.Web/Scripts/task_common.js
Expand Up @@ -19,6 +19,7 @@ UI_List_Common.prototype = {
deletes_timer: null, //删除恢复期间的定时器
deletes_timer2: null, //删除恢复期间的定时器
detail_timer: null, //详情区域渲染延时timer
detail_timer_enable: true, //为unittest而设计的属性
//常用任务属性
today: '0',
upcoming: '1',
Expand Down Expand Up @@ -68,13 +69,16 @@ UI_List_Common.prototype = {
if (this.detail_timer)
clearTimeout(this.detail_timer);
var base = this;
//增加timer延迟优化性能
this.detail_timer = setTimeout(function () {
var fn = function () {
var t = base.getTask($r);
base.$wrapper_detail.empty().append(t.renderDetail());
//额外修正一些由于未append导致的显示问题
t.fixDetail();
}, 100);
}
if (this.detail_timer_enable)
this.detail_timer = setTimeout(fn, 100); //增加timer延迟优化性能
else
fn();
},
_renderBatchDetail: function ($rows) {
if (!this.$batchDetail)
Expand Down
29 changes: 20 additions & 9 deletions src/Cooper.Web/Scripts/tests.js
Expand Up @@ -23,6 +23,9 @@ function runTests() {
var up = 38;
var down = 40;

//预置一些参数适合同步测试
UI_List_Common.prototype.detail_timer_enable = false;

///////////////////////////////////////////////////////////////////////////////
test('init', function () {
ok(taskCount() > 0, 'cached_tasks init');
Expand Down Expand Up @@ -250,27 +253,32 @@ function runTests() {
equal($el_cancel_delete.css('display'), 'block', 'cancel delete region show');
}
function assertIsCompleted($r, b) {
var task = getTask($r);
equal($r.hasClass(row_completed), b, 'mark taskrow iscompleted change');
equal(getTask($r).isCompleted(), b, 'task iscompleted change');
equal(task.isCompleted(), b, 'task iscompleted change');
//detail
var $btn = $el_wrapper_detail.find('#isCompleted');
equal($btn.hasClass('active'), b);
equal(task.$el_detail.find('#isCompleted').hasClass('active'), b);
}
function assertSubjectChange($r, v) {
equal(getTask($r).subject(), v, 'subject change');
var task = getTask($r);
equal(task.subject(), v, 'subject change');
equal($r.find('#subject').val(), v, 'subject change in row');
equal($el_wrapper_detail.find('#subject').val(), v, 'subject change in detail');
//detail
equal(task.$el_detail.find('#subject').val(), v, 'subject change in detail');
}
function assertPriorityChange($r, p) {
equal(getTask($r).priority(), p);
equal($el_wrapper_detail.find('#priority button.active').attr('priority'), p, 'priority change in detail');
var task = getTask($r);
equal(task.priority(), p);
//detail
equal(task.$el_detail.find('#priority button.active').attr('priority'), p, 'priority change in detail');
//TODO:断言位置切换
}
function assertDueTimeChange($r, t) {
var task = getTask($r);
//date assert需要改进
this[!t ? 'equal' : 'notEqual']($.trim($r.find('#dueTimeLabel').html()), '', 'dueTime change in row');
this[!t ? 'equal' : 'notEqual'](getTask($r).due(), null);
equal($el_wrapper_detail.find('#dueTime').val(), t, 'dueTime change in detail');
this[!t ? 'equal' : 'notEqual'](task.due(), null);
equal(task.$el_detail.find('#dueTime').val(), t, 'dueTime change in detail');
}
function appendTask() { $('.flag_appendTask:first').click(); }
function deleteTask() { $('.flag_deleteTask:first').click(); }
Expand All @@ -285,4 +293,7 @@ function runTests() {
$r.find('input').trigger(e);
return $r;
}

//恢复
UI_List_Common.prototype.detail_timer_enable = true;
}

0 comments on commit dfe1996

Please sign in to comment.