Skip to content

Commit ba3aad0

Browse files
authored
JBrowseTest: collapse features by location to find unique (#222)
* JBrowseTest: collapse features by location to find unique
1 parent f8ab5ea commit ba3aad0

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

jbrowse/src/client/JBrowse/VariantSearch/components/VariantTableWidget.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ const VariantTableWidget = observer(props => {
211211
}
212212

213213
// Contains all features from the API call once the useEffect finished
214-
//const [features, setFeatures] = useState<ExtendedVcfFeature[]>([])
215214
const [features, setFeatures] = useState<any[]>([])
216215
const [columns, setColumns] = useState<GridColDef[]>([])
217216

jbrowse/test/src/org/labkey/test/tests/external/labModules/JBrowseTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ private void testMessageDisplay()
420420
waitForJBrowseToLoad();
421421

422422
Actions actions = new Actions(getDriver());
423-
WebElement toClick = getDriver().findElements(getVariantWithinTrack("mgap_hg38", "deletion TA -> T")).stream().filter(WebElement::isDisplayed).findFirst().orElseThrow();
423+
WebElement toClick = getDriver().findElements(JBrowseTestHelper.getVariantWithinTrack(this, "mgap_hg38", "deletion TA -> T", false)).stream().filter(WebElement::isDisplayed).findFirst().orElseThrow();
424424
actions.click(toClick).perform();
425425
waitForElement(Locator.tagContainingText("div", "Aut molestiae temporibus nesciunt."));
426426
}

jbrowse/test/src/org/labkey/test/tests/external/labModules/JBrowseTestHelper.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.labkey.test.util.ext4cmp.Ext4FieldRef;
1414
import org.labkey.test.util.ext4cmp.Ext4GridRef;
1515
import org.openqa.selenium.By;
16+
import org.openqa.selenium.Point;
1617
import org.openqa.selenium.StaleElementReferenceException;
1718
import org.openqa.selenium.WebElement;
1819

@@ -25,13 +26,19 @@ public class JBrowseTestHelper
2526
public static final File MGAP_TEST_VCF = new File(TestFileUtils.getLabKeyRoot(), "server/modules/DiscvrLabKeyModules/jbrowse/resources/web/jbrowse/mgap/mGap.v2.1.subset.vcf.gz");
2627
public static final File GRCH37_GENOME = new File(TestFileUtils.getLabKeyRoot(), "server/modules/DiscvrLabKeyModules/jbrowse/resources/web/jbrowse/mgap/GRCh37_small.fasta");
2728

28-
public static <T> Collector<T, ?, T> toSingleton() {
29+
public static Collector<WebElement, ?, WebElement> toSingleton() {
2930
return Collectors.collectingAndThen(
3031
Collectors.toList(),
3132
list -> {
3233
if (list.size() != 1) {
33-
throw new IllegalStateException("Expected single element, found: " + list.size());
34+
long uniqueLocations = list.stream().map(WebElement::getLocation).distinct().count();
35+
if (uniqueLocations == 1) {
36+
return list.get(0);
37+
}
38+
39+
throw new IllegalStateException("Expected single element, found: " + list.size() + ", " + list.stream().map(WebElement::getLocation).map(Point::toString).collect(Collectors.joining(" / ")));
3440
}
41+
3542
return list.get(0);
3643
}
3744
);
@@ -128,10 +135,19 @@ public static Locator.XPathLocator getTrackLocator(BaseWebDriverTest test, Strin
128135
}
129136

130137
public static By getVariantWithinTrack(BaseWebDriverTest test, String trackId, String variantText)
138+
{
139+
return getVariantWithinTrack(test, trackId, variantText, true);
140+
}
141+
142+
public static By getVariantWithinTrack(BaseWebDriverTest test, String trackId, String variantText, boolean appendPolygon)
131143
{
132144
Locator.XPathLocator l = getTrackLocator(test, trackId, true);
133145
test.waitForElementToDisappear(Locator.tagWithText("p", "Loading"));
134-
l = l.append(Locator.xpath("//*[name()='text' and contains(text(), '" + variantText + "')]")).notHidden().append("/..");
146+
l = l.append(Locator.xpath("//*[name()='text' and contains(text(), '" + variantText + "')]")).notHidden().parent();
147+
if (appendPolygon){
148+
l = l.append("/*[name()='polygon']");
149+
}
150+
135151
test.waitForElement(l);
136152

137153
return By.xpath(l.toXpath());
@@ -153,14 +169,16 @@ public static long getTotalVariantFeatures(BaseWebDriverTest test)
153169
Locator l = Locator.tagWithAttribute("svg", "data-testid", "svgfeatures").append(Locator.tag("polygon"));
154170
try
155171
{
156-
return Locator.findElements(test.getDriver(), l).stream().filter(WebElement::isDisplayed).count();
172+
// NOTE: JBrowse renders features using multiple blocks per track, and these tracks can redundantly render identical features on top of one another.
173+
// Counting unique locations is indirect, but should result in unique features
174+
return Locator.findElements(test.getDriver(), l).stream().filter(WebElement::isDisplayed).map(WebElement::getLocation).distinct().count();
157175
}
158176
catch (StaleElementReferenceException e)
159177
{
160178
test.log("Stale elements, retrying");
161179
WebDriverWrapper.sleep(5000);
162180

163-
return Locator.findElements(test.getDriver(), l).stream().filter(WebElement::isDisplayed).count();
181+
return Locator.findElements(test.getDriver(), l).stream().filter(WebElement::isDisplayed).map(WebElement::getLocation).distinct().count();
164182
}
165183
}
166184
}

0 commit comments

Comments
 (0)