diff --git a/api/src/org/labkey/api/exp/query/SamplesSchema.java b/api/src/org/labkey/api/exp/query/SamplesSchema.java index c1e7412b208..0f4149ce05d 100644 --- a/api/src/org/labkey/api/exp/query/SamplesSchema.java +++ b/api/src/org/labkey/api/exp/query/SamplesSchema.java @@ -260,14 +260,17 @@ public ForeignKey materialIdForeignKey(@Nullable final ExpSampleType st, @Nullab private TableInfo createLookupTableInfo() { + // Hack to support lookup via RowId or Name + if (domainProperty != null && domainProperty.getPropertyType().getJdbcType().isText()) + _columnName = "Name"; + + // GitHub Issue #688 + if (st != null) + return getTable(tableName, getLookupContainerFilter()); + ExpMaterialTable ret = ExperimentService.get().createMaterialTable(SamplesSchema.this, getLookupContainerFilter(), st); ret.populate(); ret.overlayMetadata(ret.getPublicName(), SamplesSchema.this, new ArrayList<>()); - if (domainProperty != null && domainProperty.getPropertyType().getJdbcType().isText()) - { - // Hack to support lookup via RowId or Name - _columnName = "Name"; - } ret.setLocked(true); return ret; } diff --git a/study/test/src/org/labkey/test/tests/study/AssayTest.java b/study/test/src/org/labkey/test/tests/study/AssayTest.java index 2e177b59bd0..a1285d1436f 100644 --- a/study/test/src/org/labkey/test/tests/study/AssayTest.java +++ b/study/test/src/org/labkey/test/tests/study/AssayTest.java @@ -279,7 +279,6 @@ public void testSampleFieldUpdate() clickAndWait(Locator.linkWithText("view results")); assertElementPresent("Sample lookup failed for: OS_1", new Locator.LinkLocator("OS_1"), 1); - log("Edit assay design and change Sample field to point to created Sample Type"); goToManageAssays(); clickAndWait(Locator.LinkLocator.linkWithText(SAMPLE_FIELD_TEST_ASSAY)); @@ -294,10 +293,21 @@ public void testSampleFieldUpdate() importAssayData(SAMPLE_FIELD_TEST_ASSAY, TEST_RUN2, "SampleField\nS_1"); goToManageAssays().clickAndWait(Locator.linkWithText(SAMPLE_FIELD_TEST_ASSAY)); clickAndWait(Locator.linkWithText("view results")); -// assertElementPresent("Sample lookup failed for: OS_1", new Locator.LinkLocator("OS_1"), 1); //TODO this becomes the RowId "<123>" after change. Issue #40047 - + DataRegionTable table = new DataRegionTable("Data", getDriver()); + List sampleFieldValues = table.getColumnDataAsText("SampleField"); + assertTrue("First sample should not resolve to sample type", sampleFieldValues.get(0).startsWith("<")); + assertEquals("Second sample should resolve to sample type", "S_1", sampleFieldValues.get(1)); assertElementPresent("Sample lookup failed for: S_1", new Locator.LinkLocator("S_1"), 1); + log("GitHub Issue #688: verify sample lookup to createdBy"); + _customizeViewsHelper.openCustomizeViewPanel(); + _customizeViewsHelper.addColumn("SampleField/CreatedBy"); + _customizeViewsHelper.applyCustomView(); + table = new DataRegionTable("Data", getDriver()); + List createdByValues = table.getColumnDataAsText("SampleField/CreatedBy"); + assertEquals("First sample should not have a createdBy since it doesn't resolve", " ", createdByValues.get(0)); + assertEquals("Second sample should have a createdBy since it resolves to a sample type", getCurrentUserName(), createdByValues.get(1)); + log("Edit assay design and change Sample field to point back to 'All Samples'"); goToManageAssays(); clickAndWait(Locator.LinkLocator.linkWithText(SAMPLE_FIELD_TEST_ASSAY)); @@ -319,6 +329,10 @@ public void testSampleFieldUpdate() assertElementPresent("Sample lookup failed for: S_2", new Locator.LinkLocator("S_2"), 1); assertElementPresent("Sample lookup failed for: OS_2", new Locator.LinkLocator("OS_2"), 1); + log("GitHub Issue #688: verify sample lookup to createdBy"); + table = new DataRegionTable("Data", getDriver()); + for (int i = 0; i < table.getDataRowCount(); i++) + assertEquals("Row " + i + " should have current user as createdBy since they all resolve to samples", getCurrentUserName(), table.getDataAsText(i, "SampleField/CreatedBy")); } private void importAssayData(String assayName, String runName, String runDataStr)