From b8b01928d3f2d26b92d5d9a39c6c17299566d0ba Mon Sep 17 00:00:00 2001 From: Utkarsh Yadav Date: Thu, 27 Jul 2017 11:49:10 +0530 Subject: [PATCH] [ui test] employee attendance tool and attendance in HR (#10112) * added test for attendance tool * added test for attendance * minor changes * minor changes * path added in tests.txt * codacy fixes --- .../hr/doctype/attendance/test_attendance.js | 41 +++++++++++++++++++ erpnext/hr/doctype/employee/test_employee.js | 1 + .../test_employee_attendance_tool.js | 32 +++++++++++++++ erpnext/tests/ui/tests.txt | 7 ++-- 4 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 erpnext/hr/doctype/attendance/test_attendance.js create mode 100644 erpnext/hr/doctype/employee_attendance_tool/test_employee_attendance_tool.js diff --git a/erpnext/hr/doctype/attendance/test_attendance.js b/erpnext/hr/doctype/attendance/test_attendance.js new file mode 100644 index 00000000000..044d7162b5f --- /dev/null +++ b/erpnext/hr/doctype/attendance/test_attendance.js @@ -0,0 +1,41 @@ +QUnit.module('hr'); + +QUnit.test("Test: Attendance [HR]", function (assert) { + assert.expect(4); + let done = assert.async(); + let employee_code; + + frappe.run_serially([ + // get employee's auto generated name + () => frappe.set_route("List", "Employee", "List"), + () => frappe.timeout(0.5), + () => frappe.click_link('Test Employee'), + () => frappe.timeout(0.5), + () => employee_code = frappe.get_route()[2], + // test attendance creation for one employee + () => frappe.set_route("List", "Attendance", "List"), + () => frappe.timeout(0.5), + () => frappe.new_doc("Attendance"), + () => frappe.timeout(1), + () => assert.equal("Attendance", cur_frm.doctype, + "Form for new Attendance opened successfully."), + // set values in form + () => cur_frm.set_value("company", "Test Company"), + () => cur_frm.set_value("employee", employee_code), + () => cur_frm.save(), + () => frappe.timeout(1), + // check docstatus of attendance before submit [Draft] + () => assert.equal("0", cur_frm.doc.docstatus, + "attendance is currently drafted"), + // check docstatus of attendance after submit [Present] + () => cur_frm.savesubmit(), + () => frappe.timeout(0.5), + () => frappe.click_button('Yes'), + () => assert.equal("1", cur_frm.doc.docstatus, + "attendance is saved after submit"), + // check if auto filled date is present day + () => assert.equal(frappe.datetime.nowdate(), cur_frm.doc.attendance_date, + "attendance for Present day is marked"), + () => done() + ]); +}); \ No newline at end of file diff --git a/erpnext/hr/doctype/employee/test_employee.js b/erpnext/hr/doctype/employee/test_employee.js index 64fde8ee1a0..77d1433f0e3 100644 --- a/erpnext/hr/doctype/employee/test_employee.js +++ b/erpnext/hr/doctype/employee/test_employee.js @@ -12,6 +12,7 @@ QUnit.test("Test: Employee [HR]", function (assert) { () => frappe.timeout(1), () => cur_frm.set_value("employee_name", "Test Employee"), () => cur_frm.set_value("salutation", "Ms"), + () => cur_frm.set_value("company", "Test Company"), () => cur_frm.set_value("date_of_joining", frappe.datetime.add_months(today_date, -2)), // joined 2 month from now () => cur_frm.set_value("date_of_birth", frappe.datetime.add_months(today_date, -240)), // age is 20 years () => cur_frm.set_value("employment_type", "Test Employment type"), diff --git a/erpnext/hr/doctype/employee_attendance_tool/test_employee_attendance_tool.js b/erpnext/hr/doctype/employee_attendance_tool/test_employee_attendance_tool.js new file mode 100644 index 00000000000..c7cd3a39abd --- /dev/null +++ b/erpnext/hr/doctype/employee_attendance_tool/test_employee_attendance_tool.js @@ -0,0 +1,32 @@ +QUnit.module('hr'); + +QUnit.test("Test: Employee attendance tool [HR]", function (assert) { + assert.expect(3); + let done = assert.async(); + let attendance_date = frappe.datetime.add_days(frappe.datetime.nowdate(), -1); // previous day + + frappe.run_serially([ + () => frappe.set_route("Form", "Employee Attendance Tool"), + () => frappe.timeout(0.5), + () => assert.equal("Employee Attendance Tool", cur_frm.doctype, + "Form for Employee Attendance Tool opened successfully."), + // set values in form + () => cur_frm.set_value("date", attendance_date), + () => cur_frm.set_value("branch", "Test Branch"), + () => cur_frm.set_value("department", "Test Department"), + () => cur_frm.set_value("company", "Test Company"), + () => frappe.timeout(0.5), + () => frappe.click_check('Test Employee'), + () => frappe.tests.click_button('Mark Present'), + // check if attendance is marked + () => frappe.set_route("List", "Attendance", "List"), + () => frappe.timeout(1), + () => { + assert.equal("Test Employee", cur_list.data[0].employee_name, + "attendance marked correctly saved"); + assert.equal(attendance_date, cur_list.data[0].attendance_date, + "attendance date is set correctly"); + }, + () => done() + ]); +}); \ No newline at end of file diff --git a/erpnext/tests/ui/tests.txt b/erpnext/tests/ui/tests.txt index c46d6debb0f..cc2c643aa9b 100644 --- a/erpnext/tests/ui/tests.txt +++ b/erpnext/tests/ui/tests.txt @@ -9,12 +9,13 @@ erpnext/crm/doctype/item/test_item.js erpnext/manufacturing/doctype/workstation/test_workstation.js erpnext/manufacturing/doctype/operation/test_operation.js erpnext/manufacturing/doctype/bom/test_bom.js +erpnext/projects/doctype/project/project_timesheet.js erpnext/hr/doctype/holiday_list/test_holiday_list.js erpnext/hr/doctype/branch/test_branch.js -erpnext/manufacturing/doctype/bom/test_bom.js -erpnext/projects/doctype/project/project_timesheet.js erpnext/hr/doctype/leave_block_list/test_leave_block_list.js erpnext/hr/doctype/department/test_department.js erpnext/hr/doctype/designation/test_designation.js erpnext/hr/doctype/employment_type/test_employment_type.js -erpnext/hr/doctype/employee/test_employee.js \ No newline at end of file +erpnext/hr/doctype/employee/test_employee.js +erpnext/hr/doctype/employee_attendance_tool/test_employee_attendance_tool.js +erpnext/hr/doctype/attendance/test_attendance.js \ No newline at end of file