diff --git a/src/core/js/caosdb.js b/src/core/js/caosdb.js index fe8f0cba5e5795a23615650bf5516c344e012d54..a2c1f55ce49e409b0153c888197002868b90a637 100644 --- a/src/core/js/caosdb.js +++ b/src/core/js/caosdb.js @@ -627,20 +627,11 @@ function getPropertyFromElement(propertyelement, names = undefined) { if (property.list) { // list datatypes let listel; - if (property.reference) { - // list of referernces - listel = findElementByConditions(valel, x => x.classList.contains("caosdb-f-reference-value"), - x => x.classList.contains("caosdb-preview-container")); - for (var j = 0; j < listel.length; j++) { - property.value.push(getIDfromHREF(listel[j])); - } - } else { - // list of anything but references - listel = findElementByConditions(valel, x => x.classList.contains("list-inline-item"), - x => x.classList.contains("caosdb-preview-container")); - for (var j = 0; j < listel.length; j++) { - property.value.push(listel[j].textContent); - } + // list of anything but references + listel = findElementByConditions(valel, x => x.classList.contains("caosdb-f-property-single-raw-value"), + x => x.classList.contains("caosdb-preview-container")); + for (var j = 0; j < listel.length; j++) { + property.value.push(listel[j].textContent); } } else if (property.reference && valel.getElementsByTagName("a")[0]) { // reference datatypes diff --git a/test/core/js/modules/caosdb.js.js b/test/core/js/modules/caosdb.js.js index 8df5e2f9c2b933cd7b678286295961f2c73d7113..49b26b61d3448cbc0c9b8dd50b536e282d134dec 100644 --- a/test/core/js/modules/caosdb.js.js +++ b/test/core/js/modules/caosdb.js.js @@ -19,7 +19,15 @@ QUnit.module("caosdb.js", { }, before: function(assert) { - var done = assert.async(3); + var done = assert.async(4); + + // load entity.xsl + var qunit_obj = this; + _retrieveEntityXSL().then(function(xsl) { + qunit_obj.entityXSL = xsl + done(); + }); + this.setTestDocument("x", done, ` <Response> <Record name="nameofrecord"> @@ -82,7 +90,7 @@ QUnit.module("caosdb.js", { </Record> </Response>`); - + // Test document for unset references this.setTestDocument("unsetReferencesTest", done, ` <Response> @@ -566,3 +574,61 @@ QUnit.test("unset_file_attributes", function(assert) { undefined); assert.equal(xml2str(res3), "<File id=\"103\" name=\"test\" path=\"testfile.txt\" checksum=\"blablabla\" size=\"0\"/>"); }); + +QUnit.test("getPropertyFromElement", async function(assert) { + var data = await $.ajax({ + cache: true, + dataType: 'xml', + url: "xml/test_case_list_of_myrecordtype.xml", + }); + console.log(this.entityXSL); + var xsl = injectTemplate(this.entityXSL, '<xsl:template match="/"><ul><xsl:apply-templates select="Property" mode="entity-body"/></ul></xsl:template>'); + var params = { + entitypath: "/entitypath/" + }; + var ret = xslt(data, xsl, params); + assert.ok(ret); + assert.propEqual(getPropertyFromElement(ret.firstElementChild), { + "datatype": "LIST<MyRecordType>", + "description": undefined, + "html": {}, + "id": "149315", + "list": true, + "listDatatype": "MyRecordType", + "name": "MyRecordType", + "reference": true, + "unit": undefined, + "value": [ + "167510", + "", + "167546", + "167574", + "167625", + "167515", + "167441", + "167596", + "167249", + "167632", + "167593", + "167321", + "167536", + "167389", + "167612", + "167585", + "167228", + "167211", + "167414", + "167282", + "167409", + "167637", + "167487", + "167328", + "167572", + "167245", + "167615", + "167301", + "167466" + ] + }); + +}); diff --git a/test/core/js/modules/entity.xsl.js b/test/core/js/modules/entity.xsl.js index 34707c0bae5b128dce33ff28f584cac605579ad6..04ec35a6fc14cbad81c731908e28f788999c3563 100644 --- a/test/core/js/modules/entity.xsl.js +++ b/test/core/js/modules/entity.xsl.js @@ -128,12 +128,13 @@ QUnit.test("Entities have a caosdb-annotation-section", function(assert) { QUnit.test("LIST Property", function(assert) { var done = assert.async(); var entityXSL = this.entityXSL; - assert.expect(2); + assert.expect(4); $.ajax({ cache: true, dataType: 'xml', url: "xml/test_case_list_of_myrecordtype.xml", }).done(function(data, textStatus, jdXHR) { + console.log(entityXSL); var xsl = injectTemplate(entityXSL, '<xsl:template match="/"><xsl:apply-templates select="Property" mode="property-value"/></xsl:template>'); var params = { entitypath: "/entitypath/" @@ -141,6 +142,8 @@ QUnit.test("LIST Property", function(assert) { var ret = xslt(data, xsl, params); assert.ok(ret); assert.equal(ret.firstChild.className, "caosdb-value-list", "property value contains a list.") + assert.equal($(ret.firstChild).find(".caosdb-f-property-single-raw-value").length, 29, "29 values in the list"); + assert.equal($(ret.firstChild).find(".caosdb-f-reference-value").length, 28, "28 reference values in the list"); }).always(function() { done(); }); diff --git a/test/core/xml/test_case_list_of_myrecordtype.xml b/test/core/xml/test_case_list_of_myrecordtype.xml index b67c857e22a983774b0ae1ba7e88d9ccd2515de8..63587832758049c6de22055225c9dbb9acb7ff48 100644 --- a/test/core/xml/test_case_list_of_myrecordtype.xml +++ b/test/core/xml/test_case_list_of_myrecordtype.xml @@ -24,6 +24,7 @@ <Property id="149315" name="MyRecordType" datatype="LIST<MyRecordType>" importance="FIX"> <Value>167510</Value> + <Value></Value> <Value>167546</Value> <Value>167574</Value> <Value>167625</Value>