Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions apps/webapp/src/script/page/AppMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import {ContentState, useAppState} from './useAppState';
import {runClientVersionCheck} from '../application-periodic-checks/runClientVersionCheck';
import {startApplicationPeriodicChecks} from '../application-periodic-checks/startApplicationPeriodicChecks';
import {createWallClock} from '../clock/wallClock';
import {StartupFeatureToggleName, StartupFeatureToggles} from '../featureToggles/startupFeatureToggles';
import {StartupFeatureToggles} from '../featureToggles/startupFeatureToggles';
import {App} from '../main/app';
import {initialiseMLSMigrationFlow} from '../mls/MLSMigration';
import {generateConversationUrl} from '../router/routeGenerator';
Expand Down Expand Up @@ -302,10 +302,6 @@ export const AppMain = ({

const showLeftSidebar = (isMobileView && isMobileLeftSidebarView) || (!isMobileView && !isLeftSidebarHidden);
const showMainContent = currentTab === SidebarTabs.CELLS || !isMobileView || isMobileCentralColumnView;
function isFeatureFlagEnabled(featureName: StartupFeatureToggleName): boolean {
return startupFeatureToggles.isFeatureToggleEnabled(featureName);
}

return (
<StyledApp
themeId={THEME_ID.DEFAULT}
Expand All @@ -315,7 +311,14 @@ export const AppMain = ({
data-uie-value="is-loaded"
>
{!locked && <WindowTitleUpdater />}
<RootProvider value={{mainViewModel: mainView, wallClock, doesApplicationNeedForceReload, isFeatureFlagEnabled}}>
<RootProvider
value={{
mainViewModel: mainView,
wallClock,
doesApplicationNeedForceReload,
isFeatureToggleEnabled: startupFeatureToggles.isFeatureToggleEnabled,
}}
>
<ErrorBoundary FallbackComponent={ErrorFallback}>
<ForceReloadModal reloadApplication={app.refresh} />
{Config.getConfig().FEATURE.ENABLE_DEBUG && <ConfigToolbar />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const mockDevicesHandler = {
currentDeviceId: () => 'mock-device-id',
} as unknown as MediaDevicesHandler;

function isFeatureFlagDisabledForTest(): boolean {
function isFeatureToggleDisabledForTest(): boolean {
return false;
}

Expand Down Expand Up @@ -79,7 +79,7 @@ describe('Preferences', () => {
mainViewModel,
wallClock,
doesApplicationNeedForceReload: false,
isFeatureFlagEnabled: isFeatureFlagDisabledForTest,
isFeatureToggleEnabled: isFeatureToggleDisabledForTest,
}}
>
<MainContent {...defaultParams} />
Expand Down
25 changes: 16 additions & 9 deletions apps/webapp/src/script/page/RootProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ interface WrapperProperties {

interface RootProviderWrapper {
wrapper: (properties: WrapperProperties) => ReactNode;
isFeatureFlagEnabled: jest.Mock<boolean, [StartupFeatureToggleName]>;
isFeatureToggleEnabled: jest.Mock<boolean, [StartupFeatureToggleName]>;
deterministicWallClock: ReturnType<typeof createDeterministicWallClock>;
}

Expand All @@ -50,23 +50,30 @@ function createRootProviderWrapper(
const deterministicWallClock = createDeterministicWallClock({
initialCurrentTimestampInMilliseconds: wallClockTimestampInMilliseconds,
});
function isFeatureFlagEnabledForTest(featureName: StartupFeatureToggleName): boolean {
function isFeatureToggleEnabledForTest(featureName: StartupFeatureToggleName): boolean {
return featureName === 'reliable-websocket-connection';
}

const isFeatureFlagEnabled = jest.fn(isFeatureFlagEnabledForTest);
const isFeatureToggleEnabled = jest.fn(isFeatureToggleEnabledForTest);

function wrapper(properties: WrapperProperties): ReactNode {
const wrappedChildren = (
<RootProvider value={{mainViewModel, wallClock: deterministicWallClock, doesApplicationNeedForceReload, isFeatureFlagEnabled}}>
<RootProvider
value={{
mainViewModel,
wallClock: deterministicWallClock,
doesApplicationNeedForceReload,
isFeatureToggleEnabled,
}}
>
{properties.children}
</RootProvider>
);

return wrappedChildren;
}

return {wrapper, deterministicWallClock, isFeatureFlagEnabled};
return {wrapper, deterministicWallClock, isFeatureToggleEnabled};
}

function getRootContextValue(): RootContextValue | null {
Expand Down Expand Up @@ -114,12 +121,12 @@ describe('RootProvider', () => {
expect(result.current.doesApplicationNeedForceReload).toBe(true);
});

it('provides startup feature flag helper through useApplicationContext()', function () {
const {wrapper, isFeatureFlagEnabled} = createRootProviderWrapper(mainViewModel, 9_999, true);
it('provides startup feature toggle helper through useApplicationContext()', function () {
const {wrapper, isFeatureToggleEnabled} = createRootProviderWrapper(mainViewModel, 9_999, true);

const {result} = renderHook(useApplicationContext, {wrapper});

expect(result.current.isFeatureFlagEnabled('reliable-websocket-connection')).toBe(true);
expect(isFeatureFlagEnabled).toHaveBeenCalledWith('reliable-websocket-connection');
expect(result.current.isFeatureToggleEnabled('reliable-websocket-connection')).toBe(true);
expect(isFeatureToggleEnabled).toHaveBeenCalledWith('reliable-websocket-connection');
});
});
2 changes: 1 addition & 1 deletion apps/webapp/src/script/page/RootProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export type RootContextValue = {
readonly mainViewModel: MainViewModel;
readonly wallClock: WallClock;
readonly doesApplicationNeedForceReload: boolean;
readonly isFeatureFlagEnabled: (featureName: StartupFeatureToggleName) => boolean;
readonly isFeatureToggleEnabled: (featureName: StartupFeatureToggleName) => boolean;
};

export const RootContext = createContext<RootContextValue | null>(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ interface ForceReloadModalTestContextValue {
readonly reloadApplication: () => void;
}

function isFeatureFlagDisabledForTest(): boolean {
function isFeatureToggleDisabledForTest(): boolean {
return false;
}

Expand Down Expand Up @@ -71,7 +71,7 @@ function createForceReloadModalTestElement(
<RootProvider
value={{
doesApplicationNeedForceReload,
isFeatureFlagEnabled: isFeatureFlagDisabledForTest,
isFeatureToggleEnabled: isFeatureToggleDisabledForTest,
mainViewModel: createMainViewModelForTest(),
wallClock: createDeterministicWallClock({initialCurrentTimestampInMilliseconds: 1_111}),
}}
Expand Down