Public Access
- 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
114 lines
4.3 KiB
C++
114 lines
4.3 KiB
C++
#include <unity.h>
|
|
|
|
#include "../memory_store.h"
|
|
#include "event_bus.h"
|
|
#include "settings_menu.h"
|
|
|
|
using namespace roro;
|
|
|
|
struct Fixture {
|
|
MemoryStore store;
|
|
EventBus bus;
|
|
Settings settings{store, bus};
|
|
SettingsMenu menu{settings};
|
|
Fixture() { settings.load(); }
|
|
int row(SettingsMenu::Row r) {
|
|
for (int i = 0; i < menu.count(); i++)
|
|
if (menu.row(i) == r) return i;
|
|
return -1;
|
|
}
|
|
};
|
|
|
|
void setUp() {}
|
|
void tearDown() {}
|
|
|
|
void test_every_row_has_a_label() {
|
|
Fixture f;
|
|
TEST_ASSERT_TRUE(f.menu.count() > 0);
|
|
for (int i = 0; i < f.menu.count(); i++) TEST_ASSERT_FALSE(f.menu.label(i).empty());
|
|
}
|
|
|
|
void test_values_are_human_readable() {
|
|
Fixture f;
|
|
TEST_ASSERT_EQUAL_STRING("60%", f.menu.value(f.row(SettingsMenu::Row::Brightness)).c_str());
|
|
TEST_ASSERT_EQUAL_STRING("30 s", f.menu.value(f.row(SettingsMenu::Row::DimTimeout)).c_str());
|
|
TEST_ASSERT_EQUAL_STRING("1 min", f.menu.value(f.row(SettingsMenu::Row::OffTimeout)).c_str());
|
|
TEST_ASSERT_EQUAL_STRING("On", f.menu.value(f.row(SettingsMenu::Row::Sound)).c_str());
|
|
TEST_ASSERT_EQUAL_STRING("Brussels", f.menu.value(f.row(SettingsMenu::Row::Timezone)).c_str());
|
|
TEST_ASSERT_EQUAL_STRING("Raw", f.menu.value(f.row(SettingsMenu::Row::ProbeMacs)).c_str());
|
|
}
|
|
|
|
void test_toggle_rows_flip_on_select() {
|
|
Fixture f;
|
|
int sound = f.row(SettingsMenu::Row::Sound);
|
|
TEST_ASSERT_EQUAL(static_cast<int>(SettingsMenu::Kind::Toggle), static_cast<int>(f.menu.kind(sound)));
|
|
f.menu.toggle(sound);
|
|
TEST_ASSERT_FALSE(f.settings.getBool(Setting::Sound));
|
|
}
|
|
|
|
void test_choice_rows_list_options_and_mark_the_current_one() {
|
|
Fixture f;
|
|
int tz = f.row(SettingsMenu::Row::Timezone);
|
|
TEST_ASSERT_EQUAL(static_cast<int>(SettingsMenu::Kind::Choice), static_cast<int>(f.menu.kind(tz)));
|
|
auto options = f.menu.choices(tz);
|
|
TEST_ASSERT_TRUE(options.size() >= 3);
|
|
TEST_ASSERT_EQUAL_STRING("Brussels", options[f.menu.currentChoice(tz)].c_str());
|
|
}
|
|
|
|
void test_choosing_applies_the_setting() {
|
|
Fixture f;
|
|
int tz = f.row(SettingsMenu::Row::Timezone);
|
|
auto options = f.menu.choices(tz);
|
|
int utc = -1;
|
|
for (size_t i = 0; i < options.size(); i++)
|
|
if (options[i] == "UTC") utc = static_cast<int>(i);
|
|
TEST_ASSERT_TRUE(f.menu.choose(tz, utc).empty());
|
|
TEST_ASSERT_EQUAL_STRING("UTC0", f.settings.getString(Setting::Timezone).c_str());
|
|
}
|
|
|
|
void test_choice_that_breaks_a_rule_is_refused_with_a_reason() {
|
|
Fixture f;
|
|
int dim = f.row(SettingsMenu::Row::DimTimeout);
|
|
auto options = f.menu.choices(dim);
|
|
int fiveMinutes = -1;
|
|
for (size_t i = 0; i < options.size(); i++)
|
|
if (options[i] == "5 min") fiveMinutes = static_cast<int>(i);
|
|
TEST_ASSERT_TRUE(fiveMinutes >= 0);
|
|
std::string error = f.menu.choose(dim, fiveMinutes); // screen off is 1 min
|
|
TEST_ASSERT_FALSE(error.empty());
|
|
TEST_ASSERT_EQUAL(30, f.settings.getInt(Setting::DimTimeoutS));
|
|
}
|
|
|
|
void test_brightness_steps_with_left_right_within_bounds() {
|
|
Fixture f;
|
|
int b = f.row(SettingsMenu::Row::Brightness);
|
|
TEST_ASSERT_EQUAL(static_cast<int>(SettingsMenu::Kind::Slider), static_cast<int>(f.menu.kind(b)));
|
|
f.menu.adjust(b, +1);
|
|
TEST_ASSERT_EQUAL(70, f.settings.getInt(Setting::Brightness));
|
|
for (int i = 0; i < 10; i++) f.menu.adjust(b, -1);
|
|
TEST_ASSERT_EQUAL(10, f.settings.getInt(Setting::Brightness));
|
|
}
|
|
|
|
void test_names_are_text_rows_with_their_byte_limits() {
|
|
Fixture f;
|
|
int shortName = f.row(SettingsMenu::Row::ShortName);
|
|
TEST_ASSERT_EQUAL(static_cast<int>(SettingsMenu::Kind::Text), static_cast<int>(f.menu.kind(shortName)));
|
|
TEST_ASSERT_EQUAL(4, f.menu.maxBytes(shortName));
|
|
TEST_ASSERT_FALSE(f.menu.setText(shortName, "TOOLONG").empty());
|
|
TEST_ASSERT_TRUE(f.menu.setText(shortName, "RORO").empty());
|
|
TEST_ASSERT_EQUAL_STRING("RORO", f.menu.value(shortName).c_str());
|
|
}
|
|
|
|
int main() {
|
|
UNITY_BEGIN();
|
|
RUN_TEST(test_every_row_has_a_label);
|
|
RUN_TEST(test_values_are_human_readable);
|
|
RUN_TEST(test_toggle_rows_flip_on_select);
|
|
RUN_TEST(test_choice_rows_list_options_and_mark_the_current_one);
|
|
RUN_TEST(test_choosing_applies_the_setting);
|
|
RUN_TEST(test_choice_that_breaks_a_rule_is_refused_with_a_reason);
|
|
RUN_TEST(test_brightness_steps_with_left_right_within_bounds);
|
|
RUN_TEST(test_names_are_text_rows_with_their_byte_limits);
|
|
return UNITY_END();
|
|
}
|