Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more strict types and more changes based on review comments
- Loading branch information
1 parent
c929691
commit 18fe2e2
Showing
5 changed files
with
25 additions
and
20 deletions.
There are no files selected for viewing
8 changes: 4 additions & 4 deletions
8
frontend/packages/console-shared/src/utils/__tests__/icon-utils.spec.ts
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 |
---|---|---|
@@ -1,19 +1,19 @@ | ||
import * as _ from 'lodash'; | ||
import { sampleClusterServiceVersions } from '@console/dev-console/src/components/topology/__tests__/topology-test-data'; | ||
import { K8sResourceKind } from '@console/internal/module/k8s'; | ||
import { ClusterServiceVersionKind } from '@console/operator-lifecycle-manager'; | ||
import * as operatorLogo from '../../images/operator.svg'; | ||
import { getImageForCSVIcon } from '../icon-utils'; | ||
import { mockCSVIcon } from '../__mocks__/mock-csv-icon'; | ||
|
||
describe('Icon Utils', () => { | ||
it('should return icon from csv data', () => { | ||
const mockCSV: K8sResourceKind = _.cloneDeep(sampleClusterServiceVersions.data[0]); | ||
const mockCSV = _.cloneDeep(sampleClusterServiceVersions.data[0]) as ClusterServiceVersionKind; | ||
expect(getImageForCSVIcon(mockCSV)).toBe(mockCSVIcon); | ||
}); | ||
|
||
it('should return operator icon if csv has no icon data', () => { | ||
const mockCSV: K8sResourceKind = _.cloneDeep(sampleClusterServiceVersions.data[0]); | ||
mockCSV.spec.icon = ''; | ||
const mockCSV = _.cloneDeep(sampleClusterServiceVersions.data[0]) as ClusterServiceVersionKind; | ||
mockCSV.spec.icon = undefined; | ||
expect(getImageForCSVIcon(mockCSV)).toBe(operatorLogo); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,7 +1,11 @@ | ||
import * as _ from 'lodash'; | ||
import { | ||
ClusterServiceVersionKind, | ||
ClusterServiceVersionIcon, | ||
} from '@console/operator-lifecycle-manager'; | ||
import * as operatorLogo from '../images/operator.svg'; | ||
|
||
export const getImageForCSVIcon = (csv) => { | ||
const icon = _.get(csv, 'spec.icon', []); | ||
export const getImageForCSVIcon = (csv: ClusterServiceVersionKind) => { | ||
const icon: ClusterServiceVersionIcon = _.get(csv, 'spec.icon', []); | ||
return !_.isEmpty(icon) ? `data:${icon[0].mediatype};base64,${icon[0].base64data}` : operatorLogo; | ||
}; |
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
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