Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 (
<DatasetProvider
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { DatasetJSDataverseRepository } from '../../../../src/dataset/infrastructure/repositories/DatasetJSDataverseRepository'
import { MetadataBlockInfoJSDataverseRepository } from '../../../../src/metadata-block-info/infrastructure/repositories/MetadataBlockInfoJSDataverseRepository'
import { DatasetNonNumericVersion } from '../../../../src/dataset/domain/models/Dataset'
import { EditDatasetMetadataFactory } from '../../../../src/sections/edit-dataset-metadata/EditDatasetMetadataFactory'
import { LoadingProvider } from '../../../../src/shared/contexts/loading/LoadingProvider'
import { DatasetMother } from '../../dataset/domain/models/DatasetMother'
import { MetadataBlockInfoMother } from '../../metadata-block-info/domain/models/MetadataBlockInfoMother'
import { QueryParamKey, Route } from '../../../../src/sections/Route.enum'

const dataset = DatasetMother.createRealistic()
const metadataBlocksInfoOnEditMode =
MetadataBlockInfoMother.getByCollectionIdDisplayedOnCreateFalse()
const metadataBlocksInfoOnCreateMode =
MetadataBlockInfoMother.getByCollectionIdDisplayedOnCreateTrue()

describe('EditDatasetMetadataFactory', () => {
const persistentId = 'doi:10.5072/FK2/EDITMETA'
let getByPersistentIdStub: ReturnType<typeof cy.stub>

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(<LoadingProvider>{EditDatasetMetadataFactory.create()}</LoadingProvider>, [
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(<LoadingProvider>{EditDatasetMetadataFactory.create()}</LoadingProvider>, [
initialEntry
])

cy.wrap(getByPersistentIdStub).should(
'have.been.calledWith',
persistentId,
DatasetNonNumericVersion.LATEST,
undefined,
true
)
})
})
Loading