Skip to content

Commit

Permalink
Remove old templates and unused code around them
Browse files Browse the repository at this point in the history
- remove all legacy templates around the TestCase view page
- remove now unused JavaScript, lots of functions around
  tabs and expanding content
- remove backend views which were only used via AJAX calls
  from the removed templates, Refs #18
- remove/update tests, in particular the new view renders
  only TestPlans which have a Test Run executed, including the
  current TestCase. Other TestPlans which contain the current
  TestCase (but may not yet have test runs) are loaded via RPC
  for which we can't test right now.
  • Loading branch information
atodorov committed Jan 15, 2019
1 parent bc9c538 commit 22c10b9
Show file tree
Hide file tree
Showing 16 changed files with 1 addition and 1,281 deletions.
2 changes: 0 additions & 2 deletions tcms/static/js/tcms_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ var default_messages = {
'last_case_run': 'It is the last case run',
'invalid_bug_id': 'Please input a valid bug id!',
'no_bugs_specified': 'Please specify bug ID',
'no_plan_specified': 'Please specify one plan at least.'
},
'confirm': {
'change_case_status': 'Are you sure you want to change the status?',
Expand Down Expand Up @@ -90,7 +89,6 @@ var default_messages = {
logout: '/accounts/logout/',

case_details: '/case/$id/',
case_plan: '/case/$id/plan/',
case_run_bug: '/runs/$id/bug/',
search_case: '/cases/',
},
Expand Down
326 changes: 0 additions & 326 deletions tcms/static/js/testcase_actions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Nitrate.TestCases = {};
Nitrate.TestCases.Details = {};
Nitrate.TestCases.Edit = {};
Nitrate.TestCases.Clone = {};

Expand All @@ -25,124 +24,6 @@ Nitrate.TestCases.Clone = {};
window.Nitrate.TestCases = TestCases;
}());

function addComponent(component_name) {
jsonRPC('Component.filter',
{
'name': component_name,
'product_id': Nitrate.TestCases.Instance.product_id
}, function(data){
jsonRPC('TestCase.add_component',
[Nitrate.TestCases.Instance.pk, data[0].id],
function(data) {
window.location.reload();
}
);
}
);
}

function removeComponent(case_id, component_id) {
if (! window.confirm(default_messages.confirm.remove_case_component)) {
return false;
}

jsonRPC('TestCase.remove_component', [case_id, component_id], function(data){
$('#row-' + component_id).hide();
});
}

Nitrate.TestCases.Details.on_load = function() {
var case_id = Nitrate.TestCases.Instance.pk;
constructTagZone(jQ('#tag')[0], { 'case': case_id });
constructPlanCaseZone(jQ('#plan')[0], case_id);
jQ('li.tab a').bind('click', function(i) {
jQ('div.tab_list').hide();
jQ('li.tab').removeClass('tab_focus');
jQ(this).parent().addClass('tab_focus');
jQ('#' + this.title).show();
});

if (window.location.hash) {
fireEvent(jQ('a[href=\"' + window.location.hash + '\"]')[0], 'click');
}

// configure autocomplete for components
jQ('#id_components').autocomplete({
'source': function(request, response) {
jsonRPC('Component.filter',
{
'name__startswith': request.term,
'product_id': Nitrate.TestCases.Instance.product_id,
}, function(data) {
var processedData = [];
data.forEach(function(element) {
processedData.push(element.name);
});
response(processedData);
}
);
},
'appendTo': '#id_components_autocomplete'
});

$('#js-add-component').bind('click', function() {
addComponent($('#id_components').val());
});

jQ('.link_remove_component').bind('click', function(e) {
removeComponent(Nitrate.TestCases.Instance.pk,
jQ('input[name="component"]')[jQ('.link_remove_component').index(this)].value);
});

var toggle_case_run = function(e) {
var c = jQ(this).parent(); // Container
var c_container = c.next(); // Content Containers
var case_id = c.find('input[name="case"]')[0].value;
var case_run_id = c.find('input[name="case_run"]')[0].value;
// FIXME: case_text_version is not used in the backend to show caserun
// information, notes, logs, and comments.
var case_text_version = c.find('input[name="case_text_version"]')[0].value;
var type = 'case_case_run';
toggleSimpleCaseRunPane({
caserunRowContainer: c,
expandPaneContainer: c_container,
caseId: case_id,
caserunId: case_run_id
});
};

var toggle_case_runs_by_plan = function(e) {
var c = jQ(this).parent();
var case_id = c.find('input').first().val();
var params = {
'type' : 'case_run_list',
'container': c[0],
'c_container': c.next()[0],
'case_id': case_id,
'case_run_plan_id': c[0].id
};
var callback = function(e) {
jQ('#table_case_runs_by_plan .expandable').bind('click', toggle_case_run);
};
toggleCaseRunsByPlan(params, callback);
};

jQ('.plan_expandable').bind('click', toggle_case_runs_by_plan);

jQ('.js-remove-button').bind('click', function(event) {
var params = jQ(event.target).data('params');
removeCaseBug(params.id, params.caseId, params.caseRunId);
});

jQ('.js-add-bug').bind('click', function(event) {
addCaseBug(jQ('#id_case_bug_form')[0]);
});

jQ('#id_bugs').bind('keydown', function(event) {
addCaseBugViaEnterKey(jQ('#id_case_bug_form')[0], event);
});
};

function configure_product_on_load() {
$('#id_product').change(function() {
$('#id_category').find('option').remove();
Expand Down Expand Up @@ -232,29 +113,6 @@ function toggleExpandArrow(options) {
}


/*
* Toggle simple caserun pane in Case Runs tab in case page.
*/
function toggleSimpleCaseRunPane(options) {
var container = options.caserunRowContainer;
var content_container = options.expandPaneContainer;
var caseId = options.caseId;
var caserunId = options.caserunId;

content_container.toggle();

if (container.next().find('.ajax_loading').length) {
var url = '/case/' + caseId + '/caserun-simple-pane/';
var data = {case_run_id: caserunId};

jQ.get(url, data, function(data, textStatus) {
content_container.html(data);
},'html');
}

toggleExpandArrow({ caseRowContainer: container, expandPaneContainer: content_container });
}

function toggleTestCaseContents(template_type, container, content_container, object_pk, case_text_version, case_run_id, callback) {
if (typeof container === 'string') {
var container = jQ('#' + container)[0];
Expand Down Expand Up @@ -367,136 +225,6 @@ function blindupAllCases(element) {
}
}

function addCaseBug(form, callback) {
var addBugInfo = Nitrate.Utils.formSerialize(form);
addBugInfo.bug_validation_regexp = jQ('select[name="bug_system"] option:selected').data('validation-regexp');
addBugInfo.bug_id = addBugInfo.bug_id.trim();

if (!addBugInfo.bug_id.length) {
// No bug ID input, no any response is required
return false;
} else if (!validateIssueID(addBugInfo.bug_validation_regexp, addBugInfo.bug_id)) {
return false;
}

var complete = function(t) {
jQ('.js-add-bug').bind('click', function(event) {
addCaseBug(jQ('#id_case_bug_form')[0]);
});
jQ('#id_bugs').bind('keydown', function(event) {
addCaseBugViaEnterKey(jQ('#id_case_bug_form')[0], event);
});
jQ('.js-remove-button').bind('click', function(event) {
var params = jQ(event.target).data('params');
removeCaseBug(params.id, params.caseId, params.caseRunId);
});
if (jQ('#response').length) {
window.alert(jQ('#response').html());
return false;
}

if (callback) {
callback();
}
jQ('#case_bug_count').text(jQ('table#bugs').attr('count'));
};

jQ.ajax({
'url': form.action,
'type': form.method,
'data': addBugInfo,
'success': function (data, textStatus, jqXHR) {
jQ('#bug_list').html(data);
},
'complete': function () {
complete();
}
});
}

function constructPlanCaseZone(container, case_id, parameters) {
var complete = function(t) {
jQ('#id_plan_form').bind('submit', function(e) {
e.stopPropagation();
e.preventDefault();

var callback = function(e) {
e.stopPropagation();
e.preventDefault();
var plan_ids = Nitrate.Utils.formSerialize(this)['plan_id'];
if (!plan_ids) {
window.alert(default_messages.alert.no_plan_specified);
return false;
}

var p = { a: 'add', plan_id: plan_ids };
constructPlanCaseZone(container, case_id, p);
clearDialog();
jQ('#plan_count').text(jQ('table#testplans_table').attr('count'));
};

var p = Nitrate.Utils.formSerialize(this);
if (!p.pk__in) {
window.alert(default_messages.alert.no_plan_specified);
return false;
}

var action_url = Nitrate.http.URLConf.reverse({ name: 'case_plan', arguments: {id: case_id} });
previewPlan(p, action_url, callback);
});
if (jQ('#testplans_table td a').length) {
jQ('#testplans_table').DataTable({
"bFilter": false,
"bLengthChange": false,
"bPaginate": false,
"bInfo": false,
"bAutoWidth": false,
"aaSorting": [[ 0, "desc" ]],
"aoColumns": [
null,
{"sType": "html"},
{"sType": "html"},
{"sType": "html"},
null,
{"bSortable": false}
]
});
}

jQ('.js-remove-plan').bind('click', function() {
var params = jQ(this).data('params');
removePlanFromCase(jQ('#testplans_table_wrapper')[0], params[0], params[1]);
});

};

var url = Nitrate.http.URLConf.reverse({ name: 'case_plan', arguments: {id: case_id} });

jQ.ajax({
'url': url,
'type': 'GET',
'data': parameters,
'traditional': true,
'success': function (data, textStatus, jqXHR) {
jQ(container).html(data);
},
'complete': function (jqXHR, textStatus, errorThrown) {
complete();
}
});
}

function removePlanFromCase(container, plan_id, case_id) {
var c = window.confirm('Are you sure to remove the case from this plan?');
if (!c) {
return false;
}
var parameters = { a: 'remove', plan_id: plan_id };
constructPlanCaseZone(container, case_id, parameters);
jQ('#plan_count').text(jQ('table#testplans_table').attr('count'));
}


/*
* Serialize selected cases' Ids.
*
Expand Down Expand Up @@ -608,57 +336,3 @@ function toggleDiv(link, divId) {
link.html(hide);
}
}

function addCaseBugViaEnterKey(element, e) {
if (e.keyCode == 13) {
addCaseBug(element);
}
}

function toggleCaseRunsByPlan(params, callback) {
var container = params.container;
var content_container = params.c_container;
var case_run_plan_id = params.case_run_plan_id;
var case_id = params.case_id;
if (typeof container === 'string') {
container = jQ('#' + container);
} else {
container = jQ(container);
}

if(typeof content_container === 'string') {
content_container = jQ('#' + content_container);
} else {
content_container = jQ(content_container);
}

content_container.toggle();

if (jQ('#id_loading_' + case_run_plan_id).length) {
var url = '/case/' + case_id + '/caserun-list-pane/';
var parameters = { plan_id: case_run_plan_id };

jQ.ajax({
'url': url,
'type': 'GET',
'data': parameters,
'success': function (data, textStatus, jqXHR) {
content_container.html(data);
},
'error': function (jqXHR, textStatus, errorThrown) {
html_failure();
},
'complete': function() {
callback();
}
});

}

var blind_icon = container.find('img').first();
if (content_container.is(':hidden')) {
blind_icon.removeClass('collapse').addClass('expand').attr('src', '/static/images/t1.gif');
} else {
blind_icon.removeClass('expand').addClass('collapse').attr('src', '/static/images/t2.gif');
}
}
2 changes: 0 additions & 2 deletions tcms/static/style/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -708,8 +708,6 @@ ul.data_content_title li{ display:inline-block; margin-left:3px;}
.list .hide li{ margin-left:12px;}
.list .hide li td{border:0px; padding:0 4px 0 0; line-height:18px;}
.list .right_panel{ border:1px solid #ccc; background:#fff; vertical-align:top; padding:10px;}
.list .listGroupBlue{background:#C2DFFF; padding:0px 5px; color:#000000;}


#sort{ margin:2px 0px; color:#fff; }
#sort a{ color:#fff; }
Expand Down
Loading

0 comments on commit 22c10b9

Please sign in to comment.