1717package com .djrapitops .plan .delivery .webserver ;
1818
1919import com .djrapitops .plan .PlanSystem ;
20+ import com .djrapitops .plan .component .Component ;
21+ import com .djrapitops .plan .component .ComponentService ;
22+ import com .djrapitops .plan .extension .DataExtension ;
23+ import com .djrapitops .plan .extension .annotation .ComponentProvider ;
24+ import com .djrapitops .plan .extension .annotation .PluginInfo ;
2025import com .djrapitops .plan .gathering .domain .DataMap ;
2126import com .djrapitops .plan .gathering .domain .FinishedSession ;
2227import com .djrapitops .plan .identification .ServerUUID ;
23- import com .djrapitops .plan .settings .config .PlanConfig ;
24- import com .djrapitops .plan .settings .config .paths .DisplaySettings ;
25- import com .djrapitops .plan .settings .config .paths .ProxySettings ;
2628import com .djrapitops .plan .settings .config .paths .WebserverSettings ;
27- import com .djrapitops .plan .settings .locale .LangCode ;
2829import com .djrapitops .plan .settings .locale .Locale ;
2930import com .djrapitops .plan .storage .database .DBSystem ;
3031import com .djrapitops .plan .storage .database .Database ;
3132import com .djrapitops .plan .storage .database .transactions .events .PlayerRegisterTransaction ;
3233import com .djrapitops .plan .storage .database .transactions .events .StoreSessionTransaction ;
3334import com .djrapitops .plan .storage .database .transactions .events .StoreWorldNameTransaction ;
35+ import extension .FullSystemExtension ;
3436import extension .SeleniumExtension ;
37+ import org .intellij .lang .annotations .Language ;
3538import org .junit .jupiter .api .*;
3639import org .junit .jupiter .api .extension .ExtendWith ;
37- import org .junit .jupiter .api .io .TempDir ;
3840import org .junit .jupiter .params .ParameterizedTest ;
3941import org .junit .jupiter .params .provider .CsvSource ;
4042import org .openqa .selenium .By ;
4446import org .openqa .selenium .logging .LogType ;
4547import utilities .RandomData ;
4648import utilities .TestConstants ;
47- import utilities .mocks .PluginMockComponent ;
4849
49- import java .nio .file .Path ;
5050import java .util .*;
51- import java .util .stream .Collectors ;
51+ import java .util .stream .Stream ;
5252
5353import static com .djrapitops .plan .delivery .export .ExportTestUtilities .assertNoLogs ;
5454
5858 * Errors may have been caused by:
5959 * - Javascript mistakes / build issues
6060 * - Missed console.log statements
61- * - Automatic formatting of plugin javascript (See https://github.com/plan-player-analytics/Plan/issues/820)
6261 * - Missing file definition in Mocker
6362 */
64- @ ExtendWith (SeleniumExtension .class )
63+ @ ExtendWith ({ FullSystemExtension . class , SeleniumExtension .class } )
6564class JSErrorRegressionTest {
6665
6766 private static final int TEST_PORT_NUMBER = 9091 ;
6867
69- public static PluginMockComponent component ;
70-
71- private static PlanSystem planSystem ;
72- private static ServerUUID serverUUID ;
73-
7468 @ BeforeAll
75- static void setUpClass (@ TempDir Path tempDir ) throws Exception {
76- component = new PluginMockComponent (tempDir );
77- planSystem = component .getPlanSystem ();
78-
79- PlanConfig config = planSystem .getConfigSystem ().getConfig ();
80- config .set (WebserverSettings .PORT , TEST_PORT_NUMBER );
81- config .set (ProxySettings .IP , "localhost:" + TEST_PORT_NUMBER );
82-
83- // Avoid accidentally DDoS:ing head image service during tests.
84- config .set (DisplaySettings .PLAYER_HEAD_IMG_URL , "data:image/png;base64,AA==" );
85-
86- planSystem .enable ();
87- serverUUID = planSystem .getServerInfo ().getServerUUID ();
88- savePlayerData ();
69+ static void setUpClass (PlanSystem system ) {
70+ system .getConfigSystem ().getConfig ()
71+ .set (WebserverSettings .PORT , TEST_PORT_NUMBER );
72+ system .enable ();
73+ savePlayerData (system );
8974 }
9075
91- private static void savePlayerData () {
92- DBSystem dbSystem = planSystem .getDatabaseSystem ();
76+ private static void savePlayerData (PlanSystem system ) {
77+ ServerUUID serverUUID = system .getServerInfo ().getServerUUID ();
78+ DBSystem dbSystem = system .getDatabaseSystem ();
9379 Database database = dbSystem .getDatabase ();
9480 UUID uuid = TestConstants .PLAYER_ONE_UUID ;
9581 database .executeTransaction (new PlayerRegisterTransaction (uuid , RandomData ::randomTime , TestConstants .PLAYER_ONE_NAME ));
@@ -99,9 +85,9 @@ private static void savePlayerData() {
9985 }
10086
10187 @ AfterAll
102- static void tearDownClass () {
103- if (planSystem != null ) {
104- planSystem .disable ();
88+ static void tearDownClass (PlanSystem system ) {
89+ if (system != null ) {
90+ system .disable ();
10591 }
10692 }
10793
@@ -111,7 +97,7 @@ void tearDownTest(WebDriver driver) {
11197 }
11298
11399 @ TestFactory
114- Collection <DynamicTest > javascriptRegressionTest (ChromeDriver driver ) {
100+ Collection <DynamicTest > javascriptRegressionTest (ChromeDriver driver , PlanSystem system ) {
115101 String [] addresses = new String []{
116102 "http://localhost:" + TEST_PORT_NUMBER + "/player/" + TestConstants .PLAYER_ONE_NAME ,
117103 "http://localhost:" + TEST_PORT_NUMBER + "/player/" + TestConstants .PLAYER_ONE_UUID_STRING ,
@@ -121,19 +107,29 @@ Collection<DynamicTest> javascriptRegressionTest(ChromeDriver driver) {
121107 "http://localhost:" + TEST_PORT_NUMBER + "/query"
122108 };
123109
124- LangCode [] languages = LangCode .values ();
125- return
126- Arrays .stream (addresses )
127- .map (link -> testAddress (link , driver ))
128- .collect (Collectors .toList ());
110+ return Arrays .stream (addresses )
111+ .map (link -> testAddress (link , driver , system ))
112+ .toList ();
129113 }
130114
131- private DynamicTest testAddress (String address , ChromeDriver driver ) {
115+ @ TestFactory
116+ Stream <DynamicTest > componentJsRegressionTest (ChromeDriver driver , PlanSystem system ) {
117+ system .getApiServices ().getExtensionService ()
118+ .register (new ComponentExtension ())
119+ .orElseThrow (AssertionError ::new )
120+ .updatePlayerData (TestConstants .PLAYER_ONE_UUID , TestConstants .PLAYER_ONE_NAME );
121+
122+ String address = "http://localhost:" + TEST_PORT_NUMBER + "/player/" + TestConstants .PLAYER_ONE_UUID_STRING + "/plugins/" + system .getServerInfo ().getServerIdentifier ().getName ().replaceAll (" " , "%20" );
123+ return Stream .of (testAddress (address , driver , system ));
124+ }
125+
126+ private DynamicTest testAddress (String address , ChromeDriver driver , PlanSystem system ) {
132127 return DynamicTest .dynamicTest ("Page should not log anything on js console: " + address , () -> {
133- Locale locale = planSystem .getLocaleSystem ().getLocale ();
128+ Locale locale = system .getLocaleSystem ().getLocale ();
134129 try {
135130 driver .get (address );
136- Thread .sleep (250 );
131+ SeleniumExtension .waitForPageLoadForSeconds (5 , driver );
132+ SeleniumExtension .waitForElementToBeVisible (By .className ("load-in" ), driver );
137133 assertNoLogs (driver .manage ().logs ().get (LogType .BROWSER ).getAll (), address );
138134 } finally {
139135 locale .clear (); // Reset locale after test
@@ -175,9 +171,78 @@ private List<String> getLinks(ChromeDriver driver, int attempt) {
175171 .filter (href -> href .contains ("localhost" ) && !href .contains ("logout" ))
176172 .map (href -> href .split ("#" )[0 ])
177173 .distinct ()
178- .collect ( Collectors . toList () );
179- } catch (StaleElementReferenceException e ) {
174+ .toList ();
175+ } catch (StaleElementReferenceException _ ) {
180176 return getLinks (driver , attempt + 1 );
181177 }
182178 }
179+
180+ @ PluginInfo (name = "Component-regression" )
181+ static class ComponentExtension implements DataExtension {
182+ @ ComponentProvider (text = "regression" )
183+ public Component component (UUID playerUUID ) {
184+ @ Language ("JSON" )
185+ String json = """
186+ {
187+ "extra": [
188+ {
189+ "color": "gray",
190+ "extra": [
191+ {
192+ "color": "#9D50BB",
193+ "extra": [
194+ {
195+ "color": "#914EB7",
196+ "extra": [
197+ {
198+ "color": "#864CB3",
199+ "extra": [
200+ {
201+ "color": "#7A4AAE",
202+ "extra": [
203+ {
204+ "color": "#6E48AA",
205+ "extra": [
206+ {
207+ "color": "gray",
208+ "extra": [
209+ {
210+ "color": "dark_aqua",
211+ "text": "Executive Advisor"
212+ }
213+ ],
214+ "text": "] "
215+ }
216+ ],
217+ "text": "f"
218+ }
219+ ],
220+ "text": "f"
221+ }
222+ ],
223+ "text": "a"
224+ }
225+ ],
226+ "text": "t"
227+ }
228+ ],
229+ "text": "S"
230+ }
231+ ],
232+ "text": "["
233+ }
234+ ],
235+ "text": " "
236+ }""" ;
237+ return ComponentService .getInstance ().fromJson (json );
238+ }
239+
240+ @ ComponentProvider (text = "regression2" )
241+ public Component component2 (UUID playerUUID ) {
242+ @ Language ("JSON" )
243+ String json2 = """
244+ {"color":"dark_aqua","text":"EA"}""" ;
245+ return ComponentService .getInstance ().fromJson (json2 );
246+ }
247+ }
183248}
0 commit comments