Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

KPMP-3335: Make dmd handle missing state gracefully #34

Merged
merged 1 commit into from
Mar 21, 2022
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
6 changes: 4 additions & 2 deletions src/components/PackageDashboard/stateDisplayHelper.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export const getStateDisplayText = (state, stateDisplayMap) => {

if (!stateDisplayMap) {
return '';
}
let stateDisplayText = stateDisplayMap.filter(function(stateDisplayItem) {
if (stateDisplayItem.state === state.state) {
if (state && stateDisplayItem && (stateDisplayItem.state === state.state)) {
return stateDisplayItem;
}
return undefined;
Expand Down
15 changes: 15 additions & 0 deletions src/components/PackageDashboard/stateDisplayHelper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,20 @@ describe('getStateDisplayText', () => {
{ state: 'dead', apps: { dmd: { text: 'oh no' }}}
];
expect(getStateDisplayText(state, stateDisplayMap)).toEqual('hey ho');
});

it('should return blank string if state is undefined', () => {
let state = undefined;
let stateDisplayMap = [
{ state: 'alive', apps: { dmd: { text: 'hey ho' }}},
{ state: 'dead', apps: { dmd: { text: 'oh no' }}}
];
expect(getStateDisplayText(state, stateDisplayMap)).toEqual('');
});

it('should return blank string if stateDisplayMap is undefined', () => {
let state = { state: 'alive' };
let stateDisplayMap = undefined;
expect(getStateDisplayText(state, stateDisplayMap)).toEqual('');
})
});