Skip to content

Commit

Permalink
Refresh execution row after reporting a bug
Browse files Browse the repository at this point in the history
Only add classes on `div.list-group-item`

`test-execution-{id}` and `test-execution-case-{id}` classes.

Otherwise this classes got added on an
`li` element in the attachments group and messed up our selecting logic

Closes #479
  • Loading branch information
asankov authored and atodorov committed Dec 1, 2020
1 parent 3b4bfc0 commit 9b551f5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
46 changes: 32 additions & 14 deletions tcms/testruns/static/testruns/js/get.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
let testExecutionStatuses = {}

$(document).ready(() => {

$('.bootstrap-switch').bootstrapSwitch();
Expand Down Expand Up @@ -50,9 +52,10 @@ $(document).ready(() => {
tagsCard('TestRun', testRunId, { run: testRunId }, permRemoveTag);

jsonRPC('TestExecutionStatus.filter', {}, executionStatuses => {
testExecutionStatuses = executionStatuses
jsonRPC('TestExecution.filter', { 'run_id': testRunId }, testExecutions => {
drawPercentBar(testExecutions, executionStatuses)
renderTestExecutions(testExecutions, executionStatuses)
renderTestExecutions(testExecutions)
})
})

Expand Down Expand Up @@ -152,18 +155,14 @@ function renderCountPerStatusList(statusCount) {
}
}

function renderTestExecutions(testExecutions, executionStatuses) {
function renderTestExecutions(testExecutions) {
const container = $('#test-executions-container')
const testExecutionRowTemplate = $('#test-execution-row')[0].content

const testCaseIds = []
testExecutions.forEach(testExecution => {
testCaseIds.push(testExecution.case_id)

const executionStatus = executionStatuses.find(status => status.id === testExecution.status_id)
const template = $(testExecutionRowTemplate.cloneNode(true))

container.append(renderTestExecutionRow(template, testExecution, executionStatus))
container.append(renderTestExecutionRow(testExecution))
})

treeViewBind();
Expand All @@ -173,6 +172,10 @@ function renderTestExecutions(testExecutions, executionStatuses) {
function renderAdditionalInformation(testExecutions, testExecutionCaseIds) {
$('.test-executions-count').html(testExecutions.length);

renderTestCaseInformation(testExecutions, testExecutionCaseIds)
}

function renderTestCaseInformation(testExecutions, testExecutionCaseIds) {
jsonRPC('TestCase.filter', { 'id__in': testExecutionCaseIds }, testCases => {
testExecutions.forEach(testExecution => {
const testCase = testCases.find(testCase => testCase.id === testExecution.case_id)
Expand Down Expand Up @@ -201,7 +204,6 @@ function renderAdditionalInformation(testExecutions, testExecutionCaseIds) {
})

jsonRPC('TestCase.list_attachments', [testCase.id], attachments => {

const ul = listGroupItem.find(`.test-case-attachments`)

if (!attachments.length) {
Expand All @@ -222,19 +224,25 @@ function renderAdditionalInformation(testExecutions, testExecutionCaseIds) {
})
})
})

}

function renderTestExecutionRow(template, testExecution, testExecutionStatus) {
function renderTestExecutionRow(testExecution) {
const testExecutionRowTemplate = $('#test-execution-row')[0].content
const template = $(testExecutionRowTemplate.cloneNode(true))

template.find('.test-execution-checkbox').data('test-execution-id', testExecution.id)
template.find('.test-execution-checkbox').data('test-execution-case-id', testExecution.case_id)
template.find('.list-group-item').addClass(`test-execution-${testExecution.id}`)
template.find('.list-group-item').addClass(`test-execution-case-${testExecution.case_id}`)
template.find('.test-execution-element').addClass(`test-execution-${testExecution.id}`)
template.find('.test-execution-element').addClass(`test-execution-case-${testExecution.case_id}`)
template.find('.test-execution-info').html(`TE-${testExecution.id}`)
template.find('.test-execution-info-link').html(testExecution.case)
template.find('.test-execution-info-link').attr('href', `/case/${testExecution.case_id}/`)
template.find('.test-execution-tester').html(testExecution.tested_by || '-')
template.find('.test-execution-asignee').html(testExecution.assignee || '-')

const testExecutionStatus = testExecutionStatuses.find(status => status.id === testExecution.status_id)

template.find('.test-execution-status-icon').addClass(testExecutionStatus.icon).css('color', testExecutionStatus.color)
template.find('.test-execution-status-name').html(testExecutionStatus.name).css('color', testExecutionStatus.color)

Expand Down Expand Up @@ -291,12 +299,22 @@ function fileBugFromExecution(execution) {
const trackerId = $('.one-click-bug-report-form #id-issue-tracker').val()
jsonRPC('Bug.report', [execution.id, trackerId], result => {

// close the modal
$('#one-click-bug-report-modal button.close').click()

if (result.rc !== 0) {
alert(result.response)
return
}

$(`.test-execution-${execution.id}`).replaceWith(renderTestExecutionRow(execution))

treeViewBind();
renderTestCaseInformation([execution], [execution.case_id])

// unescape b/c Issue #1533
const targetUrl = result.response.replace(/&/g, '&')
window.open(targetUrl, '_blank')

// close the modal
$('#one-click-bug-report-modal button.close').click()
})
return false
})
Expand Down
2 changes: 1 addition & 1 deletion tcms/testruns/templates/testruns/get.html
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ <h5><span class="test-executions-count"></span> Results</h5>
<div class="card-pf-body">
<div id="test-executions-container" class="list-group tree-list-view-pf">
<template id="test-execution-row">
<div class="list-group-item">
<div class="list-group-item test-execution-element">
<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 9b551f5

Please sign in to comment.