From 85661cbc6b2f074b56052ce9d4da3558ebe9823e Mon Sep 17 00:00:00 2001 From: Maxim Stykow Date: Tue, 28 Jan 2025 21:37:51 +0100 Subject: [PATCH] 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 --- .husky/commit-msg | 2 -- CONTRIBUTING.md | 2 +- .../PackageAutocomplete.tsx | 16 +++++++++- .../Components/Autocomplete/Autocomplete.tsx | 32 ++++++++++--------- .../__tests__/updating-attributions.test.ts | 17 ++++++++++ src/e2e-tests/page-objects/AttributionForm.ts | 5 +-- src/e2e-tests/utils/fixtures.ts | 8 ++--- 7 files changed, 54 insertions(+), 28 deletions(-) diff --git a/.husky/commit-msg b/.husky/commit-msg index 3811ee6ef..95197d78b 100755 --- a/.husky/commit-msg +++ b/.husky/commit-msg @@ -5,6 +5,4 @@ # # SPDX-License-Identifier: Apache-2.0 -. "$(dirname -- "$0")/_/husky.sh" - yarn commitlint --edit ${1} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 34f3aefcb..680fe397e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -140,7 +140,7 @@ Please note, that there seem to be some issues with this plugin. It can help to ### Debugging the end-to-end tests -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. +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. 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/). diff --git a/src/Frontend/Components/AttributionForm/PackageAutocomplete/PackageAutocomplete.tsx b/src/Frontend/Components/AttributionForm/PackageAutocomplete/PackageAutocomplete.tsx index 4c3d146ca..f88e1c757 100644 --- a/src/Frontend/Components/AttributionForm/PackageAutocomplete/PackageAutocomplete.tsx +++ b/src/Frontend/Components/AttributionForm/PackageAutocomplete/PackageAutocomplete.tsx @@ -129,7 +129,7 @@ export function PackageAutocomplete({ }, [attributeValue, inputValue]); return ( - title={title} disabled={disabled} readOnly={readOnly} @@ -200,6 +200,20 @@ export function PackageAutocomplete({ secondary: (option) => typeof option === 'string' ? option : generatePurl(option), }} + onChange={(_, value) => + typeof value !== 'string' && + value[attribute] !== packageInfo[attribute] && + onEdit?.(() => { + dispatch( + setTemporaryDisplayPackageInfo({ + ...packageInfo, + [attribute]: value[attribute], + ...(attribute === 'licenseName' ? { licenseText: '' } : null), + wasPreferred: undefined, + }), + ); + }) + } onInputChange={(event, value) => event && packageInfo[attribute] !== value && diff --git a/src/Frontend/Components/Autocomplete/Autocomplete.tsx b/src/Frontend/Components/Autocomplete/Autocomplete.tsx index b7a10cdf9..848e70a6b 100644 --- a/src/Frontend/Components/Autocomplete/Autocomplete.tsx +++ b/src/Frontend/Components/Autocomplete/Autocomplete.tsx @@ -187,25 +187,27 @@ export function Autocomplete< ]).length } size={'small'} - InputLabelProps={getInputLabelProps()} inputRef={ref} - inputProps={{ - 'aria-label': props['aria-label'], - sx: { - overflowX: 'hidden', - textOverflow: 'ellipsis', - '&::placeholder': { - opacity: 1, + slotProps={{ + input: { + startAdornment: startAdornment || renderStartAdornment(), + endAdornment: renderEndAdornment(), + readOnly, + sx, + ...(variant === 'filled' && { disableUnderline: true }), + }, + inputLabel: getInputLabelProps(), + htmlInput: { + 'aria-label': props['aria-label'], + sx: { + overflowX: 'hidden', + textOverflow: 'ellipsis', + '&::placeholder': { + opacity: 1, + }, }, }, }} - InputProps={{ - startAdornment: startAdornment || renderStartAdornment(), - endAdornment: renderEndAdornment(), - readOnly, - sx, - ...(variant === 'filled' && { disableUnderline: true }), - }} onKeyDown={(event) => { // https://github.com/mui/material-ui/issues/21129 event.key === 'Backspace' && event.stopPropagation(); diff --git a/src/e2e-tests/__tests__/updating-attributions.test.ts b/src/e2e-tests/__tests__/updating-attributions.test.ts index a403f34d7..a8fa0d939 100644 --- a/src/e2e-tests/__tests__/updating-attributions.test.ts +++ b/src/e2e-tests/__tests__/updating-attributions.test.ts @@ -285,3 +285,20 @@ test('switches correctly between previously-preferred and modified previously pr await attributionDetails.attributionForm.comment.fill(faker.lorem.sentence()); await confirmationDialog.assert.isVisible(); }); + +test('resets custom license text when user selects suggested license expression', async ({ + attributionDetails, + resourcesTree, +}) => { + const licenseText = faker.lorem.sentences(); + + await resourcesTree.goto(resourceName1); + + await attributionDetails.attributionForm.licenseTextToggleButton.click(); + await attributionDetails.attributionForm.licenseText.fill(licenseText); + await attributionDetails.attributionForm.assert.licenseTextIs(licenseText); + + await attributionDetails.attributionForm.licenseName.click(); + await attributionDetails.attributionForm.selectLicense(license1); + await attributionDetails.attributionForm.assert.licenseTextIs(''); +}); diff --git a/src/e2e-tests/page-objects/AttributionForm.ts b/src/e2e-tests/page-objects/AttributionForm.ts index 47d6cfd26..01b23d90d 100644 --- a/src/e2e-tests/page-objects/AttributionForm.ts +++ b/src/e2e-tests/page-objects/AttributionForm.ts @@ -85,10 +85,7 @@ export class AttributionForm { this.licenseTextToggleButton = this.node.getByLabel( 'license-text-toggle-button', ); - this.licenseText = this.node.getByLabel( - text.attributionColumn.licenseText, - { exact: true }, - ); + this.licenseText = this.node.getByLabel(text.attributionColumn.licenseText); this.auditingLabels = { criticalityLabel: this.node.getByTestId('auditing-option-criticality'), confidenceLabel: this.node.getByTestId('auditing-option-confidence'), diff --git a/src/e2e-tests/utils/fixtures.ts b/src/e2e-tests/utils/fixtures.ts index 90fc50402..ed16a3208 100644 --- a/src/e2e-tests/utils/fixtures.ts +++ b/src/e2e-tests/utils/fixtures.ts @@ -95,11 +95,9 @@ export const test = base.extend<{ await use(Object.assign(window, { app })); await window.context().tracing.stop({ - path: info.error - ? info.outputPath( - `${data?.inputData.metadata.projectId || 'app'}.trace.zip`, - ) - : undefined, + path: info.outputPath( + `${data?.inputData.metadata.projectId || 'app'}.trace.zip`, + ), }); await app.close(); },