Skip to content

Commit

Permalink
Prevent callouts from being pull up to earlier blocks
Browse files Browse the repository at this point in the history
Closes gh-68
  • Loading branch information
wilkinsona committed Nov 18, 2022
1 parent 8e80121 commit 76472ed
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/main/js/site/tabs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 the original author or authors.
* Copyright 2021-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -59,7 +59,7 @@
function createTab(blockElement, tabsElement) {
const title = blockElement.querySelector(".title").textContent;
const content = blockElement.querySelectorAll(".content").item(0);
const colist = nextSibling(blockElement, ".colist");
const colist = nextSibling(blockElement, ".colist", ".listingblock");
if (colist) {
content.append(colist);
}
Expand All @@ -72,12 +72,15 @@
return { tabElement: tabElement, content: content };
}

function nextSibling(element, selector) {
function nextSibling(element, selector, stopSelector) {
let sibling = element.nextElementSibling;
while (sibling) {
if (sibling.matches(selector)) {
return sibling;
}
if (sibling.matches(stopSelector)) {
return;
}
sibling = sibling.nextElementSibling;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 the original author or authors.
* Copyright 2021-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -148,6 +148,15 @@ void secondaryBlockWithNoPrimary(@Source("secondaryBlockWithNoPrimary.adoc") Con
assertThat(secondaries).hasSize(1);
}

@Test
void tabsWithAndWithoutCallouts(@Source("tabsWithAndWithoutCallouts.adoc") ConvertedHtml html) throws IOException {
RemoteWebDriver driver = html.inWebBrowser(this.chrome);
List<WebElement> listings = driver.findElementsByCssSelector(".listingblock");
assertThat(listings).hasSize(3);
assertThatTabs(listings.get(0)).hasNoCalloutList();
assertThatTabs(listings.get(2)).hasDisplayedCalloutListContaining("Callout for tab one");
}

private static TabsAssert assertThatTabs(WebElement actual) {
return assertThat(new TabsAssert(actual));
}
Expand Down Expand Up @@ -186,6 +195,11 @@ TabsAssert hasDisplayedCalloutListContaining(String contained) {

}

TabsAssert hasNoCalloutList() {
assertThat(this.actual.findElements(By.cssSelector(".colist"))).isEmpty();
return this;
}

TabsAssert uponClicking(String item) {
List<WebElement> unselected = this.actual.findElements(By.cssSelector(".tab:not(.selected)"));
Optional<WebElement> match = unselected.stream().filter((element) -> element.getText().equals(item))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[source,indent=0,subs="verbatim,quotes",role="primary"]
.One
----
One without callout.
----

[source,indent=0,subs="verbatim,quotes",role="secondary"]
.Two
----
Two without callout.
----


[source,indent=0,subs="verbatim,quotes"]
.No Tabs
----
No tabs with callout <1>
----
<1> Callout without tab


[source,indent=0,subs="verbatim,quotes",role="primary"]
.One
----
One with callout <1>
----
<1> Callout for tab one

[source,indent=0,subs="verbatim,quotes",role="secondary"]
.Two
----
Two with callout <1>
----
<1> Callout for tab two

0 comments on commit 76472ed

Please sign in to comment.