Fix broken OutletTests, found and fixed bug with ancestor searching.
This commit is contained in:
parent
2b3cd3120c
commit
f6071909b6
@ -70,7 +70,10 @@ public class DefaultComponentContext implements ComponentContext {
|
|||||||
public @Nullable ViewComponent findNearestAncestor(Predicate<? super ViewComponent> matching) {
|
public @Nullable ViewComponent findNearestAncestor(Predicate<? super ViewComponent> matching) {
|
||||||
final List<ViewComponent> componentStack = this.getRenderContext().getComponentStack();
|
final List<ViewComponent> componentStack = this.getRenderContext().getComponentStack();
|
||||||
if (componentStack.size() > 1) {
|
if (componentStack.size() > 1) {
|
||||||
for (final var ancestor : componentStack.subList(1, componentStack.size() - 1)) {
|
// 1/27/25: earlier this was originally componentStack.size() - 1 as the second argument to sublist().
|
||||||
|
// On examination today, it didn't make sense, because it would be chopping off the farthest ancestor from
|
||||||
|
// search. So I removed it, in accordance with the implementation in hasAncestor().
|
||||||
|
for (final var ancestor : componentStack.subList(1, componentStack.size())) {
|
||||||
if (matching.test(ancestor)) {
|
if (matching.test(ancestor)) {
|
||||||
return ancestor;
|
return ancestor;
|
||||||
}
|
}
|
||||||
@ -83,7 +86,7 @@ public class DefaultComponentContext implements ComponentContext {
|
|||||||
public boolean hasAncestor(Predicate<? super ViewComponent> matching) {
|
public boolean hasAncestor(Predicate<? super ViewComponent> matching) {
|
||||||
final List<ViewComponent> componentStack = this.getRenderContext().getComponentStack();
|
final List<ViewComponent> componentStack = this.getRenderContext().getComponentStack();
|
||||||
if (componentStack.size() > 1) {
|
if (componentStack.size() > 1) {
|
||||||
for (final var ancestor : componentStack.subList(1, componentStack.size() - 1)) {
|
for (final var ancestor : componentStack.subList(1, componentStack.size())) {
|
||||||
if (matching.test(ancestor)) {
|
if (matching.test(ancestor)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,35 @@
|
|||||||
package groowt.view.component.web.lib
|
package groowt.view.component.web.lib
|
||||||
|
|
||||||
|
|
||||||
|
import groowt.view.component.web.WebViewComponentContext
|
||||||
|
import groowt.view.component.web.WebViewComponentScope
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
class OutletTests extends AbstractWebViewComponentTests {
|
class OutletTests extends AbstractWebViewComponentTests {
|
||||||
|
|
||||||
|
static final class DummyOutletContainer extends Echo implements OutletContainer {
|
||||||
|
|
||||||
|
DummyOutletContainer() {
|
||||||
|
super([:])
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void configureContext(WebViewComponentContext context) {
|
||||||
|
context.configureRootScope(WebViewComponentScope) {
|
||||||
|
addWithNoArgConstructor(DummyOutletContainer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void smokeScreen() {
|
void smokeScreen() {
|
||||||
doTest('<Outlet />', '')
|
doTest('<OutletTests.DummyOutletContainer><Outlet /></OutletTests.DummyOutletContainer>', '')
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void withChildren() {
|
void withChildren() {
|
||||||
doTest('<Echo items={[0, 1, 2]}><Outlet children={items} /></Echo>', '012')
|
doTest('<OutletTests.DummyOutletContainer><Echo items={[0, 1, 2]}><Outlet children={items} /></Echo></OutletTests.DummyOutletContainer>', '012')
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user