Skip to content

Commit

Permalink
Populate testcase expand area on click
Browse files Browse the repository at this point in the history
  • Loading branch information
RMadjev authored and atodorov committed Apr 29, 2020
1 parent 7a97ed0 commit 5be30ab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
27 changes: 20 additions & 7 deletions tcms/testplans/static/testplans/js/get.js
@@ -1,3 +1,5 @@
var expandedTestCaseIds = [];

$(document).ready(function() {
const testPlanId = $('#test_plan_pk').data('testplanPk');
const testCases = {
Expand Down Expand Up @@ -36,10 +38,10 @@ function drawTestCases(testCases, testPlanId, permissions) {
testCaseRowDocumentFragment = $('#test_case_row')[0].content;

if (Object.keys(testCases).length > 0) {
for (const testCaseId in testCases) {
for (const testCaseId in testCases) {
container.append(getTestCaseRowContent(testCaseRowDocumentFragment.cloneNode(true), testCases[testCaseId], permissions));
}
attachEvents(testPlanId, permissions);
attachEvents(testCases, testPlanId, permissions);
if (permissions['perm-change-testcase']) {
drawStatusAndPriority();
}
Expand All @@ -48,7 +50,6 @@ function drawTestCases(testCases, testPlanId, permissions) {
}
}


function getTestCaseRowContent(rowContent, testCase, permissions) {
var row = $(rowContent);

Expand Down Expand Up @@ -77,8 +78,6 @@ function getTestCaseRowContent(rowContent, testCase, permissions) {
);
automation_indication_element.removeClass(automated_class_to_remove);

getTestCaseExpandArea(row, testCase);

return row;
}

Expand Down Expand Up @@ -118,7 +117,7 @@ function getTestCaseExpandArea(row, testCase) {
});
}

function attachEvents(testPlanId, permissions) {
function attachEvents(testCases, testPlanId, permissions) {
if (permissions['perm-change-testcase']) {
// update default tester
$('.js-test-case-menu-tester').click(function(ev) {
Expand Down Expand Up @@ -162,8 +161,22 @@ function attachEvents(testPlanId, permissions) {
});
}

// get details and draw expand area only on expand
$('.js-testcase-row').click(function(ev) {
const testCaseId = getCaseIdFromEvent(ev);

// tc was expanded once, dom is ready
if (expandedTestCaseIds.indexOf(testCaseId) > -1) {
return;
}

const tcRow = $(ev.target).closest('.js-testcase-row');
expandedTestCaseIds.push(testCaseId);
getTestCaseExpandArea(tcRow, testCases[testCaseId]);
});

function getCaseIdFromEvent(ev) {
return $(ev.target).closest('.list-group-item').data('testcase-pk');
return $(ev.target).closest('.js-testcase-row').data('testcase-pk');
}
}

Expand Down
2 changes: 1 addition & 1 deletion tcms/testplans/templates/testplans/get.html
Expand Up @@ -113,7 +113,7 @@ <h2 class="card-pf-title">
</template>

<template id="test_case_row">
<div class="list-group-item" data-testcase-pk="">
<div class="list-group-item js-testcase-row" data-testcase-pk="">
<div class="list-group-item-header">
<div class="list-view-pf-main-info">
<div class="list-view-pf-left">
Expand Down

0 comments on commit 5be30ab

Please sign in to comment.