Skip to content

Commit

Permalink
Merge pull request #1643 from onaio/update-route-navigation
Browse files Browse the repository at this point in the history
Configuration to allow navigation to disabled route
  • Loading branch information
peterMuriuki authored Jul 30, 2021
2 parents 6d6895e + 5618a0a commit 9df962d
Show file tree
Hide file tree
Showing 7 changed files with 289 additions and 73 deletions.
4 changes: 3 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,6 @@ REACT_APP_PLAN_LIST_SHOW_FI_REASON_COLUMN=true
REACT_APP_SUPERSET_MDA_LITE_REPORTING_INDICATOR_ROWS=kenya2021
REACT_APP_SUPERSET_MDA_LITE_REPORTING_INDICATOR_STOPS=kenya2021

REACT_APP_CLIENTS_LIST_BATCH_SIZE=100
REACT_APP_CLIENTS_LIST_BATCH_SIZE=100

REACT_APP_AUTO_ENABLE_NAVIGATION_TO='/assign,/teams'
7 changes: 7 additions & 0 deletions docs/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,10 @@ Below is a list of currently supported environment variables:
- **not Required**; _(string)_
- Plan form fields to be hidden when creating new plan.
- Options: caseNum, interventionType, jurisdictions, fiReason, fiStatus, title, triggersAndConditions activityActionDefinitionUri, activityActionDescription, activityActionTitle, activityActionReason activityTimingPeriodStart, activityTimingPeriodEnd, activityGoalPriority, activityGoalValue

- **REACT_APP_AUTO_ENABLE_NAVIGATION_TO**

- **Optional**
- List of all base URLS to allow navigation to, even when the routes are diasbled.
- Options: /assign, /plans/list, /teams etc
- default: ''
291 changes: 222 additions & 69 deletions src/App/App.tsx

Large diffs are not rendered by default.

52 changes: 49 additions & 3 deletions src/App/tests/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,16 @@ describe('App', () => {
);
expect(GoogleAnalytics.pageview).not.toBeCalled();
history.push(PLAN_LIST_URL);

await act(async () => {
await new Promise<unknown>(resolve => setImmediate(resolve));
});

expect(GoogleAnalytics.pageview).not.toBeCalled();
wrapper.unmount();
});

it('can not navigate to disabled route', () => {
it('can not navigate to disabled route', async () => {
const envModule = require('../../configs/env');
envModule.ENABLE_PLANNING = false; // disable planning tool page
envModule.ENABLE_TEAMS = true; // enable teams page
Expand All @@ -165,12 +170,53 @@ describe('App', () => {

// navigate to disabled page
history.push('/plans/planning'); // navigate to planning tool page
wrapper.update();
await act(async () => {
await new Promise<unknown>(resolve => setImmediate(resolve));
wrapper.update();
});
expect(wrapper.find('Router').prop('history').location.pathname).toEqual('/page-not-found');

// navigate to enabled page
history.push('/teams'); // navigate to teams page
wrapper.update();
await act(async () => {
await new Promise<unknown>(resolve => setImmediate(resolve));
wrapper.update();
});
expect(wrapper.find('Router').prop('history').location.pathname).toEqual('/teams');

wrapper.unmount();
});

it('can navigate to disabled route if configured', async () => {
const envModule = require('../../configs/env');
envModule.ENABLE_PLANNING = false; // disable planning tool page
envModule.ENABLE_TEAMS = false; // disable teams page
envModule.AUTO_ENABLE_NAVIGATION_TO = ['/plans/planning'];

const wrapper = mount(
<Provider store={store}>
<Router history={history}>
<App />
</Router>
</Provider>
);

// navigate to disabled page with auto navigation enabled
history.push('/plans/planning'); // navigate to planning tool page
await act(async () => {
await new Promise<unknown>(resolve => setImmediate(resolve));
wrapper.update();
});
expect(wrapper.find('Router').prop('history').location.pathname).toEqual('/plans/planning');

// navigate to disabled page with auto navigation not enabled
history.push('/teams'); // navigate to teams page
await act(async () => {
await new Promise<unknown>(resolve => setImmediate(resolve));
wrapper.update();
});
expect(wrapper.find('Router').prop('history').location.pathname).toEqual('/page-not-found');

wrapper.unmount();
});
});
1 change: 1 addition & 0 deletions src/App/tests/AppNoBackend.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import store from '../../store';
import App from '../App';

jest.mock('../../configs/env', () => ({
AUTO_ENABLE_NAVIGATION_TO: [],
BACKEND_ACTIVE: false,
DISPLAYED_PLAN_TYPES: ['FI', 'IRS', 'IRS-Lite', 'MDA', 'MDA-Point'],
ENABLED_JURISDICTION_METADATA_IDENTIFIER_OPTIONS: 'COVERAGE,POPULATION,RISK,STRUCTURE,TARGET,OTHER_POPULATION'.split(
Expand Down
2 changes: 2 additions & 0 deletions src/configs/__mocks__/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,5 @@ export const AUTO_SELECT_FI_CLASSIFICATION = false;
export const PLAN_LIST_SHOW_FI_REASON_COLUMN = false;

export const CLIENTS_LIST_BATCH_SIZE = 100;

export const AUTO_ENABLE_NAVIGATION_TO = [];
5 changes: 5 additions & 0 deletions src/configs/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -820,3 +820,8 @@ export type PLAN_LIST_SHOW_FI_REASON_COLUMN = typeof PLAN_LIST_SHOW_FI_REASON_CO
/** The max number of client records to get from OpenSRP API endpoint */
export const CLIENTS_LIST_BATCH_SIZE = Number(setEnv('REACT_APP_CLIENTS_LIST_BATCH_SIZE', 200));
export type CLIENTS_LIST_BATCH_SIZE = typeof CLIENTS_LIST_BATCH_SIZE;

export const AUTO_ENABLE_NAVIGATION_TO = String(
setEnv('REACT_APP_AUTO_ENABLE_NAVIGATION_TO', '')
).split(',');
export type AUTO_ENABLE_NAVIGATION_TO = typeof AUTO_ENABLE_NAVIGATION_TO;

0 comments on commit 9df962d

Please sign in to comment.