feat(smart-app): implement complete mobile app MVP

- App.tsx: full navigation (Auth stack + Main tabs with 5 screens)
- Auth: LoginScreen, RegisterScreen, ForgotPasswordScreen
- HomeScreen: dashboard with IoT metrics, weather widget, alerts, quick actions, sensors
- MapScreen: interactive map with layer toggles (6 layers)
- MarketplaceScreen: categories (6), products (5), search
- ChatScreen: AI chat with quick prompts (4), bot responses
- ProfileScreen: user info, stats, menu (9 items), logout
- AlertsScreen: alert list with severity, acknowledge
- SensorsScreen: sensor list with type filters (6 types), search
- ZonesScreen: zone cards with stats
- SettingsScreen: language picker (FR/EN/ES/DE), privacy, about
- Stores: iotStore (sensors, zones, alerts), notificationStore, uiStore + i18n
- Hooks: useSensors, useAlerts, useNotifications, useLocation
- Components: Card, Button, LoadingSpinner, ErrorBoundary, Header
- Services: iotService, notificationService (with axios API client)
- Utils: formatters (temp, AQI, noise, dates), validators (email, password, IBAN)
- Theme: colors.ts with full design system (Blue Ocean palette)
- Ditto: fixed MongoDB connection, new JWT secrets, official gateway image
This commit is contained in:
Eric FELIXINE
2026-06-01 18:00:35 -04:00
parent 08ca495bde
commit e30ae8ed09
35578 changed files with 3703534 additions and 43 deletions

View File

@@ -0,0 +1,20 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
cmake_minimum_required(VERSION 3.13)
set(CMAKE_VERBOSE_MAKEFILE on)
add_compile_options(
-fexceptions
-frtti
-std=c++20
-Wall
-Wpedantic
-DLOG_TAG=\"ReactNative\")
file(GLOB react_featureflags_SRC CONFIGURE_DEPENDS *.cpp)
add_library(react_featureflags SHARED ${react_featureflags_SRC})
target_include_directories(react_featureflags PUBLIC ${REACT_COMMON_DIR})

View File

@@ -0,0 +1,44 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
require "json"
package = JSON.parse(File.read(File.join(__dir__, "..", "..", "..", "package.json")))
version = package['version']
source = { :git => 'https://github.com/facebook/react-native.git' }
if version == '1000.0.0'
# This is an unpublished version, use the latest commit hash of the react-native repo, which were presumably in.
source[:commit] = `git rev-parse HEAD`.strip if system("git rev-parse --git-dir > /dev/null 2>&1")
else
source[:tag] = "v#{version}"
end
header_search_paths = []
if ENV['USE_FRAMEWORKS']
header_search_paths << "\"$(PODS_TARGET_SRCROOT)/../..\"" # this is needed to allow the feature flags access its own files
end
Pod::Spec.new do |s|
s.name = "React-featureflags"
s.version = version
s.summary = "React Native internal feature flags"
s.homepage = "https://reactnative.dev/"
s.license = package["license"]
s.author = "Meta Platforms, Inc. and its affiliates"
s.platforms = min_supported_versions
s.source = source
s.source_files = "*.{cpp,h}"
s.header_dir = "react/featureflags"
s.pod_target_xcconfig = { "CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
"HEADER_SEARCH_PATHS" => header_search_paths.join(' '),
"DEFINES_MODULE" => "YES" }
if ENV['USE_FRAMEWORKS']
s.module_name = "React_featureflags"
s.header_mappings_dir = "../.."
end
end

View File

@@ -0,0 +1,82 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<82f226df2b3824d03b755a042b20bec5>>
*/
/**
* IMPORTANT: Do NOT modify this file directly.
*
* To change the definition of the flags, edit
* packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js.
*
* To regenerate this code, run the following script from the repo root:
* yarn featureflags-update
*/
#include "ReactNativeFeatureFlags.h"
namespace facebook::react {
bool ReactNativeFeatureFlags::commonTestFlag() {
return getAccessor().commonTestFlag();
}
bool ReactNativeFeatureFlags::enableBackgroundExecutor() {
return getAccessor().enableBackgroundExecutor();
}
bool ReactNativeFeatureFlags::useModernRuntimeScheduler() {
return getAccessor().useModernRuntimeScheduler();
}
bool ReactNativeFeatureFlags::enableMicrotasks() {
return getAccessor().enableMicrotasks();
}
bool ReactNativeFeatureFlags::batchRenderingUpdatesInEventLoop() {
return getAccessor().batchRenderingUpdatesInEventLoop();
}
bool ReactNativeFeatureFlags::enableSpannableBuildingUnification() {
return getAccessor().enableSpannableBuildingUnification();
}
bool ReactNativeFeatureFlags::enableCustomDrawOrderFabric() {
return getAccessor().enableCustomDrawOrderFabric();
}
bool ReactNativeFeatureFlags::enableFixForClippedSubviewsCrash() {
return getAccessor().enableFixForClippedSubviewsCrash();
}
bool ReactNativeFeatureFlags::inspectorEnableCxxInspectorPackagerConnection() {
return getAccessor().inspectorEnableCxxInspectorPackagerConnection();
}
bool ReactNativeFeatureFlags::inspectorEnableModernCDPRegistry() {
return getAccessor().inspectorEnableModernCDPRegistry();
}
void ReactNativeFeatureFlags::override(
std::unique_ptr<ReactNativeFeatureFlagsProvider> provider) {
getAccessor().override(std::move(provider));
}
void ReactNativeFeatureFlags::dangerouslyReset() {
getAccessor(true);
}
ReactNativeFeatureFlagsAccessor& ReactNativeFeatureFlags::getAccessor(
bool reset) {
static std::unique_ptr<ReactNativeFeatureFlagsAccessor> accessor;
if (accessor == nullptr || reset) {
accessor = std::make_unique<ReactNativeFeatureFlagsAccessor>();
}
return *accessor;
}
} // namespace facebook::react

View File

@@ -0,0 +1,126 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<3bfae310dfd28040f4b80d1a1df8b7b3>>
*/
/**
* IMPORTANT: Do NOT modify this file directly.
*
* To change the definition of the flags, edit
* packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js.
*
* To regenerate this code, run the following script from the repo root:
* yarn featureflags-update
*/
#pragma once
#include <react/featureflags/ReactNativeFeatureFlagsAccessor.h>
#include <react/featureflags/ReactNativeFeatureFlagsProvider.h>
#include <memory>
namespace facebook::react {
/**
* This class provides access to internal React Native feature flags.
*
* All the methods are thread-safe (as long as the methods in the overridden
* provider are).
*/
class ReactNativeFeatureFlags {
public:
/**
* Common flag for testing. Do NOT modify.
*/
static bool commonTestFlag();
/**
* Enables the use of a background executor to compute layout and commit updates on Fabric (this system is deprecated and should not be used).
*/
static bool enableBackgroundExecutor();
/**
* When enabled, it uses the modern fork of RuntimeScheduler that allows scheduling tasks with priorities from any thread.
*/
static bool useModernRuntimeScheduler();
/**
* Enables the use of microtasks in Hermes (scheduling) and RuntimeScheduler (execution).
*/
static bool enableMicrotasks();
/**
* When enabled, the RuntimeScheduler processing the event loop will batch all rendering updates and dispatch them together at the end of each iteration of the loop.
*/
static bool batchRenderingUpdatesInEventLoop();
/**
* Uses new, deduplicated logic for constructing Android Spannables from text fragments
*/
static bool enableSpannableBuildingUnification();
/**
* When enabled, Fabric will use customDrawOrder in ReactViewGroup (similar to old architecture).
*/
static bool enableCustomDrawOrderFabric();
/**
* Attempt at fixing a crash related to subview clipping on Android. This is a kill switch for the fix
*/
static bool enableFixForClippedSubviewsCrash();
/**
* Flag determining if the C++ implementation of InspectorPackagerConnection should be used instead of the per-platform one. This flag is global and should not be changed across React Host lifetimes.
*/
static bool inspectorEnableCxxInspectorPackagerConnection();
/**
* Flag determining if the modern CDP backend should be enabled. This flag is global and should not be changed across React Host lifetimes.
*/
static bool inspectorEnableModernCDPRegistry();
/**
* Overrides the feature flags with the ones provided by the given provider
* (generally one that extends `ReactNativeFeatureFlagsDefaults`).
*
* This method must be called before you initialize the React Native runtime.
*
* @example
*
* ```
* class MyReactNativeFeatureFlags : public ReactNativeFeatureFlagsDefaults {
* public:
* bool someFlag() override;
* };
*
* ReactNativeFeatureFlags.override(
* std::make_unique<MyReactNativeFeatureFlags>());
* ```
*/
static void override(
std::unique_ptr<ReactNativeFeatureFlagsProvider> provider);
/**
* Removes the overridden feature flags and makes the API return default
* values again.
*
* This is **dangerous**. Use it only if you really understand the
* implications of this method.
*
* This should only be called if you destroy the React Native runtime and
* need to create a new one with different overrides. In that case,
* call `dangerouslyReset` after destroying the runtime and `override` again
* before initializing the new one.
*/
static void dangerouslyReset();
private:
ReactNativeFeatureFlags() = delete;
static ReactNativeFeatureFlagsAccessor& getAccessor(bool reset = false);
};
} // namespace facebook::react

View File

@@ -0,0 +1,251 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<2154292f89306f25289583537833a065>>
*/
/**
* IMPORTANT: Do NOT modify this file directly.
*
* To change the definition of the flags, edit
* packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js.
*
* To regenerate this code, run the following script from the repo root:
* yarn featureflags-update
*/
#include <react/featureflags/ReactNativeFeatureFlagsDefaults.h>
#include <sstream>
#include <stdexcept>
#include <string>
#include "ReactNativeFeatureFlags.h"
namespace facebook::react {
ReactNativeFeatureFlagsAccessor::ReactNativeFeatureFlagsAccessor()
: currentProvider_(std::make_unique<ReactNativeFeatureFlagsDefaults>()),
wasOverridden_(false) {}
bool ReactNativeFeatureFlagsAccessor::commonTestFlag() {
auto flagValue = commonTestFlag_.load();
if (!flagValue.has_value()) {
// This block is not exclusive but it is not necessary.
// If multiple threads try to initialize the feature flag, we would only
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(0, "commonTestFlag");
flagValue = currentProvider_->commonTestFlag();
commonTestFlag_ = flagValue;
}
return flagValue.value();
}
bool ReactNativeFeatureFlagsAccessor::enableBackgroundExecutor() {
auto flagValue = enableBackgroundExecutor_.load();
if (!flagValue.has_value()) {
// This block is not exclusive but it is not necessary.
// If multiple threads try to initialize the feature flag, we would only
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(1, "enableBackgroundExecutor");
flagValue = currentProvider_->enableBackgroundExecutor();
enableBackgroundExecutor_ = flagValue;
}
return flagValue.value();
}
bool ReactNativeFeatureFlagsAccessor::useModernRuntimeScheduler() {
auto flagValue = useModernRuntimeScheduler_.load();
if (!flagValue.has_value()) {
// This block is not exclusive but it is not necessary.
// If multiple threads try to initialize the feature flag, we would only
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(2, "useModernRuntimeScheduler");
flagValue = currentProvider_->useModernRuntimeScheduler();
useModernRuntimeScheduler_ = flagValue;
}
return flagValue.value();
}
bool ReactNativeFeatureFlagsAccessor::enableMicrotasks() {
auto flagValue = enableMicrotasks_.load();
if (!flagValue.has_value()) {
// This block is not exclusive but it is not necessary.
// If multiple threads try to initialize the feature flag, we would only
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(3, "enableMicrotasks");
flagValue = currentProvider_->enableMicrotasks();
enableMicrotasks_ = flagValue;
}
return flagValue.value();
}
bool ReactNativeFeatureFlagsAccessor::batchRenderingUpdatesInEventLoop() {
auto flagValue = batchRenderingUpdatesInEventLoop_.load();
if (!flagValue.has_value()) {
// This block is not exclusive but it is not necessary.
// If multiple threads try to initialize the feature flag, we would only
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(4, "batchRenderingUpdatesInEventLoop");
flagValue = currentProvider_->batchRenderingUpdatesInEventLoop();
batchRenderingUpdatesInEventLoop_ = flagValue;
}
return flagValue.value();
}
bool ReactNativeFeatureFlagsAccessor::enableSpannableBuildingUnification() {
auto flagValue = enableSpannableBuildingUnification_.load();
if (!flagValue.has_value()) {
// This block is not exclusive but it is not necessary.
// If multiple threads try to initialize the feature flag, we would only
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(5, "enableSpannableBuildingUnification");
flagValue = currentProvider_->enableSpannableBuildingUnification();
enableSpannableBuildingUnification_ = flagValue;
}
return flagValue.value();
}
bool ReactNativeFeatureFlagsAccessor::enableCustomDrawOrderFabric() {
auto flagValue = enableCustomDrawOrderFabric_.load();
if (!flagValue.has_value()) {
// This block is not exclusive but it is not necessary.
// If multiple threads try to initialize the feature flag, we would only
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(6, "enableCustomDrawOrderFabric");
flagValue = currentProvider_->enableCustomDrawOrderFabric();
enableCustomDrawOrderFabric_ = flagValue;
}
return flagValue.value();
}
bool ReactNativeFeatureFlagsAccessor::enableFixForClippedSubviewsCrash() {
auto flagValue = enableFixForClippedSubviewsCrash_.load();
if (!flagValue.has_value()) {
// This block is not exclusive but it is not necessary.
// If multiple threads try to initialize the feature flag, we would only
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(7, "enableFixForClippedSubviewsCrash");
flagValue = currentProvider_->enableFixForClippedSubviewsCrash();
enableFixForClippedSubviewsCrash_ = flagValue;
}
return flagValue.value();
}
bool ReactNativeFeatureFlagsAccessor::inspectorEnableCxxInspectorPackagerConnection() {
auto flagValue = inspectorEnableCxxInspectorPackagerConnection_.load();
if (!flagValue.has_value()) {
// This block is not exclusive but it is not necessary.
// If multiple threads try to initialize the feature flag, we would only
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(8, "inspectorEnableCxxInspectorPackagerConnection");
flagValue = currentProvider_->inspectorEnableCxxInspectorPackagerConnection();
inspectorEnableCxxInspectorPackagerConnection_ = flagValue;
}
return flagValue.value();
}
bool ReactNativeFeatureFlagsAccessor::inspectorEnableModernCDPRegistry() {
auto flagValue = inspectorEnableModernCDPRegistry_.load();
if (!flagValue.has_value()) {
// This block is not exclusive but it is not necessary.
// If multiple threads try to initialize the feature flag, we would only
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(9, "inspectorEnableModernCDPRegistry");
flagValue = currentProvider_->inspectorEnableModernCDPRegistry();
inspectorEnableModernCDPRegistry_ = flagValue;
}
return flagValue.value();
}
void ReactNativeFeatureFlagsAccessor::override(
std::unique_ptr<ReactNativeFeatureFlagsProvider> provider) {
if (wasOverridden_) {
throw std::runtime_error(
"Feature flags cannot be overridden more than once");
}
ensureFlagsNotAccessed();
wasOverridden_ = true;
currentProvider_ = std::move(provider);
}
void ReactNativeFeatureFlagsAccessor::markFlagAsAccessed(
int position,
const char* flagName) {
accessedFeatureFlags_[position] = flagName;
}
void ReactNativeFeatureFlagsAccessor::ensureFlagsNotAccessed() {
std::ostringstream featureFlagListBuilder;
for (const auto& featureFlagName : accessedFeatureFlags_) {
if (featureFlagName != nullptr) {
featureFlagListBuilder << featureFlagName << ", ";
}
}
std::string accessedFeatureFlagNames = featureFlagListBuilder.str();
if (!accessedFeatureFlagNames.empty()) {
accessedFeatureFlagNames =
accessedFeatureFlagNames.substr(0, accessedFeatureFlagNames.size() - 2);
}
if (!accessedFeatureFlagNames.empty()) {
throw std::runtime_error(
"Feature flags were accessed before being overridden: " +
accessedFeatureFlagNames);
}
}
} // namespace facebook::react

View File

@@ -0,0 +1,68 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<95487968b66d40e1ec53936b06084931>>
*/
/**
* IMPORTANT: Do NOT modify this file directly.
*
* To change the definition of the flags, edit
* packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js.
*
* To regenerate this code, run the following script from the repo root:
* yarn featureflags-update
*/
#pragma once
#include <react/featureflags/ReactNativeFeatureFlagsProvider.h>
#include <array>
#include <atomic>
#include <memory>
#include <optional>
namespace facebook::react {
class ReactNativeFeatureFlagsAccessor {
public:
ReactNativeFeatureFlagsAccessor();
bool commonTestFlag();
bool enableBackgroundExecutor();
bool useModernRuntimeScheduler();
bool enableMicrotasks();
bool batchRenderingUpdatesInEventLoop();
bool enableSpannableBuildingUnification();
bool enableCustomDrawOrderFabric();
bool enableFixForClippedSubviewsCrash();
bool inspectorEnableCxxInspectorPackagerConnection();
bool inspectorEnableModernCDPRegistry();
void override(std::unique_ptr<ReactNativeFeatureFlagsProvider> provider);
private:
void markFlagAsAccessed(int position, const char* flagName);
void ensureFlagsNotAccessed();
std::unique_ptr<ReactNativeFeatureFlagsProvider> currentProvider_;
bool wasOverridden_;
std::array<std::atomic<const char*>, 10> accessedFeatureFlags_;
std::atomic<std::optional<bool>> commonTestFlag_;
std::atomic<std::optional<bool>> enableBackgroundExecutor_;
std::atomic<std::optional<bool>> useModernRuntimeScheduler_;
std::atomic<std::optional<bool>> enableMicrotasks_;
std::atomic<std::optional<bool>> batchRenderingUpdatesInEventLoop_;
std::atomic<std::optional<bool>> enableSpannableBuildingUnification_;
std::atomic<std::optional<bool>> enableCustomDrawOrderFabric_;
std::atomic<std::optional<bool>> enableFixForClippedSubviewsCrash_;
std::atomic<std::optional<bool>> inspectorEnableCxxInspectorPackagerConnection_;
std::atomic<std::optional<bool>> inspectorEnableModernCDPRegistry_;
};
} // namespace facebook::react

View File

@@ -0,0 +1,71 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<4832483bb3648380f2bb9312311f579c>>
*/
/**
* IMPORTANT: Do NOT modify this file directly.
*
* To change the definition of the flags, edit
* packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js.
*
* To regenerate this code, run the following script from the repo root:
* yarn featureflags-update
*/
#pragma once
#include <react/featureflags/ReactNativeFeatureFlagsProvider.h>
namespace facebook::react {
class ReactNativeFeatureFlagsDefaults : public ReactNativeFeatureFlagsProvider {
public:
ReactNativeFeatureFlagsDefaults() = default;
bool commonTestFlag() override {
return false;
}
bool enableBackgroundExecutor() override {
return false;
}
bool useModernRuntimeScheduler() override {
return false;
}
bool enableMicrotasks() override {
return false;
}
bool batchRenderingUpdatesInEventLoop() override {
return false;
}
bool enableSpannableBuildingUnification() override {
return false;
}
bool enableCustomDrawOrderFabric() override {
return false;
}
bool enableFixForClippedSubviewsCrash() override {
return false;
}
bool inspectorEnableCxxInspectorPackagerConnection() override {
return false;
}
bool inspectorEnableModernCDPRegistry() override {
return false;
}
};
} // namespace facebook::react

View File

@@ -0,0 +1,40 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<f707d15cf978d7342cdf5aab18444219>>
*/
/**
* IMPORTANT: Do NOT modify this file directly.
*
* To change the definition of the flags, edit
* packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js.
*
* To regenerate this code, run the following script from the repo root:
* yarn featureflags-update
*/
#pragma once
namespace facebook::react {
class ReactNativeFeatureFlagsProvider {
public:
virtual ~ReactNativeFeatureFlagsProvider() = default;
virtual bool commonTestFlag() = 0;
virtual bool enableBackgroundExecutor() = 0;
virtual bool useModernRuntimeScheduler() = 0;
virtual bool enableMicrotasks() = 0;
virtual bool batchRenderingUpdatesInEventLoop() = 0;
virtual bool enableSpannableBuildingUnification() = 0;
virtual bool enableCustomDrawOrderFabric() = 0;
virtual bool enableFixForClippedSubviewsCrash() = 0;
virtual bool inspectorEnableCxxInspectorPackagerConnection() = 0;
virtual bool inspectorEnableModernCDPRegistry() = 0;
};
} // namespace facebook::react

View File

@@ -0,0 +1,124 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <gtest/gtest.h>
#include <react/featureflags/ReactNativeFeatureFlags.h>
#include <react/featureflags/ReactNativeFeatureFlagsDefaults.h>
#include <stdexcept>
namespace facebook::react {
uint overrideAccessCount = 0;
class ReactNativeFeatureFlagsTestOverrides
: public ReactNativeFeatureFlagsDefaults {
public:
bool commonTestFlag() override {
overrideAccessCount++;
return true;
}
};
class ReactNativeFeatureFlagsTest : public testing::Test {
protected:
void SetUp() override {
overrideAccessCount = 0;
}
void TearDown() override {
ReactNativeFeatureFlags::dangerouslyReset();
}
};
TEST_F(ReactNativeFeatureFlagsTest, providesDefaults) {
EXPECT_EQ(ReactNativeFeatureFlags::commonTestFlag(), false);
}
TEST_F(ReactNativeFeatureFlagsTest, providesOverriddenValues) {
ReactNativeFeatureFlags::override(
std::make_unique<ReactNativeFeatureFlagsTestOverrides>());
EXPECT_EQ(ReactNativeFeatureFlags::commonTestFlag(), true);
}
TEST_F(ReactNativeFeatureFlagsTest, preventsOverridingAfterAccess) {
EXPECT_EQ(ReactNativeFeatureFlags::commonTestFlag(), false);
try {
ReactNativeFeatureFlags::override(
std::make_unique<ReactNativeFeatureFlagsTestOverrides>());
FAIL()
<< "Expected ReactNativeFeatureFlags::override() to throw an exception";
} catch (const std::runtime_error& e) {
EXPECT_STREQ(
"Feature flags were accessed before being overridden: commonTestFlag",
e.what());
}
// Overrides shouldn't be applied after they've been accessed
EXPECT_EQ(ReactNativeFeatureFlags::commonTestFlag(), false);
}
TEST_F(ReactNativeFeatureFlagsTest, preventsOverridingAfterOverride) {
ReactNativeFeatureFlags::override(
std::make_unique<ReactNativeFeatureFlagsTestOverrides>());
EXPECT_EQ(ReactNativeFeatureFlags::commonTestFlag(), true);
try {
ReactNativeFeatureFlags::override(
std::make_unique<ReactNativeFeatureFlagsTestOverrides>());
FAIL()
<< "Expected ReactNativeFeatureFlags::override() to throw an exception";
} catch (const std::runtime_error& e) {
EXPECT_STREQ("Feature flags cannot be overridden more than once", e.what());
}
// Original overrides should still work
EXPECT_EQ(ReactNativeFeatureFlags::commonTestFlag(), true);
}
TEST_F(ReactNativeFeatureFlagsTest, cachesValuesFromOverride) {
ReactNativeFeatureFlags::override(
std::make_unique<ReactNativeFeatureFlagsTestOverrides>());
EXPECT_EQ(overrideAccessCount, 0);
EXPECT_EQ(ReactNativeFeatureFlags::commonTestFlag(), true);
EXPECT_EQ(overrideAccessCount, 1);
EXPECT_EQ(ReactNativeFeatureFlags::commonTestFlag(), true);
EXPECT_EQ(overrideAccessCount, 1);
}
TEST_F(
ReactNativeFeatureFlagsTest,
providesDefaulValuesAgainWhenResettingAfterAnOverride) {
ReactNativeFeatureFlags::override(
std::make_unique<ReactNativeFeatureFlagsTestOverrides>());
EXPECT_EQ(ReactNativeFeatureFlags::commonTestFlag(), true);
ReactNativeFeatureFlags::dangerouslyReset();
EXPECT_EQ(ReactNativeFeatureFlags::commonTestFlag(), false);
}
TEST_F(ReactNativeFeatureFlagsTest, allowsOverridingAgainAfterReset) {
ReactNativeFeatureFlags::override(
std::make_unique<ReactNativeFeatureFlagsTestOverrides>());
EXPECT_EQ(ReactNativeFeatureFlags::commonTestFlag(), true);
ReactNativeFeatureFlags::dangerouslyReset();
ReactNativeFeatureFlags::override(
std::make_unique<ReactNativeFeatureFlagsTestOverrides>());
EXPECT_EQ(ReactNativeFeatureFlags::commonTestFlag(), true);
}
} // namespace facebook::react