Skip to content

Commit 64de3fb

Browse files
committed
Fix UI tests :)
1 parent 42771b6 commit 64de3fb

File tree

18 files changed

+557
-493
lines changed

18 files changed

+557
-493
lines changed

forge/src/test/java/fr/thesmyler/terramap/TerramapTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package fr.thesmyler.terramap;
22

3-
import fr.thesmyler.smylibgui.SmyLibGuiTest;
43
import fr.thesmyler.terramap.maps.raster.MapStylesLibrary;
4+
import net.smyler.smylib.SmyLibTest;
55
import org.apache.logging.log4j.LogManager;
66
import org.junit.jupiter.api.BeforeEach;
77

8-
public class TerramapTest extends SmyLibGuiTest {
8+
public class TerramapTest extends SmyLibTest {
99

1010
@BeforeEach
1111
public void initTerramap() {

forge/src/test/java/fr/thesmyler/terramap/gui/widgets/map/MapControllerTest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package fr.thesmyler.terramap.gui.widgets.map;
22

3-
import net.smyler.smylib.gui.TestingWidgetContainer;
3+
import net.smyler.smylib.game.TestGameClient;
44
import fr.thesmyler.terramap.MapContext;
55
import fr.thesmyler.terramap.TerramapTest;
6+
import net.smyler.smylib.gui.screen.Screen;
67
import net.smyler.smylib.math.Vec2dMutable;
78
import net.smyler.terramap.util.geo.GeoPointImmutable;
89
import org.junit.jupiter.api.BeforeEach;
@@ -15,16 +16,19 @@ public class MapControllerTest extends TerramapTest {
1516

1617
public static GeoPointImmutable PARIS = new GeoPointImmutable(2.350987d, 48.856667d);
1718

18-
private TestingWidgetContainer screen;
19+
private Screen screen;
1920
private MapWidget map;
2021
private MapController controller;
2122

2223
@BeforeEach
2324
public void setupMap() {
24-
this.screen = new TestingWidgetContainer(60, 1280f, 720f);
25+
TestGameClient client = this.getTestGameClient();
26+
client.setWindowDimensions(1280f, 720f);
27+
client.setTargetFps(60);
28+
this.screen = client.getCurrentScreen();
2529
this.map = new MapWidget(-4f, -2f, 10, 141f, 83f, MapContext.MINIMAP, 2.0f);
2630
this.screen.addWidget(this.map);
27-
this.controller = map.getController();
31+
this.controller = this.map.getController();
2832
}
2933

3034

forge/src/test/java/fr/thesmyler/terramap/gui/widgets/map/MapWidgetTest.java

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
package fr.thesmyler.terramap.gui.widgets.map;
22

33
import com.google.gson.JsonPrimitive;
4-
import net.smyler.smylib.gui.TestingWidgetContainer;
4+
import net.smyler.smylib.game.TestGameClient;
55
import fr.thesmyler.terramap.TerramapTest;
66
import fr.thesmyler.terramap.gui.widgets.map.layer.OnlineRasterMapLayer;
77
import fr.thesmyler.terramap.gui.widgets.map.layer.RasterMapLayer;
88
import fr.thesmyler.terramap.maps.SavedLayerState;
99
import fr.thesmyler.terramap.maps.SavedMapState;
1010
import fr.thesmyler.terramap.maps.raster.MapStylesLibrary;
11+
import net.smyler.smylib.gui.screen.Screen;
1112
import net.smyler.smylib.math.Vec2dImmutable;
1213
import net.smyler.terramap.util.geo.GeoPointImmutable;
1314
import org.junit.jupiter.api.Test;
1415

1516
import static fr.thesmyler.terramap.MapContext.FULLSCREEN;
1617
import static fr.thesmyler.terramap.gui.widgets.map.MapLayerRegistry.RASTER_LAYER_ID;
1718
import static net.smyler.terramap.util.geo.GeoPointImmutable.ORIGIN;
19+
import static fr.thesmyler.terramap.Assertions.*;
1820
import static org.junit.jupiter.api.Assertions.*;
1921

2022
class MapWidgetTest extends TerramapTest {
@@ -23,9 +25,11 @@ class MapWidgetTest extends TerramapTest {
2325

2426
@Test
2527
void canSaveMapWidgetToSavedMapState() throws InterruptedException {
26-
TestingWidgetContainer screen = new TestingWidgetContainer(60, 500f, 500f);
28+
TestGameClient client = this.getTestGameClient();
29+
client.setWindowDimensions(500f, 500f);
30+
client.setTargetFps(60);
2731
MapWidget map = new MapWidget(0f, 0f, 0, 500f, 500f, FULLSCREEN, 1f);
28-
screen.addWidget(map);
32+
client.getCurrentScreen().addWidget(map);
2933
OnlineRasterMapLayer raster_osm = (OnlineRasterMapLayer) map.createLayer(RASTER_LAYER_ID);
3034
OnlineRasterMapLayer osm_fr_hot = (OnlineRasterMapLayer) map.createLayer(RASTER_LAYER_ID);
3135
raster_osm.setTiledMap(MapStylesLibrary.getBaseMaps().get("osm"));
@@ -39,10 +43,10 @@ void canSaveMapWidgetToSavedMapState() throws InterruptedException {
3943

4044
map.getController().setZoom(10, false);
4145
map.getController().setRotation(45f, false);
42-
screen.doTick();
46+
client.doTick();
4347

4448
map.getController().moveLocationToCenter(PARIS, false);
45-
screen.doTick();
49+
client.doTick();
4650

4751
SavedMapState saved = map.save();
4852

@@ -71,9 +75,13 @@ void canSaveMapWidgetToSavedMapState() throws InterruptedException {
7175
@Test
7276
public void canRestoreMapState() throws InterruptedException {
7377

74-
TestingWidgetContainer screen = new TestingWidgetContainer(60, 500f, 500f);
78+
TestGameClient client = this.getTestGameClient();
79+
client.setWindowDimensions(500f, 500f);
80+
client.setTargetFps(60);
81+
Screen screen = client.getCurrentScreen();
82+
7583
MapWidget map = new MapWidget(0f, 0f, 0, 500f, 500f, FULLSCREEN, 1f);
76-
screen.moveMouse(750, 750, 1000);
84+
client.moveMouse(750, 750, 1000);
7785
screen.addWidget(map);
7886

7987
// Let's start in some random state
@@ -83,9 +91,9 @@ public void canRestoreMapState() throws InterruptedException {
8391
map.setLayerZ(rasterLayer, -1);
8492
map.getController().setZoomStaticLocation(PARIS);
8593
map.getController().setZoom(18, true);
86-
screen.runFor(1000);
94+
client.runFor(1000);
8795
map.getController().moveLocationToCenter(PARIS, true);
88-
screen.runFor(1000);
96+
client.runFor(1000);
8997
map.getController().setRotationStaticLocation(PARIS);
9098
map.getController().setRotation(45f, true);
9199

@@ -101,7 +109,7 @@ public void canRestoreMapState() throws InterruptedException {
101109

102110
// And we try restoring...
103111
map.restore(state);
104-
screen.doTick();
112+
client.doTick();
105113

106114
assertEquals(ORIGIN, map.getController().getCenterLocation().getImmutable());
107115
assertEquals(0, map.getController().getZoom());
@@ -117,9 +125,14 @@ public void canRestoreMapState() throws InterruptedException {
117125
@Test
118126
public void canRestoreMapStateWithInvalidLayerId() throws InterruptedException {
119127

120-
TestingWidgetContainer screen = new TestingWidgetContainer(60, 500f, 500f);
128+
TestGameClient client = this.getTestGameClient();
129+
client.setWindowDimensions(500f, 500f);
130+
client.setTargetFps(60);
131+
132+
Screen screen = client.getCurrentScreen();
133+
121134
MapWidget map = new MapWidget(0f, 0f, 0, 500f, 500f, FULLSCREEN, 1f);
122-
screen.moveMouse(750, 750, 1000);
135+
client.moveMouse(750, 750, 1000);
123136
screen.addWidget(map);
124137

125138
SavedMapState state = new SavedMapState();
@@ -128,7 +141,7 @@ public void canRestoreMapStateWithInvalidLayerId() throws InterruptedException {
128141
state.layers.add(layerState);
129142

130143
map.restore(state);
131-
screen.doTick();
144+
client.doTick();
132145

133146
}
134147

smylib/core/src/main/java/net/smyler/smylib/gui/screen/PopupScreen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public abstract class PopupScreen extends Screen {
1515

1616
private final Popup popup;
1717

18-
public PopupScreen(Popup popup) {
18+
PopupScreen(Popup popup) {
1919
super(BackgroundOption.NONE);
2020
this.popup = popup;
2121
this.addWidget(popup);
Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package net.smyler.smylib.gui.widgets;
22

3-
import net.smyler.smylib.gui.TestingWidgetContainer;
3+
import net.smyler.smylib.game.TestGameClient;
44
import net.smyler.smylib.SmyLibTest;
55
import net.smyler.smylib.game.Key;
6-
import net.smyler.smylib.gui.widgets.ColorPickerWidget;
6+
import net.smyler.smylib.gui.screen.Screen;
77
import org.junit.jupiter.api.Test;
88

99
import java.util.concurrent.atomic.AtomicBoolean;
@@ -48,68 +48,62 @@ void canDealWithCustomOnTextChangedCallback() {
4848

4949
@Test
5050
void canInputColors() throws InterruptedException {
51-
//TODO repair ColorPickerWidgetTest
52-
/*
53-
TestingWidgetContainer container = new TestingWidgetContainer(30, 500f, 500f);
51+
TestGameClient client = this.getTestGameClient();
52+
Screen container = client.getCurrentScreen();
5453
ColorPickerWidget colorPicker = new ColorPickerWidget(0, 0, 0, BLACK, getGameClient().defaultFont());
5554
container.addWidget(colorPicker);
5655

5756
// Focus the widget and move cursor to the right
58-
container.moveMouse(10f, 10f, 500);
59-
container.click(0);
57+
client.moveMouse(10f, 10f, 500);
58+
client.click(0);
6059
for (int i = 0; i < 10; i++) {
61-
container.pressKey((char)Key.KEY_RIGHT.code, Key.KEY_RIGHT);
62-
container.doTick();
60+
client.pressKey((char)Key.KEY_RIGHT.code, Key.KEY_RIGHT);
61+
client.doTick();
6362
}
6463

65-
container.pressKey((char) Key.KEY_BACK.code, Key.KEY_BACK);
66-
container.doTick();
67-
container.pressKey((char) Key.KEY_BACK.code, Key.KEY_BACK);
68-
container.doTick();
69-
container.pressKey((char) Key.KEY_BACK.code, Key.KEY_BACK);
70-
container.doTick();
64+
client.pressKey((char) Key.KEY_BACK.code, Key.KEY_BACK);
65+
client.doTick();
66+
client.pressKey((char) Key.KEY_BACK.code, Key.KEY_BACK);
67+
client.doTick();
68+
client.pressKey((char) Key.KEY_BACK.code, Key.KEY_BACK);
69+
client.doTick();
7170

7271
assertFalse(colorPicker.hasValidColor());
7372
assertEquals("#000", colorPicker.getText());
7473

75-
container.pressKey((char) Key.KEY_BACK.code, Key.KEY_BACK);
76-
container.doTick();
77-
container.pressKey((char) Key.KEY_BACK.code, Key.KEY_BACK);
78-
container.doTick();
79-
container.pressKey((char) Key.KEY_BACK.code, Key.KEY_BACK);
80-
container.doTick();
74+
client.pressKey((char) Key.KEY_BACK.code, Key.KEY_BACK);
75+
client.doTick();
76+
client.pressKey((char) Key.KEY_BACK.code, Key.KEY_BACK);
77+
client.doTick();
78+
client.pressKey((char) Key.KEY_BACK.code, Key.KEY_BACK);
79+
client.doTick();
8180

8281
assertFalse(colorPicker.hasValidColor());
8382
assertEquals("#", colorPicker.getText());
8483

85-
container.pressKey('F', Key.KEY_F);
86-
container.doTick();
87-
container.pressKey('F', Key.KEY_F);
88-
container.doTick();
89-
container.pressKey('0', Key.KEY_0);
90-
container.doTick();
91-
container.pressKey('0', Key.KEY_0);
92-
container.doTick();
93-
container.pressKey('0', Key.KEY_0);
94-
container.doTick();
95-
container.pressKey('0', Key.KEY_0);
96-
container.doTick();
84+
client.pressKey('F', Key.KEY_F);
85+
client.doTick();
86+
client.pressKey('F', Key.KEY_F);
87+
client.doTick();
88+
client.pressKey('0', Key.KEY_0);
89+
client.doTick();
90+
client.pressKey('0', Key.KEY_0);
91+
client.doTick();
92+
client.pressKey('0', Key.KEY_0);
93+
client.doTick();
94+
client.pressKey('0', Key.KEY_0);
95+
client.doTick();
9796

9897
assertTrue(colorPicker.hasValidColor());
9998
assertEquals(RED, colorPicker.getColor());
10099

101-
container.pressKey('F', Key.KEY_F);
102-
container.doTick();
103-
container.pressKey('F', Key.KEY_F);
104-
container.doTick();
100+
client.pressKey('F', Key.KEY_F);
101+
client.doTick();
102+
client.pressKey('F', Key.KEY_F);
103+
client.doTick();
105104

106105
assertTrue(colorPicker.hasValidColor());
107106
assertEquals(RED, colorPicker.getColor());
108-
*/
109-
}
110-
111-
@Test
112-
void setOnColorChange() {
113107
}
114108

115109
}

smylib/core/src/test/java/net/smyler/smylib/gui/widgets/buttons/TextButtonWidgetTest.java

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33

44
import net.smyler.smylib.SmyLibTest;
5-
import net.smyler.smylib.gui.TestingWidgetContainer;
5+
import net.smyler.smylib.game.TestGameClient;
6+
import net.smyler.smylib.gui.screen.Screen;
67
import org.junit.jupiter.api.Test;
78

89
import java.util.concurrent.atomic.AtomicInteger;
@@ -15,43 +16,44 @@ public class TextButtonWidgetTest extends SmyLibTest {
1516
@Test
1617
public void testActivation() throws InterruptedException {
1718
AtomicInteger clickCounter = new AtomicInteger();
18-
TestingWidgetContainer screen = new TestingWidgetContainer(30, 400, 300);
19+
TestGameClient client = this.getTestGameClient();
20+
Screen screen = this.getTestGameClient().getCurrentScreen();
1921
TextButtonWidget button = new TextButtonWidget(10, 10, 0, 200, "Test button", clickCounter::incrementAndGet);
2022
screen.addWidget(button);
2123

2224
assertNull(screen.getFocusedWidget());
2325

24-
screen.moveMouse(30, 30, 500);
25-
screen.click(0);
26-
screen.doTick();
27-
screen.doTick(); // We are giving it a frame to lose focus
26+
client.moveMouse(30, 30, 500);
27+
client.click(0);
28+
client.doTick();
29+
client.doTick(); // We are giving it a frame to lose focus
2830
assertEquals(1, clickCounter.get());
2931
assertNull(screen.getFocusedWidget());
3032

31-
screen.doubleClick(0);
32-
screen.doTick();
33-
screen.doTick();
33+
client.doubleClick(0);
34+
client.doTick();
35+
client.doTick();
3436
assertEquals(3, clickCounter.get());
3537
assertNull(screen.getFocusedWidget());
3638

37-
screen.moveMouse(1, 1, 500);
38-
screen.click(0);
39-
screen.doTick();
40-
screen.doTick();
39+
client.moveMouse(1, 1, 500);
40+
client.click(0);
41+
client.doTick();
42+
client.doTick();
4143
assertEquals(3, clickCounter.get());
4244
assertNull(screen.getFocusedWidget());
4345

44-
screen.moveMouse(30, 30, 500);
45-
screen.click(0);
46-
screen.doTick();
47-
screen.doTick();
46+
client.moveMouse(30, 30, 500);
47+
client.click(0);
48+
client.doTick();
49+
client.doTick();
4850
assertEquals(4, clickCounter.get());
4951
assertNull(screen.getFocusedWidget());
5052

5153
button.setEnabled(false);
52-
screen.click(0);
53-
screen.doTick();
54-
screen.doTick();
54+
client.click(0);
55+
client.doTick();
56+
client.doTick();
5557
assertEquals(4, clickCounter.get());
5658
assertNull(screen.getFocusedWidget());
5759
}

smylib/core/src/test/java/net/smyler/smylib/gui/widgets/sliders/OptionSliderWidgetTest.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package net.smyler.smylib.gui.widgets.sliders;
22

3-
import net.smyler.smylib.gui.TestingWidgetContainer;
43
import net.smyler.smylib.SmyLibTest;
5-
import org.junit.jupiter.api.Test;
6-
7-
import static org.junit.jupiter.api.Assertions.*;
84

95
public class OptionSliderWidgetTest extends SmyLibTest {
106

smylib/core/src/test/java/net/smyler/smylib/gui/widgets/text/TextFieldWidgetTest.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
package net.smyler.smylib.gui.widgets.text;
22

3-
import net.smyler.smylib.gui.TestingWidgetContainer;
43
import net.smyler.smylib.SmyLibTest;
5-
import net.smyler.smylib.game.Key;
6-
import net.smyler.smylib.gui.DummyFont;
7-
import net.smyler.smylib.gui.widgets.text.TextFieldWidget;
84
import org.junit.jupiter.api.Test;
95

10-
import static org.junit.jupiter.api.Assertions.*;
11-
126
public class TextFieldWidgetTest extends SmyLibTest {
137

148
@Test

smylib/forge/src/main/java/net/smyler/smylib/game/WrappedMinecraft.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
1010
import net.smyler.smylib.gui.*;
1111
import net.smyler.smylib.gui.popups.Popup;
12-
import net.smyler.smylib.gui.popups.PopupScreenImplementation;
12+
import net.smyler.smylib.gui.screen.PopupScreenImplementation;
1313
import net.smyler.smylib.gui.screen.*;
1414
import net.smyler.smylib.gui.sprites.SpriteLibrary;
1515

0 commit comments

Comments
 (0)