Skip to content

Commit

Permalink
split tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wsky committed Aug 9, 2012
1 parent dfe1996 commit 8741273
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 86 deletions.
162 changes: 93 additions & 69 deletions src/Cooper.Web/Scripts/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,35 @@

//cooper web ui auto tests
//amazing?
function runTests() {
var row_task = 'row_task';
var class_row_task = '.row_task';
var row_active = 'row_active';
var class_row_active = '.row_active';
var row_completed = 'row_completed';

var $el_wrapper_region = $('#todolist_wrapper');
var $el_wrapper_detail = $('#detail_wrapper');
var $el_cancel_delete = $('#cancel_delete');
var row_task = 'row_task';
var class_row_task = '.row_task';
var row_active = 'row_active';
var class_row_active = '.row_active';
var row_completed = 'row_completed';

var up = 38;
var down = 40;
var $el_wrapper_region = $('#todolist_wrapper');
var $el_wrapper_detail = $('#detail_wrapper');
var $el_cancel_delete = $('#cancel_delete');

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

///////////////////////////////////////////////////////////////////////////////
function runAll() {
test('init', function () {
ok(taskCount() > 0, 'cached_tasks init');
});
///////////////////////////////////////////////////////////////////////////////
//按钮区域

runMouseTests();
runShortcutsTests();
runDetailTests();
runTasklistTests();
}

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

test('append', function () {
var c = taskCount();
appendTask();
Expand Down Expand Up @@ -115,7 +121,15 @@ function runTests() {
$r.find('#subject').trigger(e2);
ok($r.hasClass(row_active) && getActives().length == 3, 'row shift+click and 3 actives');
});
//快捷键操作

UI_List_Common.prototype.detail_timer_enable = true;
}

//快捷键操作
function runShortcutsTests() {
//预置一些参数适合同步测试
UI_List_Common.prototype.detail_timer_enable = false;

test('up/down', function () {
focusRow(0);
var e = jQuery.Event('keydown'); e.keyCode = down;
Expand Down Expand Up @@ -179,6 +193,12 @@ function runTests() {
$el_wrapper_region.trigger(e);
assertIsCompleted($r, false);
});

UI_List_Common.prototype.detail_timer_enable = true;
}

function runDetailTests() {
UI_List_Common.prototype.detail_timer_enable = false;
///////////////////////////////////////////////////////////////////////////////
//详情区域
//complete
Expand Down Expand Up @@ -223,6 +243,10 @@ function runTests() {
var $e = $el_wrapper_detail.find('#dueTime').val('8/7/12').change();
assertDueTimeChange($r, '2012-8-7');
});
UI_List_Common.prototype.detail_timer_enable = true;
}

function runTasklistTests() {
///////////////////////////////////////////////////////////////////////////////
//任务表操作
test('add_tasklist', function () {
Expand All @@ -242,58 +266,58 @@ function runTests() {
});
}, 1000);
});
}

function assertAppend(c) {
equal(taskCount(), c + 1, 'add 1 task');
equal(getActives().length, 1, 'only the new task is focus');
equal(getTask(getActives().first()).id().indexOf('temp'), 0, 'new task id is "temp_*"');
}
function assertDelete(c) {
equal(taskCount(), c - 1, 'delete 1 task when backspace');
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(task.isCompleted(), b, 'task iscompleted change');
//detail
equal(task.$el_detail.find('#isCompleted').hasClass('active'), b);
}
function assertSubjectChange($r, v) {
var task = getTask($r);
equal(task.subject(), v, 'subject change');
equal($r.find('#subject').val(), v, 'subject change in row');
//detail
equal(task.$el_detail.find('#subject').val(), v, 'subject change in detail');
}
function assertPriorityChange($r, p) {
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'](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(); }
function getTask($r) { return UI_List_Common.prototype.getTask($r); }
function taskCount() { var i = 0; UI_List_Common.prototype.eachTask(function (t) { i++; }); return i; }
function getActives() { return $el_wrapper_region.find(class_row_active); }
function getTasks() { return $el_wrapper_region.find(class_row_task); }
function getRow(i) { return $el_wrapper_region.find(class_row_task).eq(i); }
function focusRow(i) {
var e = jQuery.Event('click');
var $r = $el_wrapper_region.find(class_row_task).eq(i);
$r.find('input').trigger(e);
return $r;
}

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


function assertAppend(c) {
equal(taskCount(), c + 1, 'add 1 task');
equal(getActives().length, 1, 'only the new task is focus');
equal(getTask(getActives().first()).id().indexOf('temp'), 0, 'new task id is "temp_*"');
}
function assertDelete(c) {
equal(taskCount(), c - 1, 'delete 1 task when backspace');
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(task.isCompleted(), b, 'task iscompleted change');
//detail
equal(task.$el_detail.find('#isCompleted').hasClass('active'), b);
}
function assertSubjectChange($r, v) {
var task = getTask($r);
equal(task.subject(), v, 'subject change');
equal($r.find('#subject').val(), v, 'subject change in row');
//detail
equal(task.$el_detail.find('#subject').val(), v, 'subject change in detail');
}
function assertPriorityChange($r, p) {
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'](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(); }
function getTask($r) { return UI_List_Common.prototype.getTask($r); }
function taskCount() { var i = 0; UI_List_Common.prototype.eachTask(function (t) { i++; }); return i; }
function getActives() { return $el_wrapper_region.find(class_row_active); }
function getTasks() { return $el_wrapper_region.find(class_row_task); }
function getRow(i) { return $el_wrapper_region.find(class_row_task).eq(i); }
function focusRow(i) {
var e = jQuery.Event('click');
var $r = $el_wrapper_region.find(class_row_task).eq(i);
$r.find('input').trigger(e);
return $r;
}
29 changes: 12 additions & 17 deletions src/Cooper.Web/Views/Shared/Settings.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<img src="@Url.Content("~/Content/images/laptop-small.png")" width="300px" />
<br />
@this.Lang().download_address:<input type="text" value="http://xyj.im" />

</div>
<div class="modal-footer">
</div>
Expand Down Expand Up @@ -55,7 +54,7 @@
Join us</h3>
</div>
<div class="modal-body">
<p style="line-height:25px">
<p style="line-height: 25px">
我们致力于构建开源技术产品/业务系统,<br />
目前主要关注于“流畅、便捷”的工作支持系统,
<br />
Expand All @@ -65,9 +64,7 @@
</p>
</div>
</div>

@{ Html.RenderPartial("Scripts"); }

<script type="text/javascript">
//输出运行时动态设置用于脚本使用
var sys_versionFlag = '@this.VersionFlag()';
Expand Down Expand Up @@ -101,7 +98,6 @@
$('#joinus').modal('show');
}
</script>

@if (!CodeSharp.Framework.SystemConfig.Settings.VersionFlag.Equals("Release"))
{
<script type="text/javascript">
Expand All @@ -115,25 +111,24 @@
DevToolBar[@CodeSharp.Framework.SystemConfig.Settings.VersionFlag] -
@if (HttpContext.Current.User != null && HttpContext.Current.User.Identity != null && HttpContext.Current.User.Identity.IsAuthenticated)
{
<code>Hi! AccountId=@HttpContext.Current.User.Identity.Name</code>
<code>Hi! #@HttpContext.Current.User.Identity.Name</code>
}
<code><a href="@Url.Action("Issues", "Home", null)" target="_blank" title="缺陷跟踪">
BugTrace</a> | <a href="https://github.com/codesharp/Cooper" target="_blank">OpenSource</a></code>
<code><a href="@Url.Action("Issues", "Home", null)" target="_blank" title="缺陷跟踪">BugTrace</a></code>
| <a href="@Url.Action("Index", "Per", null)">TaskPage</a> | <a href="@Url.Action("Mobile", "Per", null)">
Mobile Web</a> | <a href="@Url.Action("", "Account", null)">Account</a> | <a href="@Url.Action("Login", "Account", null)">
Login</a> | <a href="@Url.Action("Logout", "Account", null)">Logout</a>
| UI Auto Tests
<button type="button" class="btn btn-success" onclick="$('#qunit').show();runTests()"
style="width: 110px">
Run Tests Full</button>
Mobile</a> | <a href="@Url.Action("", "Account", null)">Account</a> | <a href="@Url.Action("Logout", "Account", null)">
Logout</a> | UI Auto Tests
<button type="button" class="btn" onclick="$('#qunit').show();runAll()">Full</button>
<button type="button" class="btn btn-primary" onclick="$('#qunit').show();runMouseTests()">mouse</button>
<button type="button" class="btn btn-info" onclick="$('#qunit').show();runShortcutsTests()">shortcuts</button>
<button type="button" class="btn btn-success" onclick="$('#qunit').show();runDetailTests()">detail</button>
<button type="button" class="btn btn-warning" onclick="$('#qunit').show();runTasklistTests()">tasklist</button>
<div id="qunit" style="display: none; margin-top: 20px">
</div>
</div>
<link href="../Content/jquery/css/qunit-1.9.0.css" rel="stylesheet" type="text/css" />
<script src="../Content/jquery/qunit-1.9.0.js" type="text/javascript"></script>
<script src="@Url.Content("~/scripts/tests.js")" type="text/javascript"></script>

@*@Html.IncludeAppfailOverlay()*@
@*@Html.IncludeAppfailOverlay()*@
}

@Html.Raw(this.Lang().web_analysis)
@Html.Raw(this.Lang().web_analysis)

0 comments on commit 8741273

Please sign in to comment.