def test_required_field(self) -> None: """Test xlson.build_field() - returns a native form required field dict.""" options = { "name": "first_name", "label": "What's your name?", "type": "text", "bind": { "required": "yes", "jr:requiredMsg": "Please enter the first name.", }, } self.assertDictEqual( xlson.build_field(options), { "key": "first_name", "openmrs_entity_parent": "", "openmrs_entity": "", "openmrs_entity_id": "", "type": "edit_text", "hint": "What's your name?", "edit_type": "name", "v_required": { "value": "true", "err": "Please enter the first name." }, }, )
def test_group_field(self) -> None: """Test a native form step structure.""" step = { "name": "step1", "label": "Patient Information", "type": "group", "children": [{ "name": "first_name", "label": "What's your name?", "type": "text" }], } self.assertDictEqual( xlson.build_field(step), { "step1": { "title": "Patient Information", "fields": [{ "edit_type": "name", "hint": "What's your name?", "key": "first_name", "openmrs_entity": "", "openmrs_entity_id": "", "openmrs_entity_parent": "", "type": "edit_text", }], } }, )
def test_constraint_field_with_regex_value(self) -> None: """Test xlson.build_field() - returns a native form constraint field dict.""" options = { "name": "user_first_name", "label": "User First name", "type": "text", "bind": { "jr:constraintMsg": "Please enter a valid name.", "constraint": "regex(., '[A-Za-z\\s\\.\\-]*')", }, } self.assertDictEqual( xlson.build_field(options), { "key": "user_first_name", "openmrs_entity_parent": "", "openmrs_entity": "", "openmrs_entity_id": "", "type": "edit_text", "hint": "User First name", "edit_type": "name", "v_regex": { "value": "[A-Za-z\\s\\.\\-]*", "err": "Please enter a valid name.", }, }, )
def test_checkbox_field(self) -> None: """Test xlson.build_field() - returns a native form checkbox field dict.""" # Without openmrs_entity_id options = { "name": "colours", "label": "Choose colours you like?", "type": "select all that apply", "children": [ { "name": "ze_gree", "label": "Green", "instance": { "openmrs_entity_id": "AABBGRR" }, }, { "name": "ze_yellow", "label": "Yellow", "instance": { "openmrs_entity_id": "BBCCYLL" }, }, ], } selected = False self.assertDictEqual( xlson.build_field(options), { "key": "colours", "openmrs_entity_parent": "", "openmrs_entity": "", "openmrs_entity_id": "", "type": "check_box", "label": "Choose colours you like?", "options": [ { "key": "ze_gree", "text": "Green", "openmrs_choice_id": "AABBGRR", "value": selected, }, { "key": "ze_yellow", "text": "Yellow", "openmrs_choice_id": "BBCCYLL", "value": selected, }, ], }, # noqa )
def test_native_radio_field(self) -> None: """Test xlson.build_field() - returns a native form native radio field dict""" options = { "name": "user_select", "label": "Is the child happy?", "type": "select one", "children": [ { "name": "yes", "label": "Yes", "instance": { "openmrs_entity_id": "AABB" }, }, { "name": "no", "label": "No", "instance": { "openmrs_entity_id": "BBCC" }, }, ], } # noqa self.assertDictEqual( xlson.build_field(options), { "key": "user_select", "openmrs_entity_parent": "", "openmrs_entity": "", "openmrs_entity_id": "", "type": "native_radio", "label": "Is the child happy?", "options": [ { "key": "yes", "openmrs_entity_parent": "", "openmrs_entity": "", "openmrs_entity_id": "AABB", "text": "Yes", }, { "key": "no", "openmrs_entity_parent": "", "openmrs_entity": "", "openmrs_entity_id": "BBCC", "text": "No", }, ], }, # noqa )
def test_spinner_field(self) -> None: """Test xlson.build_field() - returns a native form spinner field dict.""" options = { "name": "user_spinner", "label": "What is the mood?", "type": "select all that apply", "children": [ { "name": "happy", "label": "Happy", "instance": { "openmrs_entity_id": "1107AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" }, }, { "name": "sad", "label": "Sad", "instance": { "openmrs_entity_id": "1713AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" }, }, { "name": "somber", "label": "Somber", "instance": { "openmrs_entity_id": "2113AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" }, }, ], } self.assertDictEqual( xlson.build_field(options), { "key": "user_spinner", "openmrs_entity_parent": "", "openmrs_entity": "", "openmrs_entity_id": "", "type": "spinner", "hint": "What is the mood?", "values": ["Happy", "Sad", "Somber"], "keys": ["happy", "sad", "somber"], "openmrs_choice_ids": { "happy": "1107AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "sad": "1713AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "somber": "2113AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", }, }, # noqa )
def test_gps_field(self) -> None: """Test xlson.build_field() - returns a native form gps field dict.""" options = {"name": "user_gps", "label": "GPS", "type": "geopoint"} self.assertDictEqual( xlson.build_field(options), { "key": "user_gps", "openmrs_entity": "", "openmrs_entity_id": "", "openmrs_entity_parent": "", "openmrs_data_type": "text", "type": "gps", }, )
def test_number_field(self) -> None: """Test xlson.build_field() - returns a native form integer field dict.""" options = {"name": "user_age", "label": "User age", "type": "integer"} self.assertDictEqual( xlson.build_field(options), { "key": "user_age", "openmrs_entity_parent": "", "openmrs_entity": "", "openmrs_entity_id": "", "type": "edit_text", "hint": "User age", "edit_type": "number", }, )
def test_choose_image_field(self) -> None: """Test xlson.build_field() - returns a native form choose_image field dict.""" options = { "name": "user_image", "label": "Take a photo of the child.", "type": "photo", } self.assertDictEqual( xlson.build_field(options), { "uploadButtonText": options["label"], "key": options["name"], "openmrs_entity": "", "openmrs_entity_id": "", "openmrs_entity_parent": "", "type": "choose_image", }, )
def test_edit_text_field(self) -> None: """Test xlson.build_field() - returns a native form field dict.""" options = { "name": "first_name", "label": "What's your name?", "type": "text" } self.assertDictEqual( xlson.build_field(options), { "edit_type": "name", "hint": options["label"], "key": options["name"], "openmrs_entity": "", "openmrs_entity_id": "", "openmrs_entity_parent": "", "type": "edit_text", }, )
def test_barcode_field(self) -> None: """Test xlson.build_field() - returns a native form barcode field dict""" options = { "name": "user_qrcode", "label": "User ID", "hint": "Scan QR code", "type": "barcode", } self.assertDictEqual( xlson.build_field(options), { "key": "user_qrcode", "openmrs_entity_parent": "", "openmrs_entity": "", "openmrs_entity_id": "", "type": "barcode", "barcode_type": "qrcode", "hint": "User ID", "scanButtonText": "Scan QR code", }, )