Skip to content

Commit

Permalink
chore: remove unused functions in orgUnit module (#290)
Browse files Browse the repository at this point in the history
These functions were leftover after the OrgUnitDimension was moved to d2-ui-analytics.

Because files were renamed,, it's a little difficult to see what I actually changed. This is what has changed:

renamed file orgUnitDimensions.js to orgUnit.js
renamed "removeOrgUnitLastPathSegment" to "removeLastPathSegment"
deleted all functions from orgUnit.js that were not imported anywhere
deleted all tests for removed functions
  • Loading branch information
jenniferarnesen committed May 23, 2019
1 parent d118422 commit 556e5b3
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 514 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ import { apiFetchRecommendedIds } from '../../../api/dimensions';
import { FIXED_DIMENSIONS } from '../../../modules/fixedDimensions';
import {
getOrgUnitsFromIds,
removeOrgUnitLastPathSegment,
} from '../../../modules/orgUnitDimensions';
removeLastPathSegment,
} from '../../../modules/orgUnit';

const dxId = FIXED_DIMENSIONS.dx.id;
const peId = FIXED_DIMENSIONS.pe.id;
Expand Down Expand Up @@ -95,7 +95,7 @@ export class DialogManager extends Component {
};

if (ou.path) {
const path = removeOrgUnitLastPathSegment(ou.path);
const path = removeLastPathSegment(ou.path);

forParentGraphMap[ou.id] =
path === `/${ou.id}` ? '' : path.replace(/^\//, '');
Expand Down
73 changes: 73 additions & 0 deletions packages/app/src/modules/__tests__/orgUnit.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { getOrgUnitsFromIds, removeLastPathSegment } from '../orgUnit';

describe('getOrgUnitsFromIds', () => {
it('returns org units with ids in given array', () => {
const ids = ['ID1', 'ID2', 'LEVEL-LEVEL', 'GROUP-GROUP_ID'];
const metadata = {
ID1: {
id: 'ID1',
name: 'Org unit 1',
path: '/ID1',
},
ID2: {
id: 'ID2',
name: 'Org unit 2',
path: '/ID2',
},
};
const parentGraphMap = {};

const orgUnits = getOrgUnitsFromIds(ids, metadata, parentGraphMap);

// test that it only extracts org units, not levels/groups
expect(orgUnits.length).toEqual(2);

orgUnits.forEach(orgUnit => {
expect(orgUnit.id).toEqual(metadata[orgUnit.id].id);
expect(orgUnit.name).toEqual(metadata[orgUnit.id].name);
expect(orgUnit.path).toEqual(metadata[orgUnit.id].path);
});
});

it('returns empty array if there no org units in ou dimension', () => {
const ids = [];
const metadata = {};
const parentGraphMap = {};

expect(getOrgUnitsFromIds(ids, metadata, parentGraphMap)).toEqual([]);
});

it('only extracts org unit ids, not groups/levels', () => {
const levelId = 'LEVEL_ID';
const groupId = 'GROUP_ID';

const ids = [`LEVEL-${levelId}`, `GROUP-${groupId}`];
const metadata = {
[levelId]: { name: 'Level', level: 1 },
[groupId]: { name: 'Group' },
};
const parentGraphMap = {};

expect(getOrgUnitsFromIds(ids, metadata, parentGraphMap)).toEqual([]);
});
});

describe('removeLastPathSegment', () => {
it('handles a root path', () => {
const path = '/';

expect(removeLastPathSegment(path)).toEqual(path);
});

it('handles a path with single segment', () => {
const path = '/abc';

expect(removeLastPathSegment(path)).toEqual(path);
});

it('handles a path with multiple segments', () => {
const path = 'ABC/def/GHI';

expect(removeLastPathSegment(path)).toEqual('ABC/def');
});
});
Loading

0 comments on commit 556e5b3

Please sign in to comment.