Skip to content

Commit

Permalink
test: geolocation tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchamahabal committed May 29, 2024
1 parent 63e3b70 commit 8773889
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
6 changes: 2 additions & 4 deletions hrms/hr/doctype/employee_checkin/employee_checkin.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ frappe.ui.form.on("Employee Checkin", {

navigator.geolocation.getCurrentPosition(
async (position) => {
frm.set_value({
latitude: position.coords.latitude,
longitude: position.coords.longitude,
});
frm.set_value("latitude", position.coords.latitude);
frm.set_value("longitude", position.coords.longitude);

await frm.call("set_geolocation_from_coordinates");
frappe.dom.unfreeze();
Expand Down
31 changes: 31 additions & 0 deletions hrms/hr/doctype/employee_checkin/test_employee_checkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,37 @@ def setUp(self):
to_date = get_year_ending(getdate())
self.holiday_list = make_holiday_list(from_date=from_date, to_date=to_date)

def test_geolocation_tracking(self):
employee = make_employee("test_add_log_based_on_employee_field@example.com")
checkin = make_checkin(employee)
checkin.latitude = 23.31773
checkin.longitude = 66.82876
checkin.save()

# geolocation tracking is disabled
self.assertIsNone(checkin.geolocation)

hr_settings = frappe.get_single("HR Settings")
hr_settings.allow_geolocation_tracking = 1
hr_settings.save()

checkin.save()
self.assertEqual(
checkin.geolocation,
frappe.json.dumps(
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {"type": "Point", "coordinates": [66.82876, 23.31773]},
}
],
}
),
)

def test_add_log_based_on_employee_field(self):
employee = make_employee("test_add_log_based_on_employee_field@example.com")
employee = frappe.get_doc("Employee", employee)
Expand Down

0 comments on commit 8773889

Please sign in to comment.