Skip to content

Commit

Permalink
feat: hide settings based on zimbraFeatureOptionsEnabled value
Browse files Browse the repository at this point in the history
refs: SHELL-120 (#283)
  • Loading branch information
CataldoMazzilli authored Jul 11, 2023
1 parent f9d30b6 commit 0af1744
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 10 deletions.
27 changes: 19 additions & 8 deletions src/boot/app/default-views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import produce from 'immer';
import type { TFunction } from 'i18next';
import { size } from 'lodash';
import type { AppState, PrimaryBarView, SettingsView } from '../../../types';
import { SEARCH_APP_ID, SETTINGS_APP_ID, SHELL_APP_ID } from '../../constants';
import Feedback from '../../reporting/feedback';
Expand All @@ -17,6 +18,7 @@ import { settingsSubSections } from '../../settings/general-settings-sub-section
import { SettingsAppView } from '../../settings/settings-app-view';
import { SettingsSidebar } from '../../settings/settings-sidebar';
import { useAppStore } from '../../store/app';
import { useAccountStore } from '../../store/account';

const settingsRoute = {
route: SETTINGS_APP_ID,
Expand Down Expand Up @@ -103,14 +105,23 @@ const feedbackBoardView = {
export const registerDefaultViews = (t: TFunction): void => {
useAppStore.setState(
produce((s: AppState) => {
s.routes = {
[SEARCH_APP_ID]: searchRoute,
[SETTINGS_APP_ID]: settingsRoute
};
s.views.primaryBar = [searchPrimaryBar(t), settingsPrimaryBar(t)];
s.views.secondaryBar = [settingsSecondaryBar];
s.views.appView = [searchAppView, settingsAppView];
s.views.settings = [settingsGeneralView(t), settingsAccountsView(t)];
const { attrs } = useAccountStore.getState().settings;
if (size(attrs) === 0 || attrs.zimbraFeatureOptionsEnabled === 'FALSE') {
s.routes = {
[SEARCH_APP_ID]: searchRoute
};
s.views.primaryBar = [searchPrimaryBar(t)];
s.views.appView = [searchAppView];
} else {
s.routes = {
[SEARCH_APP_ID]: searchRoute,
[SETTINGS_APP_ID]: settingsRoute
};
s.views.primaryBar = [searchPrimaryBar(t), settingsPrimaryBar(t)];
s.views.secondaryBar = [settingsSecondaryBar];
s.views.appView = [searchAppView, settingsAppView];
s.views.settings = [settingsGeneralView(t), settingsAccountsView(t)];
}
s.views.board = [feedbackBoardView];
})
);
Expand Down
29 changes: 28 additions & 1 deletion src/shell/shell-primary-bar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ import { act, screen, within } from '@testing-library/react';
import { Button, Text } from '@zextras/carbonio-design-system';
import { Route, Switch, useParams, useRouteMatch } from 'react-router-dom';

import produce from 'immer';
import AppViewContainer from './app-view-container';
import ShellPrimaryBar from './shell-primary-bar';
import { PrimaryBarView } from '../../types';
import { AccountState, PrimaryBarView } from '../../types';
import { DefaultViewsRegister } from '../boot/bootstrapper';
import { usePushHistoryCallback } from '../history/hooks';
import { ModuleSelector } from '../search/module-selector';
import { useAppStore } from '../store/app';
import { setup } from '../test/utils';
import { useAccountStore } from '../store/account';
import { ICONS } from '../test/constants';

const ShellWrapper = (): JSX.Element => (
<>
Expand Down Expand Up @@ -419,4 +422,28 @@ describe('Shell primary bar', () => {
expect(screen.queryByText('default mails view')).not.toBeInTheDocument();
expect(screen.queryByText('files view')).not.toBeInTheDocument();
});

test('When zimbraFeatureOptionsEnabled is TRUE the setting icon is visible in primary bar', async () => {
useAccountStore.setState(
produce((state: AccountState) => {
state.settings.attrs.zimbraFeatureOptionsEnabled = 'TRUE';
})
);
const { getByRoleWithIcon } = setup(<ShellWrapper />);

const searchIcon = getByRoleWithIcon('button', { icon: ICONS.settings });
expect(searchIcon).toBeVisible();
expect(searchIcon).toBeEnabled();
});

test('When zimbraFeatureOptionsEnabled is FALSE the setting icon is missing in primary bar', async () => {
useAccountStore.setState(
produce((state: AccountState) => {
state.settings.attrs.zimbraFeatureOptionsEnabled = 'FALSE';
})
);
const { queryByRoleWithIcon } = setup(<ShellWrapper />);

expect(queryByRoleWithIcon('button', { icon: ICONS.settings })).not.toBeInTheDocument();
});
});
3 changes: 2 additions & 1 deletion src/test/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ export const ICONS = {
enlargeBoard: 'ExpandOutline',
reduceBoard: 'CollapseOutline',
resetBoardSize: 'DiagonalArrowLeftDown',
unCollapseBoard: 'BoardOpen'
unCollapseBoard: 'BoardOpen',
settings: 'SettingsModOutline'
};

export const TESTID_SELECTORS = {
Expand Down
1 change: 1 addition & 0 deletions types/account/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export interface AccountSettingsPrefs {
}

export type AccountSettingsAttrs = {
zimbraFeatureOptionsEnabled?: BooleanString;
zimbraIdentityMaxNumEntries?: number;
[key: string]: string | number | Array<string | number>;
};
Expand Down

0 comments on commit 0af1744

Please sign in to comment.