diff --git a/CHANGELOG.md b/CHANGELOG.md index 24677b8e6..ffea5b7de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ This changelog follows the principles of [Keep a Changelog](https://keepachangel - Dataset versions: (1) file changes should be `Access: Restricted` instead of `isResticted: true/false`; (2) logic of View Detail button. (#879) - File versions: (1) logic of linking to a file version; (2)If file not included, show text information "File not included in this version.". (#879) - Dataset page publish flow now avoids rendering duplicate tab sets by making tabs skeleton and tabs content mutually exclusive. +- Fixed custom terms navigation url while publishing a datsaet. ### Removed diff --git a/src/sections/dataset/publish-dataset/PublishDatasetModal.tsx b/src/sections/dataset/publish-dataset/PublishDatasetModal.tsx index e1300cef8..40e47ae0b 100644 --- a/src/sections/dataset/publish-dataset/PublishDatasetModal.tsx +++ b/src/sections/dataset/publish-dataset/PublishDatasetModal.tsx @@ -158,9 +158,7 @@ export function PublishDatasetModal({ handleCustomTermsClick={() => { const searchParams = new URLSearchParams(location.search) searchParams.set('tab', 'terms') - const newUrl = `${import.meta.env.BASE_URL}${ - location.pathname - }?${searchParams.toString()}` + const newUrl = `${location.pathname}?${searchParams.toString()}` window.open(newUrl, '_blank') }} diff --git a/tests/component/sections/dataset/dataset-publish/PublishDatasetModal.spec.tsx b/tests/component/sections/dataset/dataset-publish/PublishDatasetModal.spec.tsx index a585e9d76..7e5183bf9 100644 --- a/tests/component/sections/dataset/dataset-publish/PublishDatasetModal.spec.tsx +++ b/tests/component/sections/dataset/dataset-publish/PublishDatasetModal.spec.tsx @@ -34,7 +34,7 @@ const createCollectionRepository = (options: CreateRepositoryOptions = {}) => { type MountOptions = { mountAs?: 'authenticated' | 'superuser' repository?: DatasetRepository - collectionRepository: CollectionRepository | undefined + collectionRepository?: CollectionRepository | undefined parentCollection?: ReturnType handleClose?: sinon.SinonStub dataverseInfoRepository?: DataverseInfoRepository @@ -242,7 +242,7 @@ describe('PublishDatasetModal', () => { .and('include', `/collections/${parentCollection.id}`) }) - it('Displays custom terms when license is undefined', () => { + it('displays custom terms when license is undefined', () => { const parentCollection = UpwardHierarchyNodeMother.createCollection({ isReleased: false }) mountPublishDatasetModal({ @@ -256,6 +256,51 @@ describe('PublishDatasetModal', () => { cy.findByText(/Custom Dataset Terms/).should('exist') }) + it('renders the Custom Dataset Terms link when license is undefined', () => { + mountPublishDatasetModal({ + props: { + license: undefined, + customTerms: CustomTermsMother.create() + } + }) + + cy.findByRole('link', { name: /Custom Dataset Terms/ }).should('exist') + }) + + it('does not render the Custom Dataset Terms link when license is defined', () => { + mountPublishDatasetModal({ + props: { + license: LicenseMother.create(), + customTerms: undefined + } + }) + + cy.findByText(/Custom Dataset Terms/).should('not.exist') + cy.findByRole('link', { name: 'CC0 1.0' }).should('exist') + }) + + it('opens the terms tab URL when Custom Dataset Terms link is clicked', () => { + const windowOpenStub = cy.stub().as('windowOpen') + cy.window().then((win) => { + cy.stub(win, 'open').callsFake(windowOpenStub) + }) + + mountPublishDatasetModal({ + props: { + license: undefined, + customTerms: CustomTermsMother.create() + } + }) + + cy.findByRole('link', { name: /Custom Dataset Terms/ }).click() + + cy.get('@windowOpen').should('have.been.calledOnce') + cy.get('@windowOpen').then((stub) => { + const calledUrl = (stub as unknown as sinon.SinonStub).firstCall.args[0] as string + expect(calledUrl).to.include('tab=terms') + }) + }) + it('Displays disclaimer text from settings', () => { const dataverseInfoRepository = new DataverseInfoMockRepository() const disclaimerText = 'This is custom text for the dataset publish popup.'