Skip to content

Commit 85661cb

Browse files
committed
feat: reset license text
- ensure that the license text is reset whenever a new license expression is selected - reset does not occur if a new license expression is typed instead of selected from the available options - new behavior prevents accidental mismatches between expression and text - adjust e2e tests to always write a trace even when successful
1 parent 74ebf1e commit 85661cb

File tree

7 files changed

+54
-28
lines changed

7 files changed

+54
-28
lines changed

.husky/commit-msg

-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,4 @@
55
#
66
# SPDX-License-Identifier: Apache-2.0
77

8-
. "$(dirname -- "$0")/_/husky.sh"
9-
108
yarn commitlint --edit ${1}

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ Please note, that there seem to be some issues with this plugin. It can help to
140140

141141
### Debugging the end-to-end tests
142142

143-
Each executed end-to-end test creates artifacts in the folder `src/e2e-tests/artifacts`. The artifacts contain the auto-generated .opossum file that the test was run against and, in case the test failed, a Playwright trace file.
143+
Each executed end-to-end test creates artifacts in the folder `src/e2e-tests/artifacts`. The artifacts contain the auto-generated .opossum file that the test was run against and a Playwright trace file.
144144

145145
The trace file includes screenshots and DOM snapshots at each step of the test up to the failure. You can open this file (do not unzip it!) in your browser by going to the [Playwright Trace Viewer](https://trace.playwright.dev/).
146146

src/Frontend/Components/AttributionForm/PackageAutocomplete/PackageAutocomplete.tsx

+15-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export function PackageAutocomplete({
129129
}, [attributeValue, inputValue]);
130130

131131
return (
132-
<Autocomplete
132+
<Autocomplete<PackageInfo, false, true, true>
133133
title={title}
134134
disabled={disabled}
135135
readOnly={readOnly}
@@ -200,6 +200,20 @@ export function PackageAutocomplete({
200200
secondary: (option) =>
201201
typeof option === 'string' ? option : generatePurl(option),
202202
}}
203+
onChange={(_, value) =>
204+
typeof value !== 'string' &&
205+
value[attribute] !== packageInfo[attribute] &&
206+
onEdit?.(() => {
207+
dispatch(
208+
setTemporaryDisplayPackageInfo({
209+
...packageInfo,
210+
[attribute]: value[attribute],
211+
...(attribute === 'licenseName' ? { licenseText: '' } : null),
212+
wasPreferred: undefined,
213+
}),
214+
);
215+
})
216+
}
203217
onInputChange={(event, value) =>
204218
event &&
205219
packageInfo[attribute] !== value &&

src/Frontend/Components/Autocomplete/Autocomplete.tsx

+17-15
Original file line numberDiff line numberDiff line change
@@ -187,25 +187,27 @@ export function Autocomplete<
187187
]).length
188188
}
189189
size={'small'}
190-
InputLabelProps={getInputLabelProps()}
191190
inputRef={ref}
192-
inputProps={{
193-
'aria-label': props['aria-label'],
194-
sx: {
195-
overflowX: 'hidden',
196-
textOverflow: 'ellipsis',
197-
'&::placeholder': {
198-
opacity: 1,
191+
slotProps={{
192+
input: {
193+
startAdornment: startAdornment || renderStartAdornment(),
194+
endAdornment: renderEndAdornment(),
195+
readOnly,
196+
sx,
197+
...(variant === 'filled' && { disableUnderline: true }),
198+
},
199+
inputLabel: getInputLabelProps(),
200+
htmlInput: {
201+
'aria-label': props['aria-label'],
202+
sx: {
203+
overflowX: 'hidden',
204+
textOverflow: 'ellipsis',
205+
'&::placeholder': {
206+
opacity: 1,
207+
},
199208
},
200209
},
201210
}}
202-
InputProps={{
203-
startAdornment: startAdornment || renderStartAdornment(),
204-
endAdornment: renderEndAdornment(),
205-
readOnly,
206-
sx,
207-
...(variant === 'filled' && { disableUnderline: true }),
208-
}}
209211
onKeyDown={(event) => {
210212
// https://github.com/mui/material-ui/issues/21129
211213
event.key === 'Backspace' && event.stopPropagation();

src/e2e-tests/__tests__/updating-attributions.test.ts

+17
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,20 @@ test('switches correctly between previously-preferred and modified previously pr
285285
await attributionDetails.attributionForm.comment.fill(faker.lorem.sentence());
286286
await confirmationDialog.assert.isVisible();
287287
});
288+
289+
test('resets custom license text when user selects suggested license expression', async ({
290+
attributionDetails,
291+
resourcesTree,
292+
}) => {
293+
const licenseText = faker.lorem.sentences();
294+
295+
await resourcesTree.goto(resourceName1);
296+
297+
await attributionDetails.attributionForm.licenseTextToggleButton.click();
298+
await attributionDetails.attributionForm.licenseText.fill(licenseText);
299+
await attributionDetails.attributionForm.assert.licenseTextIs(licenseText);
300+
301+
await attributionDetails.attributionForm.licenseName.click();
302+
await attributionDetails.attributionForm.selectLicense(license1);
303+
await attributionDetails.attributionForm.assert.licenseTextIs('');
304+
});

src/e2e-tests/page-objects/AttributionForm.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,7 @@ export class AttributionForm {
8585
this.licenseTextToggleButton = this.node.getByLabel(
8686
'license-text-toggle-button',
8787
);
88-
this.licenseText = this.node.getByLabel(
89-
text.attributionColumn.licenseText,
90-
{ exact: true },
91-
);
88+
this.licenseText = this.node.getByLabel(text.attributionColumn.licenseText);
9289
this.auditingLabels = {
9390
criticalityLabel: this.node.getByTestId('auditing-option-criticality'),
9491
confidenceLabel: this.node.getByTestId('auditing-option-confidence'),

src/e2e-tests/utils/fixtures.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,9 @@ export const test = base.extend<{
9595
await use(Object.assign(window, { app }));
9696

9797
await window.context().tracing.stop({
98-
path: info.error
99-
? info.outputPath(
100-
`${data?.inputData.metadata.projectId || 'app'}.trace.zip`,
101-
)
102-
: undefined,
98+
path: info.outputPath(
99+
`${data?.inputData.metadata.projectId || 'app'}.trace.zip`,
100+
),
103101
});
104102
await app.close();
105103
},

0 commit comments

Comments
 (0)