WiFiManager: stabilize root rendering and reduce page reallocations.

Keep root template state request-scoped so dynamic placeholders stay consistent during chunked renders, add reserve() coverage for non-streamed pages, and add compile/test coverage for the new root render lifecycle.
This commit is contained in:
2026-04-16 20:54:03 +10:00
parent bb1008435f
commit 9f111ab8bd
7 changed files with 239 additions and 14 deletions
+2
View File
@@ -30,6 +30,8 @@ TestCase tests[] = {
TEST_ENTRY(test_config_portal_multiple_start_stop),
TEST_ENTRY(test_config_portal_already_active),
TEST_ENTRY(test_get_config_portal_ssid),
TEST_ENTRY(test_root_render_menu_state_transitions),
TEST_ENTRY(test_root_render_snapshot_consistency),
// Non-blocking tests
TEST_ENTRY(test_nonblocking_process),
+2
View File
@@ -40,6 +40,8 @@ void test_stop_web_portal();
void test_config_portal_multiple_start_stop();
void test_config_portal_already_active();
void test_get_config_portal_ssid();
void test_root_render_menu_state_transitions();
void test_root_render_snapshot_consistency();
// Non-blocking tests
void test_nonblocking_process();
@@ -0,0 +1,64 @@
#include <unity.h>
#include <Arduino.h>
#include <WiFiManager.h>
#include <WiFiManagerHandlers.h>
void test_root_render_menu_state_transitions() {
Serial.println("[TEST] Testing root menu state transitions...");
WiFiManager wm;
WiFiManagerHandlers handlers(&wm);
String menuBefore;
handlers.getMenuOut(&menuBefore);
TEST_ASSERT_EQUAL(-1, menuBefore.indexOf("/close"));
wm.setConfigPortalTimeout(5);
wm.startConfigPortal("RootStateAP");
wm.process();
delay(100);
String menuActive;
handlers.getMenuOut(&menuActive);
TEST_ASSERT_NOT_EQUAL(-1, menuActive.indexOf("/close"));
wm.stopConfigPortal();
delay(100);
String menuAfter;
handlers.getMenuOut(&menuAfter);
TEST_ASSERT_EQUAL(-1, menuAfter.indexOf("/close"));
Serial.println("[TEST] Root menu state transitions test completed successfully");
}
void test_root_render_snapshot_consistency() {
Serial.println("[TEST] Testing root render snapshot consistency...");
WiFiManager wm;
WiFiManagerHandlers handlers(&wm);
wm.setConfigPortalTimeout(5);
wm.startConfigPortal("RootSnapshotAP");
wm.process();
delay(100);
String menuSnapshot1;
String statusSnapshot1;
handlers.getMenuOut(&menuSnapshot1);
handlers.reportStatus(statusSnapshot1);
String menuSnapshot2;
String statusSnapshot2;
handlers.getMenuOut(&menuSnapshot2);
handlers.reportStatus(statusSnapshot2);
TEST_ASSERT_GREATER_THAN(0, menuSnapshot1.length());
TEST_ASSERT_GREATER_THAN(0, statusSnapshot1.length());
TEST_ASSERT_EQUAL_STRING(menuSnapshot1.c_str(), menuSnapshot2.c_str());
TEST_ASSERT_EQUAL_STRING(statusSnapshot1.c_str(), statusSnapshot2.c_str());
wm.stopConfigPortal();
Serial.println("[TEST] Root render snapshot consistency test completed successfully");
}