[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
diff --git a/erpnext/hr/doctype/employee/test_employee.js b/erpnext/hr/doctype/employee/test_employee.js
index 64a6b7a..b7f5105 100644
--- a/erpnext/hr/doctype/employee/test_employee.js
+++ b/erpnext/hr/doctype/employee/test_employee.js
@@ -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()
 	]);
 });
\ No newline at end of file
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
index a71ba0f..3ec8ac0 100644
--- a/erpnext/hr/doctype/employee_attendance_tool/test_employee_attendance_tool.js
+++ b/erpnext/hr/doctype/employee_attendance_tool/test_employee_attendance_tool.js
@@ -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 @@
 		() => 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()
 	]);
diff --git a/erpnext/hr/doctype/leave_control_panel/test_leave_control_panel.js b/erpnext/hr/doctype/leave_control_panel/test_leave_control_panel.js
index e71ff6e..5133c0c 100644
--- a/erpnext/hr/doctype/leave_control_panel/test_leave_control_panel.js
+++ b/erpnext/hr/doctype/leave_control_panel/test_leave_control_panel.js
@@ -28,8 +28,8 @@
 		() => 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()
 	]);
diff --git a/erpnext/hr/doctype/salary_slip/test_salary_slip.js b/erpnext/hr/doctype/salary_slip/test_salary_slip.js
new file mode 100644
index 0000000..a49c973
--- /dev/null
+++ b/erpnext/hr/doctype/salary_slip/test_salary_slip.js
@@ -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()
+	]);
+});
\ No newline at end of file
diff --git a/erpnext/hr/doctype/salary_structure/test_salary_structure.js b/erpnext/hr/doctype/salary_structure/test_salary_structure.js
new file mode 100644
index 0000000..0740357
--- /dev/null
+++ b/erpnext/hr/doctype/salary_structure/test_salary_structure.js
@@ -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()
+	]);
+});
\ No newline at end of file
diff --git a/erpnext/tests/ui/tests.txt b/erpnext/tests/ui/tests.txt
index 86b6a3a..5d60ad1 100644
--- a/erpnext/tests/ui/tests.txt
+++ b/erpnext/tests/ui/tests.txt
@@ -64,6 +64,8 @@
 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