-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: start screen most viewed updates v36 (DHIS2-11065) (#1712)
- Loading branch information
1 parent
8fa8a57
commit b3a1fc3
Showing
4 changed files
with
141 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
packages/app/src/components/Visualization/__tests__/utils.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { matchVisualizationWithType } from '../utils' | ||
|
||
let visualizations | ||
|
||
describe('utils', () => { | ||
describe('matchVisualizationWithType', () => { | ||
beforeEach(() => { | ||
visualizations = [ | ||
{ | ||
position: 1, | ||
views: 10, | ||
id: 'aaa111', | ||
created: '2020-01-01', | ||
}, | ||
{ | ||
position: 2, | ||
views: 9, | ||
id: 'bbb222', | ||
created: '2020-01-02', | ||
}, | ||
{ | ||
position: 3, | ||
views: 8, | ||
id: 'ccc333', | ||
created: '2020-01-03', | ||
}, | ||
] | ||
}) | ||
it('all visualizations are matched with a type', () => { | ||
const types = [ | ||
{ | ||
id: 'aaa111', | ||
type: 'typeX', | ||
}, | ||
{ | ||
id: 'bbb222', | ||
type: 'typeY', | ||
}, | ||
{ | ||
id: 'ccc333', | ||
type: 'typeZ', | ||
}, | ||
] | ||
const expectedResult = [ | ||
{ | ||
position: 1, | ||
views: 10, | ||
id: 'aaa111', | ||
created: '2020-01-01', | ||
type: 'typeX', | ||
}, | ||
{ | ||
position: 2, | ||
views: 9, | ||
id: 'bbb222', | ||
created: '2020-01-02', | ||
type: 'typeY', | ||
}, | ||
{ | ||
position: 3, | ||
views: 8, | ||
id: 'ccc333', | ||
created: '2020-01-03', | ||
type: 'typeZ', | ||
}, | ||
] | ||
expect(matchVisualizationWithType(visualizations, types)).toEqual( | ||
expectedResult | ||
) | ||
}) | ||
it('only visualizations with a type are returned', () => { | ||
const types = [ | ||
{ | ||
id: 'aaa111', | ||
type: 'typeX', | ||
}, | ||
{ | ||
id: 'bbb222', | ||
type: 'typeY', | ||
}, | ||
] | ||
const expectedResult = [ | ||
{ | ||
position: 1, | ||
views: 10, | ||
id: 'aaa111', | ||
created: '2020-01-01', | ||
type: 'typeX', | ||
}, | ||
{ | ||
position: 2, | ||
views: 9, | ||
id: 'bbb222', | ||
created: '2020-01-02', | ||
type: 'typeY', | ||
}, | ||
] | ||
expect(matchVisualizationWithType(visualizations, types)).toEqual( | ||
expectedResult | ||
) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export const matchVisualizationWithType = ( | ||
visualizations, | ||
visualizationsWithType | ||
) => { | ||
const result = [] | ||
visualizations.forEach(visualization => { | ||
const type = visualizationsWithType.find( | ||
visWithType => visWithType.id === visualization.id | ||
)?.type | ||
if (type) { | ||
result.push({ | ||
...visualization, | ||
type, | ||
}) | ||
} | ||
}) | ||
return result | ||
} |