diff --git a/CHANGELOG.md b/CHANGELOG.md index 57dd57551..c0553a482 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ This changelog follows the principles of [Keep a Changelog](https://keepachangel - After saving on either Edit Template tab (Metadata or Terms), the user is redirected to the templates listing with a success toast instead of staying on the edit page. - Edit Template breadcrumb on the Terms page no longer renders the dataset's "Terms and Guestbook" label (templates have no guestbook). +- Edit Metadata always loads the latest dataset version (draft if present, otherwise latest published), ignoring the browsed `version` query param so it matches JSF / Edit Terms. (#1024) ### Removed diff --git a/src/sections/edit-dataset-metadata/EditDatasetMetadataFactory.tsx b/src/sections/edit-dataset-metadata/EditDatasetMetadataFactory.tsx index 9c7bdc77e..edbf49047 100644 --- a/src/sections/edit-dataset-metadata/EditDatasetMetadataFactory.tsx +++ b/src/sections/edit-dataset-metadata/EditDatasetMetadataFactory.tsx @@ -4,7 +4,7 @@ import { EditDatasetMetadata } from './EditDatasetMetadata' import { DatasetProvider } from '../dataset/DatasetProvider' import { DatasetJSDataverseRepository } from '../../dataset/infrastructure/repositories/DatasetJSDataverseRepository' import { MetadataBlockInfoJSDataverseRepository } from '../../metadata-block-info/infrastructure/repositories/MetadataBlockInfoJSDataverseRepository' -import { searchParamVersionToDomainVersion } from '../../router' +import { DatasetNonNumericVersion } from '../../dataset/domain/models/Dataset' const datasetRepository = new DatasetJSDataverseRepository() const metadataBlockInfoRepository = new MetadataBlockInfoJSDataverseRepository() @@ -18,8 +18,7 @@ export class EditDatasetMetadataFactory { function EditDatasetMetadataWithParams() { const [searchParams] = useSearchParams() const persistentId = searchParams.get('persistentId') ?? undefined - const searchParamVersion = searchParams.get('version') ?? undefined - const version = searchParamVersionToDomainVersion(searchParamVersion) + const version = DatasetNonNumericVersion.LATEST return ( { + const persistentId = 'doi:10.5072/FK2/EDITMETA' + let getByPersistentIdStub: ReturnType + + beforeEach(() => { + getByPersistentIdStub = cy + .stub(DatasetJSDataverseRepository.prototype, 'getByPersistentId') + .resolves(dataset) + cy.stub(DatasetJSDataverseRepository.prototype, 'updateMetadata').resolves(undefined) + cy.stub(DatasetJSDataverseRepository.prototype, 'getDatasetVersionsSummaries').resolves({ + summaries: [], + totalCount: 0 + }) + cy.stub(MetadataBlockInfoJSDataverseRepository.prototype, 'getByCollectionId').resolves( + metadataBlocksInfoOnEditMode + ) + cy.stub( + MetadataBlockInfoJSDataverseRepository.prototype, + 'getDisplayedOnCreateByCollectionId' + ).resolves(metadataBlocksInfoOnCreateMode) + }) + + it('always fetches :latest when the URL carries an older published version', () => { + const initialEntry = `${Route.EDIT_DATASET_METADATA}?${ + QueryParamKey.PERSISTENT_ID + }=${encodeURIComponent(persistentId)}&${QueryParamKey.VERSION}=1.0` + + cy.customMount({EditDatasetMetadataFactory.create()}, [ + initialEntry + ]) + + cy.wrap(getByPersistentIdStub).should( + 'have.been.calledWith', + persistentId, + DatasetNonNumericVersion.LATEST, + undefined, + true + ) + cy.wrap(getByPersistentIdStub).should( + 'not.have.been.calledWith', + persistentId, + '1.0', + undefined, + true + ) + + cy.findByTestId('edit-dataset-metadata-skeleton').should('not.exist') + cy.findByText(/^Host Collection/i).should('exist') + }) + + it('still fetches :latest when the URL has no version param', () => { + const initialEntry = `${Route.EDIT_DATASET_METADATA}?${ + QueryParamKey.PERSISTENT_ID + }=${encodeURIComponent(persistentId)}` + + cy.customMount({EditDatasetMetadataFactory.create()}, [ + initialEntry + ]) + + cy.wrap(getByPersistentIdStub).should( + 'have.been.calledWith', + persistentId, + DatasetNonNumericVersion.LATEST, + undefined, + true + ) + }) +})