[UI Test Salary] To test the salary structure and the salary slip (#10407)

* Test for salary structure and salary slip

* Test for salary structure and salary slip

* Test for salary structure and salary slip

* Travis CI fixes

* Updated

* Updated

* travis fixes

* Travis fixes
This commit is contained in:
Utkarsh Goswami 2017-08-16 11:32:04 +05:30 committed by Makarand Bauskar
parent 289400d944
commit 44b088c6b3
6 changed files with 170 additions and 39 deletions

View File

@ -1,39 +1,40 @@
QUnit.module('hr');
QUnit.test("Test: Employee [HR]", function (assert) {
assert.expect(3);
assert.expect(4);
let done = assert.async();
let today_date = frappe.datetime.nowdate();
frappe.run_serially([
// let today_date = frappe.datetime.nowdate();
let employee_creation = (name,joining_date,birth_date) => {
frappe.run_serially([
// test employee creation
() => frappe.set_route("List", "Employee", "List"),
() => frappe.new_doc("Employee"),
() => frappe.timeout(1),
() => cur_frm.set_value("employee_name", "Test Employee 1"),
() => 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"),
() => cur_frm.set_value("holiday_list", "Test Holiday list"),
() => cur_frm.set_value("branch", "Test Branch"),
() => cur_frm.set_value("department", "Test Department"),
() => cur_frm.set_value("designation", "Test Designation"),
() => frappe.click_button('Add Row'),
() => cur_frm.fields_dict.leave_approvers.grid.grid_rows[0].doc.leave_approver="Administrator",
// save data
() => cur_frm.save(),
() => frappe.timeout(1),
// check name of employee
() => assert.equal("Test Employee 1", cur_frm.doc.employee_name,
'name of employee correctly saved'),
// check auto filled gender according to salutation
() => assert.equal("Female", cur_frm.doc.gender,
'gender correctly saved as per salutation'),
// check auto filled retirement date [60 years from DOB]
() => assert.equal(frappe.datetime.add_months(today_date, 480), cur_frm.doc.date_of_retirement, // 40 years from now
'retirement date correctly saved as per date of birth'),
() => {
frappe.tests.make('Employee', [
{ employee_name: name},
{ salutation: 'Mr'},
{ company: 'Test Company'},
{ date_of_joining: joining_date},
{ date_of_birth: birth_date},
{ employment_type: 'Test Employment Type'},
{ holiday_list: 'Test Holiday List'},
{ branch: 'Test Branch'},
{ department: 'Test Department'},
{ designation: 'Test Designation'}
]);
},
() => frappe.timeout(2),
() => {
assert.ok(cur_frm.get_field('employee_name').value==name,
'Name of an Employee is correctly set');
assert.ok(cur_frm.get_field('gender').value=='Male',
'Gender of an Employee is correctly set');
},
]);
};
frappe.run_serially([
() => employee_creation('Test Employee 1','2017-04-01','1992-02-02'),
() => frappe.timeout(6),
() => employee_creation('Test Employee 3','2017-04-01','1992-02-02'),
() => frappe.timeout(4),
() => done()
]);
});

View File

@ -1,10 +1,10 @@
QUnit.module('hr');
QUnit.test("Test: Employee attendance tool [HR]", function (assert) {
assert.expect(3);
assert.expect(2);
let done = assert.async();
let today_date = frappe.datetime.nowdate();
let date_of_attendance = frappe.datetime.add_days(today_date, -1); // previous day
let date_of_attendance = frappe.datetime.add_days(today_date, -2); // previous day
frappe.run_serially([
// create employee
@ -38,11 +38,9 @@ QUnit.test("Test: Employee attendance tool [HR]", function (assert) {
() => frappe.set_route("List", "Attendance", "List"),
() => frappe.timeout(1),
() => {
assert.deepEqual(["Test Employee 2", "Test Employee 1"], [cur_list.data[0].employee_name, cur_list.data[1].employee_name],
"marked attendance correctly saved for both employee");
let marked_attendance = cur_list.data.filter(d => d.attendance_date == date_of_attendance);
assert.equal(marked_attendance.length, 2,
'both the attendance are marked for correct date');
assert.equal(marked_attendance.length, 3,
'all the attendance are marked for correct date');
},
() => done()
]);

View File

@ -28,8 +28,8 @@ QUnit.test("Test: Leave control panel [HR]", function (assert) {
() => frappe.timeout(1),
() => {
let leave_allocated = cur_list.data.filter(d => d.leave_type == "Test Leave type");
assert.equal(2, leave_allocated.length,
'leave allocation successfully done for both the employee');
assert.equal(3, leave_allocated.length,
'leave allocation successfully done for all the employees');
},
() => done()
]);

View File

@ -0,0 +1,49 @@
QUnit.test("test salary slip", function(assert) {
assert.expect(6);
let done = assert.async();
let employee_name;
let salary_slip = (ename) => {
frappe.run_serially([
() => frappe.db.get_value('Employee', {'employee_name': ename}, 'name'),
(r) => {
employee_name = r.message.name;
},
() => {
// Creating a salary slip for a employee
frappe.tests.make('Salary Slip', [
{ employee: employee_name}
]);
},
() => frappe.timeout(1),
() => {
// To check if all the calculations are correctly done
if(ename === 'Test Employee 1')
{
assert.ok(cur_frm.doc.gross_pay==24000,
'Gross amount for first employee is correctly calculated');
assert.ok(cur_frm.doc.total_deduction==4800,
'Deduction amount for first employee is correctly calculated');
assert.ok(cur_frm.doc.net_pay==19200,
'Net amount for first employee is correctly calculated');
}
if(ename === 'Test Employee 3')
{
assert.ok(cur_frm.doc.gross_pay==28800,
'Gross amount for second employee is correctly calculated');
assert.ok(cur_frm.doc.total_deduction==5760,
'Deduction amount for second employee is correctly calculated');
assert.ok(cur_frm.doc.net_pay==23040,
'Net amount for second employee is correctly calculated');
}
},
]);
};
frappe.run_serially([
() => salary_slip('Test Employee 1'),
() => frappe.timeout(6),
() => salary_slip('Test Employee 3'),
() => frappe.timeout(3),
() => done()
]);
});

View File

@ -0,0 +1,81 @@
QUnit.test("test Salary Structure", function(assert) {
assert.expect(6);
let done = assert.async();
let employee_name1;
let salary_structure = (ename1,ename2) => {
frappe.run_serially([
() => frappe.db.get_value('Employee', {'employee_name': ename1}, 'name'),
(r) => {
employee_name1 = r.message.name;
},
() => frappe.db.get_value('Employee', {'employee_name': ename2}, 'name'),
(r) => {
// Creating Salary Structure for employees);
frappe.tests.make('Salary Structure', [
{ company: 'Test Company'},
{ payroll_frequency: 'Monthly'},
{ employees: [
[
{employee: employee_name1},
{from_date: '2017-07-01'},
{base: 25000}
],
[
{employee: r.message.name},
{from_date: '2017-07-01'},
{base: 30000}
]
]},
{ earnings: [
[
{salary_component: 'Basic'},
{formula: 'base * .80'}
],
[
{salary_component: 'Leave Encashment'},
{formula: 'B * .20'}
]
]},
{ deductions: [
[
{salary_component: 'Income Tax'},
{formula: '(B+LE) * .20'}
]
]},
{ payment_account: 'CASH - TC'},
]);
},
() => frappe.timeout(9),
() => cur_dialog.set_value('value','Test Salary Structure'),
() => frappe.timeout(2),
() => frappe.click_button('Create'),
() => {
// To check if all the fields are correctly set
assert.ok(cur_frm.doc.employees[0].employee_name.includes('Test Employee 1') &&
cur_frm.doc.employees[1].employee_name.includes('Test Employee 3'),
'Employee names are correctly set');
assert.ok(cur_frm.doc.employees[0].base==25000,
'Base value for first employee is correctly set');
assert.ok(cur_frm.doc.employees[1].base==30000,
'Base value for second employee is correctly set');
assert.ok(cur_frm.doc.earnings[0].formula.includes('base * .80'),
'Formula for earnings as Basic is correctly set');
assert.ok(cur_frm.doc.earnings[1].formula.includes('B * .20'),
'Formula for earnings as Leave Encashment is correctly set');
assert.ok(cur_frm.doc.deductions[0].formula.includes('(B+LE) * .20'),
'Formula for deductions as Income Tax is correctly set');
},
]);
};
frappe.run_serially([
() => salary_structure('Test Employee 1','Test Employee 3'),
() => frappe.timeout(14),
() => done()
]);
});

View File

@ -64,6 +64,8 @@ erpnext/schools/doctype/assessment_criteria_group/test_assessment_criteria_group
erpnext/schools/doctype/assessment_criteria/test_assessment_criteria.js
erpnext/schools/doctype/course/test_course.js
erpnext/schools/doctype/program/test_program.js
erpnext/hr/doctype/salary_structure/test_salary_structure.js
erpnext/hr/doctype/salary_slip/test_salary_slip.js
erpnext/schools/doctype/guardian/test_guardian.js
erpnext/schools/doctype/student_admission/test_student_admission.js
erpnext/schools/doctype/student_applicant/tests/test_student_applicant_dummy_data.js