Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 70 additions & 1 deletion study/test/src/org/labkey/test/tests/study/AssayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.labkey.test.tests.study;

import org.assertj.core.api.Assertions;
import org.junit.Assume;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.labkey.api.util.FileUtil;
Expand All @@ -34,6 +36,8 @@
import org.labkey.test.components.domain.DomainFormPanel;
import org.labkey.test.pages.ReactAssayDesignerPage;
import org.labkey.test.pages.assay.AssayBeginPage;
import org.labkey.test.pages.assay.AssayImportPage;
import org.labkey.test.pages.assay.AssayRunsPage;
import org.labkey.test.params.FieldDefinition;
import org.labkey.test.params.FieldInfo;
import org.labkey.test.params.experiment.SampleTypeDefinition;
Expand All @@ -46,17 +50,23 @@
import org.labkey.test.util.SampleTypeHelper;
import org.labkey.test.util.StudyHelper;
import org.labkey.test.util.TestDataGenerator;
import org.labkey.test.util.data.TestArrayDataUtils;
import org.labkey.test.util.data.TestDataUtils;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.labkey.test.util.TestDataGenerator.shuffleSelect;
import static org.labkey.test.util.samplemanagement.SMTestUtils.COL_ASSAY_ID_LABEL;
import static org.labkey.test.util.samplemanagement.SMTestUtils.COL_MULTITEXTCHOICE;
import static org.labkey.test.util.samplemanagement.SMTestUtils.TEXT_MULTI_CHOICE_LIST;
Comment on lines +67 to +69
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless there is a matching dependency between the modules themselves, tests for one module shouldn't import anything from tests for another module.
Referring to code in a private repository from code in a public repository is especially unwanted. The community suites can't run with this sort of import present.

This test should just define its own multi-text choice column.


@Category({Daily.class, Assays.class})
public class AssayTest extends AbstractAssayTest
Expand All @@ -71,6 +81,8 @@ public class AssayTest extends AbstractAssayTest
private static final String ISSUE_53831_PROJECT = "Issue53831Project" + TRICKY_CHARACTERS_FOR_PROJECT_NAMES;
private static final String SAMPLE_FIELD_TEST_ASSAY = "SampleFieldTestAssay";
private static final String SAMPLE_FIELD_PROJECT_NAME = "Sample Field Test Project" + TRICKY_CHARACTERS_FOR_PROJECT_NAMES;
private static final String MVTC_MULTI_FILE_IMPORT_ASSAY = TestDataGenerator.randomDomainName("MVTCMultiFileImportAssay", DomainUtils.DomainKind.Assay);
private static final String MVTC_MULTI_FILE_IMPORT_PROJECT = "MVTCMultiFileImportAssay" + TRICKY_CHARACTERS_FOR_PROJECT_NAMES;

@Override
protected String getProjectName()
Expand All @@ -90,6 +102,7 @@ protected void doCleanup(boolean afterTest) throws TestTimeoutException
_containerHelper.deleteProject(ISSUE_53616_PROJECT, false);
_containerHelper.deleteProject(ISSUE_53625_PROJECT, false);
_containerHelper.deleteProject(ISSUE_53831_PROJECT, false);
_containerHelper.deleteProject(MVTC_MULTI_FILE_IMPORT_PROJECT, false);

_userHelper.deleteUsers(false, TEST_ASSAY_USR_PI1, TEST_ASSAY_USR_TECH1);
}
Expand All @@ -109,6 +122,62 @@ public void testAssayNameMaxLength() throws Exception
assayDesignerPage.clickCancel();
}

@Test
public void testAssayMultiFileImportForMVTC() throws Exception
{
Assume.assumeTrue("Multi-choice text fields are only supported on PostgreSQL", WebTestHelper.getDatabaseType() == WebTestHelper.DatabaseType.PostgreSQL);
_containerHelper.createProject(MVTC_MULTI_FILE_IMPORT_PROJECT, "Assay");
goToProjectHome(MVTC_MULTI_FILE_IMPORT_PROJECT);
log("Create test assay");
ReactAssayDesignerPage assayDesignerPage = _assayHelper.createAssayDesign("General", MVTC_MULTI_FILE_IMPORT_ASSAY);

assayDesignerPage.goToResultsFields()
.removeAllFields(false)
.addField(COL_MULTITEXTCHOICE.getFieldDefinition());

assayDesignerPage.clickFinish();
Comment on lines +132 to +138
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create this assay via API.


String firstFileName = "MVTCAssayImport.tsv";
String secondFileName = "MVTCAssayImportSecond.tsv";
List<List<String>> fileDataFirstImport = Stream.generate(() -> shuffleSelect(TEXT_MULTI_CHOICE_LIST))
.limit(5)
.toList();
List<List<String>> fileDataSecondImport = Stream.generate(() -> shuffleSelect(TEXT_MULTI_CHOICE_LIST))
.limit(5)
.toList();

log("Import first and second runs with MVTC data from files");
AssayImportPage assayImportPage = goToManageAssays()
.clickAssay(MVTC_MULTI_FILE_IMPORT_ASSAY)
.clickImportData();
assayImportPage.clickNext();
assayImportPage.setDataFile(TestFileUtils.writeTempFile(firstFileName, buildFileContent(fileDataFirstImport)));

assayImportPage = assayImportPage.clickSaveAndImportAnother();
assayImportPage.setDataFile(TestFileUtils.writeTempFile(secondFileName, buildFileContent(fileDataSecondImport)));
assayImportPage.clickSaveAndFinish();

AssayRunsPage assayRunsPage = new AssayRunsPage(getDriver());
checker().wrapAssertion(() -> Assertions.assertThat(assayRunsPage.getTable().getColumnDataAsText(COL_ASSAY_ID_LABEL))
.as("expect both runs to appear in the runs list")
.containsExactlyInAnyOrder(firstFileName, secondFileName));

List<String> expectedValues = Stream.concat(fileDataFirstImport.stream(), fileDataSecondImport.stream())
.map(values -> TestArrayDataUtils.sortAndJoin(values, " "))
.toList();
checker().wrapAssertion(() -> Assertions.assertThat(assayRunsPage.clickViewResults().getDataTable().getColumnDataAsText(COL_MULTITEXTCHOICE.getLabel()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use column labels as a last resort.

Suggested change
checker().wrapAssertion(() -> Assertions.assertThat(assayRunsPage.clickViewResults().getDataTable().getColumnDataAsText(COL_MULTITEXTCHOICE.getLabel()))
checker().wrapAssertion(() -> Assertions.assertThat(assayRunsPage.clickViewResults().getDataTable().getColumnDataAsText(COL_MULTITEXTCHOICE))

.as("expect MVTC values to match imported data")
.containsExactlyInAnyOrderElementsOf(expectedValues));
}

private String buildFileContent(List<List<String>> fileData)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method's functionality is much more specialized than the method name implies. The name should reflect the specific purpose of this method. Also, it should just return the file since that's how this is always used.

Suggested change
private String buildFileContent(List<List<String>> fileData)
private File writeMultiValueTextForAssayRun(List<List<String>> multiValueSelections)

{
return Stream.concat(
Stream.of(COL_MULTITEXTCHOICE.getName()),
fileData.stream().map(TestArrayDataUtils::formatMultiValueText)
).collect(Collectors.joining("\n", "", "\n"));
}

// Issue 53616: Assay creation attempt after an error results in "Assay protocol already exists for this name."
@Test
public void testFailedCreation() throws Exception
Expand Down
Loading