fix(tests): add test for bulk complete / cancellation of project

This commit is contained in:
Rushabh Mehta 2019-02-20 17:06:47 +05:30
parent 02a9ec33ed
commit b94c8b1c77
6 changed files with 47 additions and 23 deletions

View File

@ -23,7 +23,7 @@ class EmployeeOnboarding(EmployeeBoardingController):
continue
else:
task_status = frappe.db.get_value("Task", activity.task, "status")
if task_status not in ["Closed", "Cancelled"]:
if task_status not in ["Completed", "Cancelled"]:
frappe.throw(_("All the mandatory Task for employee creation hasn't been done yet."), IncompleteTaskError)
def on_submit(self):

View File

@ -39,7 +39,7 @@ class TestEmployeeOnboarding(unittest.TestCase):
# complete the task
project = frappe.get_doc('Project', onboarding.project)
project.tasks[0].status = 'Closed'
project.tasks[0].status = 'Completed'
project.save()
# make employee

View File

@ -95,8 +95,8 @@ frappe.ui.form.on("Project", {
set_status: function(frm, status) {
frappe.confirm(__('Set Project and all Tasks to status {0}?', [status.bold()]), () => {
frappe.xcall('erpnext.projects.doctype.project.project.set_project_status',
{project: frm.doc.name, status: status}).then((r) => { /* page will auto reload */ });
})
{project: frm.doc.name, status: status}).then(() => { /* page will auto reload */ });
});
},
tasks_refresh: function (frm) {

View File

@ -8,22 +8,16 @@ test_records = frappe.get_test_records('Project')
test_ignore = ["Sales Order"]
from erpnext.projects.doctype.project_template.test_project_template import get_project_template
from erpnext.projects.doctype.project.project import set_project_status
from frappe.utils import getdate
class TestProject(unittest.TestCase):
def test_project_with_template(self):
template = get_project_template()
frappe.db.sql('delete from tabTask where project = "Test Project with Template"')
frappe.delete_doc('Project', 'Test Project with Template')
# frappe.db.sql('delete from tabTask where project = "Test Project with Template"')
# frappe.delete_doc('Project', 'Test Project with Template')
project = frappe.get_doc(dict(
doctype = 'Project',
project_name = 'Test Project with Template',
status = 'Open',
project_template = template.name,
expected_start_date = '2019-01-01'
)).insert()
project = get_project('Test Project with Template')
project.load_tasks()
@ -37,3 +31,33 @@ class TestProject(unittest.TestCase):
task4 = project.tasks[3]
self.assertEqual(task4.title, 'Task 4')
self.assertEqual(getdate(task4.end_date), getdate('2019-01-06'))
def test_bulk_complete_and_cancel(self):
frappe.db.sql('delete from tabTask where project = "Test Project for Bulk Actions"')
frappe.delete_doc('Project', 'Test Project for Bulk Actions')
project = get_project('Test Project for Bulk Actions')
set_project_status(project.name, 'Completed')
# check all tasks are completed
self.assertTrue(all([d.status=='Completed' for d in
frappe.get_all('Task', ['name', 'status'], dict(project = project.name))]))
# check all tasks are cancelled
set_project_status(project.name, 'Cancelled')
self.assertTrue(all([d.status=='Cancelled' for d in
frappe.get_all('Task', ['name', 'status'], dict(project = project.name))]))
def get_project(name):
template = get_project_template()
project = frappe.get_doc(dict(
doctype = 'Project',
project_name = name,
status = 'Open',
project_template = template.name,
expected_start_date = '2019-01-01'
)).insert()
return project

View File

@ -83,11 +83,11 @@ class TestTask(unittest.TestCase):
# assignment should be
task.load_from_db()
task.status = "Closed"
task.status = "Completed"
task.save()
todo = get_owner_and_status()
self.assertEqual(todo.owner, "test@example.com")
self.assertEqual(todo.status, "Closed")
self.assertEqual(todo.status, "Completed")
def test_overdue(self):
task = create_task("Testing Overdue", add_days(nowdate(), -10), add_days(nowdate(), -5))

View File

@ -3,7 +3,7 @@ frappe.ready(function() {
$('.task-status-switch').on('click', function() {
var $btn = $(this);
if($btn.attr('data-status')==='Open') {
reload_items('closed', 'task', $btn);
reload_items('completed', 'task', $btn);
} else {
reload_items('open', 'task', $btn);
}
@ -13,7 +13,7 @@ frappe.ready(function() {
$('.issue-status-switch').on('click', function() {
var $btn = $(this);
if($btn.attr('data-status')==='Open') {
reload_items('closed', 'issue', $btn);
reload_items('completed', 'issue', $btn);
} else {
reload_items('open', 'issue', $btn);
}
@ -61,9 +61,9 @@ frappe.ready(function() {
// update status
if(item_status==='open') {
$btn.html(__('Show closed')).attr('data-status', 'Open');
$btn.html(__('Show Completed')).attr('data-status', 'Open');
} else {
$btn.html(__('Show open')).attr('data-status', 'Closed');
$btn.html(__('Show Open')).attr('data-status', 'Completed');
}
}
});
@ -72,8 +72,8 @@ frappe.ready(function() {
var more_items = function(item, item_status){
if(item_status) {
var item_status = $('.project-'+ item +'-section .btn-group .bold').hasClass('btn-closed-'+ item)
? 'closed' : 'open';
var item_status = $('.project-'+ item +'-section .btn-group .bold').hasClass('btn-completed-'+ item)
? 'completed' : 'open';
}
$.ajax({
method: "GET",