From 9def326a3b82685db3a26ffe11ce99beeab01496 Mon Sep 17 00:00:00 2001 From: Anton Sankov Date: Wed, 3 Mar 2021 23:43:27 +0200 Subject: [PATCH 1/4] Render Individual test case health on test case page --- tcms/templates/include/tc_executions.html | 16 +++++++++- tcms/testcases/static/testcases/js/get.js | 38 +++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/tcms/templates/include/tc_executions.html b/tcms/templates/include/tc_executions.html index 6c82856e5b..7fb08da9f6 100644 --- a/tcms/templates/include/tc_executions.html +++ b/tcms/templates/include/tc_executions.html @@ -23,10 +23,24 @@

-
+
+
+
{% trans 'Completion rate' %}: +
+
+
+
+
+
{% trans 'Failure rate' %}: +
+
+
+
+
+
diff --git a/tcms/testcases/static/testcases/js/get.js b/tcms/testcases/static/testcases/js/get.js index 5dbee3187b..1f2b65c02f 100644 --- a/tcms/testcases/static/testcases/js/get.js +++ b/tcms/testcases/static/testcases/js/get.js @@ -210,6 +210,44 @@ $(document).ready(function () { }) }) + jsonRPC('Testing.individual_test_case_health', { case_id: case_id }, ress => { + const res = {} + let planId = 0 + ress.forEach(r => { + let positive = 0 + let negative = 0 + let allCount = 0 + if (r.status__weight > 0) { + positive++ + } else if (r.status__weight < 0) { + negative++ + } + allCount++ + + if (r.run__plan !== planId) { + planId = r.run__plan + res[planId] = { + completion_rate: allCount > 0 ? ((positive + negative) / allCount) : 0, + failure_rate: allCount > 0 ? (negative / allCount) : 0 + } + positive = 0 + negative = 0 + allCount = 0 + } + }) + + Object.entries(res).forEach(([runId, data]) => { + const executionRow = $(`#execution-for-plan-${runId}`) + executionRow.find('.completion-rate').html(data.completion_rate) + executionRow.find('.completion-rate-container .progress-bar-danger').css('width', `${(1 - data.completion_rate) * 100}%`) + executionRow.find('.completion-rate-container .progress-bar-success').css('width', `${(data.completion_rate) * 100}%`) + + executionRow.find('.failure-rate').html(data.failure_rate) + executionRow.find('.failure-rate-container .progress-bar-danger').css('width', `${(data.failure_rate) * 100}%`) + executionRow.find('.failure-rate-container .progress-bar-success').css('width', `${(1 - data.failure_rate) * 100}%`) + }) + }) + // bind add TP to TC widget initAddPlan(case_id, plans_table) From 78313c314cefc9640a4de93c28ff913fbee3a18d Mon Sep 17 00:00:00 2001 From: Anton Sankov Date: Sat, 11 Sep 2021 01:54:22 +0300 Subject: [PATCH 2/4] Fix calculation logic --- tcms/templates/include/tc_executions.html | 23 ++++++++------ tcms/testcases/static/testcases/js/get.js | 37 +++++++++++++++-------- 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/tcms/templates/include/tc_executions.html b/tcms/templates/include/tc_executions.html index 7fb08da9f6..419ce4ca00 100644 --- a/tcms/templates/include/tc_executions.html +++ b/tcms/templates/include/tc_executions.html @@ -28,23 +28,26 @@

TP-{{ execution.run.plan.pk }}: {{ execution.run.plan.name }}
-
{% trans 'Completion rate' %}: -
-
-
-
-
-
{% trans 'Failure rate' %}: -
-
-
+
{% trans 'Completion rate' %}: + +
+
+
+
+
{% trans 'Failure rate' %}: + +
+
+
+
+ {% endifchanged %}
diff --git a/tcms/testcases/static/testcases/js/get.js b/tcms/testcases/static/testcases/js/get.js index 1f2b65c02f..4a6d77fa81 100644 --- a/tcms/testcases/static/testcases/js/get.js +++ b/tcms/testcases/static/testcases/js/get.js @@ -213,10 +213,14 @@ $(document).ready(function () { jsonRPC('Testing.individual_test_case_health', { case_id: case_id }, ress => { const res = {} let planId = 0 + let positive = 0 + let negative = 0 + let allCount = 0 ress.forEach(r => { - let positive = 0 - let negative = 0 - let allCount = 0 + if (planId === 0) { + planId = r.run__plan + } + if (r.status__weight > 0) { positive++ } else if (r.status__weight < 0) { @@ -226,25 +230,34 @@ $(document).ready(function () { if (r.run__plan !== planId) { planId = r.run__plan + const completionRate = allCount > 0 ? ((positive + negative) / allCount) : 0 + const failureRate = allCount > 0 ? (negative / allCount) : 0 res[planId] = { - completion_rate: allCount > 0 ? ((positive + negative) / allCount) : 0, - failure_rate: allCount > 0 ? (negative / allCount) : 0 + completionRate: completionRate.toFixed(2), + failureRate: failureRate.toFixed(2) } positive = 0 negative = 0 allCount = 0 } }) + // add the last entry + const completionRate = allCount > 0 ? ((positive + negative) / allCount) : 0 + const failureRate = allCount > 0 ? (negative / allCount) : 0 + res[planId] = { + completionRate: completionRate.toFixed(2), + failureRate: failureRate.toFixed(2) + } Object.entries(res).forEach(([runId, data]) => { const executionRow = $(`#execution-for-plan-${runId}`) - executionRow.find('.completion-rate').html(data.completion_rate) - executionRow.find('.completion-rate-container .progress-bar-danger').css('width', `${(1 - data.completion_rate) * 100}%`) - executionRow.find('.completion-rate-container .progress-bar-success').css('width', `${(data.completion_rate) * 100}%`) + executionRow.find('.completion-rate').html(data.completionRate) + executionRow.find('.completion-rate-container .progress-bar-danger').css('width', `${(1 - data.completionRate) * 100}%`) + executionRow.find('.completion-rate-container .progress-bar-success').css('width', `${(data.completionRate) * 100}%`) - executionRow.find('.failure-rate').html(data.failure_rate) - executionRow.find('.failure-rate-container .progress-bar-danger').css('width', `${(data.failure_rate) * 100}%`) - executionRow.find('.failure-rate-container .progress-bar-success').css('width', `${(1 - data.failure_rate) * 100}%`) + executionRow.find('.failure-rate').html(data.failureRate) + executionRow.find('.failure-rate-container .progress-bar-danger').css('width', `${(data.failureRate) * 100}%`) + executionRow.find('.failure-rate-container .progress-bar-success').css('width', `${(1 - data.failureRate) * 100}%`) }) }) @@ -259,4 +272,4 @@ $(document).ready(function () { // executions treeview treeViewBind() -}) +}) \ No newline at end of file From f94cd6a71ec0416c97b99ed5c0a1aa804e919022 Mon Sep 17 00:00:00 2001 From: Anton Sankov Date: Sat, 18 Sep 2021 17:11:47 +0300 Subject: [PATCH 3/4] remove obsolete div tag --- tcms/templates/include/tc_executions.html | 1 - tcms/testcases/static/testcases/js/get.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/tcms/templates/include/tc_executions.html b/tcms/templates/include/tc_executions.html index 419ce4ca00..14df01c00e 100644 --- a/tcms/templates/include/tc_executions.html +++ b/tcms/templates/include/tc_executions.html @@ -47,7 +47,6 @@

- {% endifchanged %}
diff --git a/tcms/testcases/static/testcases/js/get.js b/tcms/testcases/static/testcases/js/get.js index 4a6d77fa81..bfb685a804 100644 --- a/tcms/testcases/static/testcases/js/get.js +++ b/tcms/testcases/static/testcases/js/get.js @@ -272,4 +272,4 @@ $(document).ready(function () { // executions treeview treeViewBind() -}) \ No newline at end of file +}) From 24fe92626dee8b73c04100ca3262fe8d69b8291c Mon Sep 17 00:00:00 2001 From: Anton Sankov Date: Wed, 22 Sep 2021 20:35:53 +0300 Subject: [PATCH 4/4] Simplify widget by removing completion rate metric --- tcms/templates/include/tc_executions.html | 11 ++------ tcms/testcases/static/testcases/js/get.js | 31 ++++++++++----------- tcms/testcases/templates/testcases/get.html | 1 + 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/tcms/templates/include/tc_executions.html b/tcms/templates/include/tc_executions.html index 14df01c00e..39902f24f4 100644 --- a/tcms/templates/include/tc_executions.html +++ b/tcms/templates/include/tc_executions.html @@ -28,16 +28,9 @@

TP-{{ execution.run.plan.pk }}: {{ execution.run.plan.name }}

-
{% trans 'Completion rate' %}: - -
-
-
-
-
-
{% trans 'Failure rate' %}: +
-
+
diff --git a/tcms/testcases/static/testcases/js/get.js b/tcms/testcases/static/testcases/js/get.js index bfb685a804..258754e71a 100644 --- a/tcms/testcases/static/testcases/js/get.js +++ b/tcms/testcases/static/testcases/js/get.js @@ -90,6 +90,8 @@ $(document).ready(function () { const perm_remove_component = $('#test_case_pk').data('perm-remove-component') === 'True' const perm_remove_plan = $('#test_case_pk').data('perm-remove-plan') === 'True' const perm_remove_bug = $('#test_case_pk').data('perm-remove-bug') === 'True' + const testCaseHealthMessageTemplate = $('#test_case_pk').data('individual-test-case-health-msg') + // bind everything in tags table tagsCard('TestCase', case_id, { case: case_id }, perm_remove_tag) @@ -213,7 +215,6 @@ $(document).ready(function () { jsonRPC('Testing.individual_test_case_health', { case_id: case_id }, ress => { const res = {} let planId = 0 - let positive = 0 let negative = 0 let allCount = 0 ress.forEach(r => { @@ -221,41 +222,39 @@ $(document).ready(function () { planId = r.run__plan } - if (r.status__weight > 0) { - positive++ - } else if (r.status__weight < 0) { + if (r.status__weight < 0) { negative++ } allCount++ if (r.run__plan !== planId) { planId = r.run__plan - const completionRate = allCount > 0 ? ((positive + negative) / allCount) : 0 const failureRate = allCount > 0 ? (negative / allCount) : 0 res[planId] = { - completionRate: completionRate.toFixed(2), - failureRate: failureRate.toFixed(2) + negativeCount: negative, + allCount: allCount, + failureRate: failureRate } - positive = 0 negative = 0 allCount = 0 } }) // add the last entry - const completionRate = allCount > 0 ? ((positive + negative) / allCount) : 0 const failureRate = allCount > 0 ? (negative / allCount) : 0 res[planId] = { - completionRate: completionRate.toFixed(2), - failureRate: failureRate.toFixed(2) + negativeCount: negative, + allCount: allCount, + failureRate: failureRate } Object.entries(res).forEach(([runId, data]) => { - const executionRow = $(`#execution-for-plan-${runId}`) - executionRow.find('.completion-rate').html(data.completionRate) - executionRow.find('.completion-rate-container .progress-bar-danger').css('width', `${(1 - data.completionRate) * 100}%`) - executionRow.find('.completion-rate-container .progress-bar-success').css('width', `${(data.completionRate) * 100}%`) + const stabilityPercent = (1-data.failureRate)*100 + const msg = testCaseHealthMessageTemplate.replace("%s", data.negativeCount) + .replace("%s", data.allCount) + .replace("%s", stabilityPercent.toFixed(2)) - executionRow.find('.failure-rate').html(data.failureRate) + const executionRow = $(`#execution-for-plan-${runId}`) + executionRow.find('.failure-rate').html(msg) executionRow.find('.failure-rate-container .progress-bar-danger').css('width', `${(data.failureRate) * 100}%`) executionRow.find('.failure-rate-container .progress-bar-success').css('width', `${(1 - data.failureRate) * 100}%`) }) diff --git a/tcms/testcases/templates/testcases/get.html b/tcms/testcases/templates/testcases/get.html index 968ad29986..5653c770c0 100644 --- a/tcms/testcases/templates/testcases/get.html +++ b/tcms/testcases/templates/testcases/get.html @@ -17,6 +17,7 @@

data-perm-remove-component="{{ perms.testcases.delete_testcasecomponent }}" data-perm-remove-plan="{{ perms.testcases.delete_testcaseplan }}" data-perm-remove-bug="{{ perms.testcases.delete_bug }}" + data-individual-test-case-health-msg="{% trans 'Failed %s times in the last %s run. Stability: %s %' %}" >TC-{{ object.pk }}: {{ object.summary }}