Skip to content

Commit

Permalink
test(framework): Add tests for history
Browse files Browse the repository at this point in the history
  • Loading branch information
LeStegii committed Feb 27, 2024
1 parent d3ee915 commit cdcba0c
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private Pair<Object, Parent> navigate(Pair<Either<TraversableNodeTree.Node<Field

Object controller = either.isLeft() ?
ReflectionUtil.getInstanceOfProviderField(either.getLeft().orElseThrow().value(), this.routerObject) :
either.getRight();
either.getRight().orElseThrow();

return new Pair<>(controller, this.manager.get().initAndRender(
controller,
Expand Down
37 changes: 37 additions & 0 deletions framework/src/test/java/org/fulib/fx/app/FrameworkTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.fulib.fx.app;

import org.fulib.fx.FulibFxApp;
import org.fulib.fx.app.history.AController;
import org.fulib.fx.app.history.BController;
import org.fulib.fx.app.history.CController;
import org.fulib.fx.app.modal.ModalComponent;
import org.fulib.fx.app.controllertypes.sub.ButtonSubComponent;
import org.fulib.fx.controller.Modals;
Expand Down Expand Up @@ -183,4 +186,38 @@ public void params() {
assertEquals(true, controller.getSetterMultiParams2());
}

@Test
public void history() {
app.show(new AController(), Map.of("string", "a"));
verifyThat("A:a", Node::isVisible);

app.show(new BController(), Map.of("string", "b"));
verifyThat("B:b", Node::isVisible);

app.show(new CController(), Map.of("string", "c"));
verifyThat("C:c", Node::isVisible);

app.back();
verifyThat("B:b", Node::isVisible);

app.back();
verifyThat("A:a", Node::isVisible);

app.forward();
verifyThat("B:b", Node::isVisible);

app.forward();
verifyThat("C:c", Node::isVisible);

app.forward();
verifyThat("C:c", Node::isVisible); // should not change

app.back();
verifyThat("B:b", Node::isVisible);

FulibFxApp.FX_SCHEDULER.scheduleDirect(app::refresh);
waitForFxEvents();
verifyThat("B:b", Node::isVisible);
}

}
25 changes: 25 additions & 0 deletions framework/src/test/java/org/fulib/fx/app/history/AController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.fulib.fx.app.history;

import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import org.fulib.fx.annotation.controller.Controller;
import org.fulib.fx.annotation.event.onRender;
import org.fulib.fx.annotation.param.Param;

@Controller(view = "#render")
public class AController {

Label label = new Label();

public AController() {
}

public VBox render() {
return new VBox(label);
}

@onRender
public void onRender(@Param("string") String string) {
label.setText("A:" + string);
}
}
25 changes: 25 additions & 0 deletions framework/src/test/java/org/fulib/fx/app/history/BController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.fulib.fx.app.history;

import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import org.fulib.fx.annotation.controller.Controller;
import org.fulib.fx.annotation.event.onRender;
import org.fulib.fx.annotation.param.Param;

@Controller(view = "#render")
public class BController {

Label label = new Label();

public BController() {
}

public VBox render() {
return new VBox(label);
}

@onRender
public void onRender(@Param("string") String string) {
label.setText("B:" + string);
}
}
25 changes: 25 additions & 0 deletions framework/src/test/java/org/fulib/fx/app/history/CController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.fulib.fx.app.history;

import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import org.fulib.fx.annotation.controller.Controller;
import org.fulib.fx.annotation.event.onRender;
import org.fulib.fx.annotation.param.Param;

@Controller(view = "#render")
public class CController {

Label label = new Label();

public CController() {
}

public VBox render() {
return new VBox(label);
}

@onRender
public void onRender(@Param("string") String string) {
label.setText("C:" + string);
}
}

0 comments on commit cdcba0c

Please sign in to comment.