Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add link to Test Execution #1842

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/source/modules/tcms.core.contrib.linkreference.forms.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
tcms.core.contrib.linkreference.forms module
============================================

.. automodule:: tcms.core.contrib.linkreference.forms
:members:
:undoc-members:
:show-inheritance:
1 change: 1 addition & 0 deletions docs/source/modules/tcms.core.contrib.linkreference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ Submodules
.. toctree::
:maxdepth: 4

tcms.core.contrib.linkreference.forms
tcms.core.contrib.linkreference.models
9 changes: 9 additions & 0 deletions tcms/core/contrib/linkreference/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django import forms

from tcms.core.contrib.linkreference.models import LinkReference


class LinkReferenceForm(forms.ModelForm):
class Meta:
model = LinkReference
exclude = ['created_on'] # pylint: disable=modelform-uses-exclude
1 change: 1 addition & 0 deletions tcms/rpc/api/testexecution.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def add_link(values, update_tracker=False, **kwargs):
tracker = tracker_from_url(link.url, request)

if (link.is_defect and
tracker is not None and
update_tracker and
not tracker.is_adding_testcase_to_issue_disabled()) or \
isinstance(tracker, KiwiTCMS):
Expand Down
62 changes: 59 additions & 3 deletions tcms/testruns/static/testruns/js/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,17 @@ function renderAdditionalInformation(testExecutions, testExecutionCaseIds) {
isAutomatedElement.addClass(isAutomatedIcon)
isAutomatedElement.attr('title', isAutomatedAttr)

jsonRPC('TestExecution.get_links', { 'execution_id': testExecution.id, 'is_defect': true }, bugs => {
listGroupItem.find('.test-execution-bugs-count').html(bugs.length)
jsonRPC('TestExecution.get_links', { 'execution_id': testExecution.id }, links => {
const bugCount = links.filter(link => link.is_defect).length;
listGroupItem.find('.test-execution-bugs-count').html(bugCount)

listGroupItem.find('.add-link-button').click(() => addLinkToExecution(testExecution))

const ul = listGroupItem.find('.test-execution-hyperlinks')
links.forEach(link => ul.append(renderLink(link)))
})
})
})

}

function renderTestExecutionRow(template, testExecution, testExecutionStatus) {
Expand Down Expand Up @@ -210,3 +215,54 @@ function fileBugFromExecution(run_id, title_container, container, case_id, execu

dialog.show();
}

function addLinkToExecution(testExecution) {

// remove all previous event handlers
$('.add-hyperlink-form').off('submit')

// this handler must be here, because if we bind it when the page is loaded.
// we have no way of knowing for what execution ID the form is submitted for.
$('.add-hyperlink-form').submit(() => {
const url = $('.add-hyperlink-form #id_url').val()
const name = $('.add-hyperlink-form #id_name').val()
const isDefect = $('.add-hyperlink-form #defectCheckbox').is(':checked')
const updateTracker = true

jsonRPC('TestExecution.add_link', [{
execution_id: testExecution.id,
url: url,
name: name,
is_defect: isDefect,
}, updateTracker], link => {
const ul = $(`.test-execution-${testExecution.id} .test-execution-hyperlinks`)
ul.append(renderLink(link))

// clean the values
$('.add-hyperlink-form #id_url').val('')
$('.add-hyperlink-form #id_name').val('')
$('.add-hyperlink-form #defectCheckbox').bootstrapSwitch('state', false)
$('.add-hyperlink-form #autoUpdateCheckbox').bootstrapSwitch('state', false)

// close the modal
$('#add-link-modal button.close').click()
})

return false;
})


return true; // so that the modal is opened
}

function renderLink(link) {
const linkEntryTemplate = $('#link-entry')[0].content
const template = $(linkEntryTemplate.cloneNode(true))
if (link.is_defect) {
template.find('.link-icon').addClass('fa fa-bug')
}

template.find('.link-url').html(link.name || link.url)

return template
}
asankov marked this conversation as resolved.
Show resolved Hide resolved
atodorov marked this conversation as resolved.
Show resolved Hide resolved
56 changes: 55 additions & 1 deletion tcms/testruns/templates/testruns/get.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,17 @@ <h5><span class="test-executions-count"></span> Results</h5>
<div class="list-view-pf-checkbox" style="margin-top: 0; margin-bottom: 0">
<input type="checkbox">
</div>
<div class="list-view-pf-actions" style="margin-top: 0; margin-bottom: 0;">
<div class="dropdown pull-right dropdown-kebab-pf">
<button class="btn btn-link dropdown-toggle" type="button" id="dropdownKebabRight9"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<span class="fa fa-ellipsis-v"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownKebabRight9">
<li><a href="#" class="add-link-button" data-toggle="modal" data-target="#add-link-modal">{% trans 'Add hyperlink' %}</a></li>
</ul>
</div>
</div>
<div class="list-view-pf-body">
<div class="list-view-pf-description" style="flex: 1 0 30%;">
<div class="list-group-item-text">
Expand Down Expand Up @@ -240,8 +251,12 @@ <h5><span class="test-executions-count"></span> Results</h5>
<p class="test-execution-notes">
<strong>{% trans 'Notes' %}:</strong>
</p>
<strong>{% trans "Bugs and hyperlinks" %}: </strong>
<div>
{% comment %} TODO: bugs come here {% endcomment %}
<ul class="test-execution-hyperlinks"></ul>
<template id="link-entry">
<li><span class="link-icon"></span><a class="link-url" href="${link.url}">${link.name || link.url}</a></li>
</template>
</div>
</div>
</div>
Expand All @@ -262,6 +277,45 @@ <h5><span class="test-executions-count"></span> Results</h5>
</div> <!-- /row -->
</div>

<div class="modal fade" id="add-link-modal" tabindex="-1" role="dialog" aria-labelledby="add-hyperlink-modal-title" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true" aria-label="Close">
<span class="pficon pficon-close"></span>
</button>
<h4 class="modal-title" id="add-hyperlink-modal-title">{% trans "Add hyperlink" %}</h4>
</div>
<form class="form-horizontal add-hyperlink-form">
<div class="modal-body">
<div class="form-group">
<label class="col-sm-3 control-label" for="{{ link_form.url.id_for_label }}">{% trans "URL" %}</label>
<div class="col-sm-9">
<input type="url" name="{{ link_form.url.name }}" maxlength="{{ link_form.url.field.max_length }}" {% if link_form.url.field.required %}required{% endif %} id="{{ link_form.url.id_for_label }}" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="{{ link_form.name.id_for_label }}">{% trans "Name" %}</label>
<div class="col-sm-9">
<input type="text" name="{{ link_form.name.name }}" maxlength="{{ link_form.name.field.max_length }}" {% if link_form.name.field.required %}required{% endif %} id="{{ link_form.name.id_for_label }}" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-md-3 col-lg-3 col-sm-3 control-label" for="defectCheckbox">{% trans "Is a defect" %}</label>
<div class="col-md-3 col-lg-3">
<input class="bootstrap-switch" type="checkbox" id="defectCheckbox" data-on-text="{% trans 'Yes' %}" data-off-text="{% trans 'No' %}"/>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">{% trans "Cancel" %}</button>
<button type="submit" class="btn btn-primary add-hyperlink-button">{% trans "Save" %}</button>
</div>
</form>
</div>
</div>
</div>

<script src="{% static 'typeahead.js/dist/typeahead.jquery.min.js' %}"></script>
<script src="{% static 'bootstrap-switch/dist/js/bootstrap-switch.min.js' %}"></script>
<script src="{% static 'moment/min/moment.min.js' %}"></script>
Expand Down
2 changes: 2 additions & 0 deletions tcms/testruns/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from tcms.testplans.models import TestPlan
from tcms.testruns.forms import BaseRunForm, NewRunForm, SearchRunForm
from tcms.testruns.models import TestExecutionStatus, TestRun
from tcms.core.contrib.linkreference.forms import LinkReferenceForm

User = get_user_model() # pylint: disable=invalid-name

Expand Down Expand Up @@ -134,6 +135,7 @@ class GetTestRunView(DetailView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['execution_statuses'] = TestExecutionStatus.objects.order_by('-weight', 'name')
context['link_form'] = LinkReferenceForm()
return context

def render_to_response(self, context, **response_kwargs):
Expand Down