Skip to content

Commit

Permalink
Add original source field (opossum-tool#2342)
Browse files Browse the repository at this point in the history
Signed-off-by: Vasily Pozdnyakov <[email protected]>
  • Loading branch information
vasily-pozdnyakov authored Nov 24, 2023
1 parent d81d9c0 commit 00ffc05
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 15 deletions.
6 changes: 4 additions & 2 deletions example-files/opossum_input.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@
"bb61b094-b5ba-4bd0-b218-8ec96b7c5ae0": {
"source": {
"name": "MERGER",
"documentConfidence": 50.0
"documentConfidence": 50.0,
"additionalName": "ScanCode"
},
"attributionConfidence": 100,
"comment": "TypeScript. \nhttps://www.npmjs.com/package/typescript",
Expand All @@ -172,7 +173,8 @@
"bb61b094-b5ba-4bd0-b218-8ec96b7c5af0": {
"source": {
"name": "MERGER",
"documentConfidence": 50.0
"documentConfidence": 50.0,
"additionalName": "REUSER"
},
"attributionConfidence": 100,
"comment": "TypeScript. \nhttps://www.npmjs.com/package/typescript",
Expand Down
4 changes: 4 additions & 0 deletions src/ElectronBackend/input/OpossumInputFileSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
"description": "How much the information is trusted (0: bad, 100: good)",
"minimum": 0,
"maximum": 100
},
"additionalName": {
"type": "string",
"description": "Original source for suggested signals (e.g. a tool like ScanCode)"
}
},
"required": ["name", "documentConfidence"],
Expand Down
17 changes: 10 additions & 7 deletions src/ElectronBackend/input/__tests__/importFromFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import upath from 'upath';
import * as zlib from 'zlib';

import { EMPTY_PROJECT_METADATA } from '../../../Frontend/shared-constants';
import { faker } from '../../../shared/Faker';
import { AllowedFrontendChannels } from '../../../shared/ipc-channels';
import {
Criticality,
Expand Down Expand Up @@ -566,15 +567,16 @@ describe('Test of loading function', () => {
deleteFolder(temporaryPath);
});

it('loads file and parses json successfully, custom metadata', async () => {
it('loads file and parses json successfully, origin Ids and original source', async () => {
const inputFileContentWithOriginIds: ParsedOpossumInputFile = {
...inputFileContent,
externalAttributions: {
uuid: {
source: {
name: 'REUSER:HHC',
source: faker.opossum.source({
name: 'MERGER',
documentConfidence: 13,
},
additionalName: 'Original Source',
}),
packageName: 'react',
originIds: ['abc', 'def'],
},
Expand All @@ -599,10 +601,11 @@ describe('Test of loading function', () => {
externalAttributions: {
attributions: {
uuid: {
source: {
name: 'REUSER:HHC',
source: faker.opossum.source({
name: 'MERGER',
documentConfidence: 13,
},
additionalName: 'Original Source',
}),
packageName: 'react',
originIds: ['abc', 'def'],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const classes = {
},
sourceField: {
marginBottom: '4px',
flex: 0.5,
flex: 0,
flexBasis: 100,
},
};

Expand Down Expand Up @@ -107,7 +108,8 @@ export function AuditingSubPanel(props: AuditingSubPanelProps): ReactElement {
sx={classes.sourceField}
title={'Source'}
text={prettifySource(
props.displayPackageInfo.source.name,
props.displayPackageInfo.source.additionalName ??
props.displayPackageInfo.source.name,
attributionSources,
)}
handleChange={doNothing}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import { screen } from '@testing-library/react';
import { act } from 'react-dom/test-utils';

import { faker } from '../../../../shared/Faker';
import {
DiscreteConfidence,
DisplayPackageInfo,
FollowUp,
FrequentLicenses,
SaveFileArgs,
Source,
} from '../../../../shared/shared-types';
import { text } from '../../../../shared/text';
import { ButtonText, CheckboxLabel } from '../../../enums/enums';
Expand Down Expand Up @@ -281,9 +281,9 @@ describe('The AttributionColumn', () => {
);
});

it('renders a TextBox for the source, if it is defined', () => {
it('renders a source name, if it is defined', () => {
const testTemporaryDisplayPackageInfo: DisplayPackageInfo = {
source: { name: 'The Source', documentConfidence: 10 },
source: faker.opossum.source(),
attributionIds: [],
};
const { store } = renderComponentWithStore(
Expand All @@ -304,9 +304,40 @@ describe('The AttributionColumn', () => {
);
});

expect(
screen.getByDisplayValue(testTemporaryDisplayPackageInfo.source!.name),
);
});

it('renders the name of the original source, if it is defined', () => {
const testTemporaryDisplayPackageInfo: DisplayPackageInfo = {
source: faker.opossum.source({
additionalName: 'Original Source',
}),
attributionIds: [],
};

const { store } = renderComponentWithStore(
<AttributionColumn
isEditable={true}
onSaveButtonClick={doNothing}
onSaveGloballyButtonClick={doNothing}
showManualAttributionData={true}
saveFileRequestListener={doNothing}
onDeleteButtonClick={doNothing}
onDeleteGloballyButtonClick={doNothing}
/>,
);
act(() => {
store.dispatch(setSelectedResourceId('test_id'));
store.dispatch(
setTemporaryDisplayPackageInfo(testTemporaryDisplayPackageInfo),
);
});

expect(
screen.getByDisplayValue(
(testTemporaryDisplayPackageInfo.source as Source).name,
testTemporaryDisplayPackageInfo.source!.additionalName!,
),
);
});
Expand Down
1 change: 1 addition & 0 deletions src/shared/shared-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export interface DisplayPackageInfo extends PackageInfoCore {
export interface Source {
name: string;
documentConfidence: number;
additionalName?: string;
}

export interface Attributions {
Expand Down

0 comments on commit 00ffc05

Please sign in to comment.