Files
twislaandClaude Opus 5.5 51698a8011 M0 step 7: Settings, About, Storage, first-boot setup
- lib/apps_model (host-tested): SettingsMenu (rows, readable values,
  choices, validation messages) and SetupWizard (names, Region
  confirmation, timezone; saves only when finished)
- AppManager: modal Apps that Home/Back can't leave (setup wizard)
- SettingsApp: all settings plus Storage (usage, erase SD behind a
  dialog) and About (version, node id, battery, memory, uptime) pages,
  replacing the temporary Diagnostics App
- SetupApp: first-boot wizard, opened modally until SetupDone
- Node id and default names derived from the MAC like Meshtastic
- Widget demo is now hidden (About, then w)
- lib_ldf_mode = deep+ so libraries see each other's headers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
2026-10-02 13:47:03 +02:00

122 lines
4.0 KiB
C++

#include <unity.h>
#include "../memory_store.h"
#include "event_bus.h"
#include "setup_wizard.h"
using namespace roro;
struct Fixture {
MemoryStore store;
EventBus bus;
Settings settings{store, bus};
SetupWizard wizard{settings, "roro9stack 2fa4", "2fa4"};
Fixture() { settings.load(); }
};
using Step = SetupWizard::Step;
void setUp() {}
void tearDown() {}
static void assertStep(Step expected, const SetupWizard& w) {
TEST_ASSERT_EQUAL(static_cast<int>(expected), static_cast<int>(w.step()));
}
void test_walks_through_every_step_with_defaults() {
Fixture f;
assertStep(Step::Welcome, f.wizard);
TEST_ASSERT_TRUE(f.wizard.next());
assertStep(Step::LongName, f.wizard);
TEST_ASSERT_EQUAL_STRING("roro9stack 2fa4", f.wizard.editor().text().c_str());
TEST_ASSERT_TRUE(f.wizard.next());
assertStep(Step::ShortName, f.wizard);
TEST_ASSERT_EQUAL_STRING("2fa4", f.wizard.editor().text().c_str());
TEST_ASSERT_TRUE(f.wizard.next());
assertStep(Step::Region, f.wizard);
TEST_ASSERT_TRUE(f.wizard.next());
assertStep(Step::Timezone, f.wizard);
TEST_ASSERT_TRUE(f.wizard.next());
assertStep(Step::Done, f.wizard);
TEST_ASSERT_FALSE(f.wizard.finished());
TEST_ASSERT_TRUE(f.wizard.next());
TEST_ASSERT_TRUE(f.wizard.finished());
}
void test_nothing_is_saved_until_the_end() {
Fixture f;
for (int i = 0; i < 5; i++) f.wizard.next();
TEST_ASSERT_FALSE(f.settings.getBool(Setting::SetupDone));
TEST_ASSERT_FALSE(f.settings.getBool(Setting::RegionConfirmed));
TEST_ASSERT_TRUE(f.store.ints.empty() && f.store.strings.empty());
}
void test_finishing_saves_names_region_timezone_and_marks_setup_done() {
Fixture f;
f.wizard.next();
f.wizard.editor().setText("Cl\xC3\xA9ment");
f.wizard.next();
f.wizard.editor().setText("CLEM");
f.wizard.next();
f.wizard.next(); // region
f.wizard.selectChoice(1); // second timezone
f.wizard.next();
f.wizard.next();
TEST_ASSERT_EQUAL_STRING("Cl\xC3\xA9ment", f.settings.getString(Setting::LongName).c_str());
TEST_ASSERT_EQUAL_STRING("CLEM", f.settings.getString(Setting::ShortName).c_str());
TEST_ASSERT_EQUAL_STRING("EU868", f.settings.getString(Setting::Region).c_str());
TEST_ASSERT_TRUE(f.settings.getBool(Setting::RegionConfirmed));
TEST_ASSERT_TRUE(f.settings.getBool(Setting::SetupDone));
TEST_ASSERT_TRUE(f.settings.getString(Setting::Timezone) != "CET-1CEST,M3.5.0,M10.5.0/3");
}
void test_empty_name_cannot_advance_and_explains_why() {
Fixture f;
f.wizard.next();
f.wizard.editor().setText("");
TEST_ASSERT_FALSE(f.wizard.next());
assertStep(Step::LongName, f.wizard);
TEST_ASSERT_FALSE(f.wizard.error().empty());
}
void test_short_name_editor_is_limited_to_four_bytes() {
Fixture f;
f.wizard.next();
f.wizard.next();
TEST_ASSERT_EQUAL(4, f.wizard.editor().maxBytes());
}
void test_back_returns_to_the_previous_step_keeping_input() {
Fixture f;
f.wizard.next();
f.wizard.editor().setText("Alice");
f.wizard.next();
f.wizard.back();
assertStep(Step::LongName, f.wizard);
TEST_ASSERT_EQUAL_STRING("Alice", f.wizard.editor().text().c_str());
f.wizard.back();
f.wizard.back();
assertStep(Step::Welcome, f.wizard);
}
void test_region_step_offers_eu868() {
Fixture f;
f.wizard.next();
f.wizard.next();
f.wizard.next();
TEST_ASSERT_EQUAL(1, f.wizard.choiceCount());
TEST_ASSERT_TRUE(f.wizard.choiceLabel(0).find("EU868") != std::string::npos);
}
int main() {
UNITY_BEGIN();
RUN_TEST(test_walks_through_every_step_with_defaults);
RUN_TEST(test_nothing_is_saved_until_the_end);
RUN_TEST(test_finishing_saves_names_region_timezone_and_marks_setup_done);
RUN_TEST(test_empty_name_cannot_advance_and_explains_why);
RUN_TEST(test_short_name_editor_is_limited_to_four_bytes);
RUN_TEST(test_back_returns_to_the_previous_step_keeping_input);
RUN_TEST(test_region_step_offers_eu868);
return UNITY_END();
}