diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f90edbeb..f0fee4cad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ This changelog follows the principles of [Keep a Changelog](https://keepachangel - Changed the way we were handling DATE type metadata field validation to better match the backend validation and give users better error messages. For example, for an input like “foo AD”, we now show “Production Date is not a valid date. The AD year must be numeric.“. For an input like “99999 AD”, we now show “Production Date is not a valid date. The AD year cant be higher than 9999.“. For an input like “[-9999?], we now show “Production Date is not a valid date. The year in brackets cannot be negative.“, etc. - The SPA now fetches the runtime configuration from `config.js` on each load, allowing configurations without rebuilding the app. We don't use `.env` variables at build time anymore. - Renamed dataset template fetch/create use cases and DTOs to `getTemplatesByCollectionId` and `CreateTemplateDTO` for API alignment, and added new `getTemplate` and `deleteTemplate` use cases for retrieving a single template by ID and deleting templates. +- Added disclaimer text and custom popup text to Publish Dataset modal for better communication of the implications of publishing a dataset. The text can be configured through the runtime configuration. ### Fixed diff --git a/package-lock.json b/package-lock.json index cf249ad1d..42ad7d2b4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@dnd-kit/sortable": "8.0.0", "@dnd-kit/utilities": "3.2.2", "@faker-js/faker": "7.6.0", - "@iqss/dataverse-client-javascript": "2.0.0-alpha.85", + "@iqss/dataverse-client-javascript": "2.1.0-pr422.1631011", "@iqss/dataverse-design-system": "*", "@istanbuljs/nyc-config-typescript": "1.0.2", "@tanstack/react-table": "8.9.2", @@ -1954,9 +1954,9 @@ }, "node_modules/@iqss/dataverse-client-javascript": { "name": "@IQSS/dataverse-client-javascript", - "version": "2.0.0-alpha.85", - "resolved": "https://npm.pkg.github.com/download/@IQSS/dataverse-client-javascript/2.0.0-alpha.85/9f7d8be5c1fbe022c11fcc6d956bbf1cc4821776", - "integrity": "sha512-2aEA0MdkhFjugxImJ3a334jlVbwmNMDVsFXnwPutbbkqn89UMXClMxADkqlmLQ3/4dOMtOrdVDitxYsYmYZ6RQ==", + "version": "2.1.0-pr422.1631011", + "resolved": "https://npm.pkg.github.com/download/@IQSS/dataverse-client-javascript/2.1.0-pr422.1631011/1bdf6f4d5a705ee8e1b9efdba5691209df08853d", + "integrity": "sha512-HsC/RmIQ8skAY3KiANvib1sg+JGwS87ieGTdd29EsPzL3PTPh0z60Ll11qUQriQtQULA3Bk7pE2+T5GVf6LwPQ==", "license": "MIT", "dependencies": { "@types/node": "^18.15.11", diff --git a/package.json b/package.json index 3b8b27edf..41fcd91a5 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "@dnd-kit/sortable": "8.0.0", "@dnd-kit/utilities": "3.2.2", "@faker-js/faker": "7.6.0", - "@iqss/dataverse-client-javascript": "2.0.0-alpha.85", + "@iqss/dataverse-client-javascript": "2.1.0-pr422.1631011", "@iqss/dataverse-design-system": "*", "@istanbuljs/nyc-config-typescript": "1.0.2", "@tanstack/react-table": "8.9.2", diff --git a/src/info/domain/repositories/DataverseInfoRepository.ts b/src/info/domain/repositories/DataverseInfoRepository.ts index aa19be558..874fa6498 100644 --- a/src/info/domain/repositories/DataverseInfoRepository.ts +++ b/src/info/domain/repositories/DataverseInfoRepository.ts @@ -12,4 +12,6 @@ export interface DataverseInfoRepository { getHasPublicStore: () => Promise> getExternalStatusesAllowed: () => Promise> getAvailableDatasetMetadataExportFormats: () => Promise + getDatasetPublishPopupCustomText: () => Promise> + getPublishDatasetDisclaimerText: () => Promise> } diff --git a/src/info/domain/useCases/getDatasetPublishPopupCustomText.ts b/src/info/domain/useCases/getDatasetPublishPopupCustomText.ts new file mode 100644 index 000000000..5c20966c8 --- /dev/null +++ b/src/info/domain/useCases/getDatasetPublishPopupCustomText.ts @@ -0,0 +1,8 @@ +import { Setting } from '@/settings/domain/models/Setting' +import { DataverseInfoRepository } from '../repositories/DataverseInfoRepository' + +export function getDatasetPublishPopupCustomText( + dataverseInfoRepository: DataverseInfoRepository +): Promise> { + return dataverseInfoRepository.getDatasetPublishPopupCustomText() +} diff --git a/src/info/domain/useCases/getPublishDatasetDisclaimerText.ts b/src/info/domain/useCases/getPublishDatasetDisclaimerText.ts new file mode 100644 index 000000000..fa2064b44 --- /dev/null +++ b/src/info/domain/useCases/getPublishDatasetDisclaimerText.ts @@ -0,0 +1,8 @@ +import { Setting } from '@/settings/domain/models/Setting' +import { DataverseInfoRepository } from '../repositories/DataverseInfoRepository' + +export function getPublishDatasetDisclaimerText( + dataverseInfoRepository: DataverseInfoRepository +): Promise> { + return dataverseInfoRepository.getPublishDatasetDisclaimerText() +} diff --git a/src/info/infrastructure/repositories/DataverseInfoJSDataverseRepository.ts b/src/info/infrastructure/repositories/DataverseInfoJSDataverseRepository.ts index 54544f84f..d1d3c6580 100644 --- a/src/info/infrastructure/repositories/DataverseInfoJSDataverseRepository.ts +++ b/src/info/infrastructure/repositories/DataverseInfoJSDataverseRepository.ts @@ -4,6 +4,8 @@ import { getMaxEmbargoDurationInMonths, getZipDownloadLimit, getAvailableDatasetMetadataExportFormats, + getPublishDatasetDisclaimerText, + getDatasetPublishPopupCustomText, ReadError } from '@iqss/dataverse-client-javascript' import { DataverseInfoRepository } from '@/info/domain/repositories/DataverseInfoRepository' @@ -102,4 +104,37 @@ export class DataverseInfoJSDataverseRepository implements DataverseInfoReposito getAvailableDatasetMetadataExportFormats(): Promise { return getAvailableDatasetMetadataExportFormats.execute() } + + getPublishDatasetDisclaimerText(): Promise> { + return getPublishDatasetDisclaimerText + .execute() + .then((text) => { + return { + name: SettingName.PUBLISH_DATASET_DISCLAIMER_TEXT, + value: text + } + }) + .catch(() => { + // In case of error, we default to an empty string which indicates no disclaimer text. + return { + name: SettingName.PUBLISH_DATASET_DISCLAIMER_TEXT, + value: '' + } + }) + } + getDatasetPublishPopupCustomText(): Promise> { + return getDatasetPublishPopupCustomText + .execute() + .then((text) => ({ + name: SettingName.DATASET_PUBLISH_POPUP_CUSTOM_TEXT, + value: text + })) + .catch(() => { + // In case of error, we default to an empty string which indicates no custom text. + return { + name: SettingName.DATASET_PUBLISH_POPUP_CUSTOM_TEXT, + value: '' + } + }) + } } diff --git a/src/sections/dataset/publish-dataset/PublishDatasetModal.module.scss b/src/sections/dataset/publish-dataset/PublishDatasetModal.module.scss index 59a26cb95..e568ea919 100644 --- a/src/sections/dataset/publish-dataset/PublishDatasetModal.module.scss +++ b/src/sections/dataset/publish-dataset/PublishDatasetModal.module.scss @@ -7,3 +7,21 @@ .secondaryText { color: $dv-subtext-color; } + +.disclaimerText { + + label { + color: $dv-danger-color; + } +} + +.customPopupTextBlock { + border: 1px solid $dv-border-color; + background-color: #f8f9fa; + padding: 0.75rem 1rem; + border-radius: 0.25rem; +} + +.customPopupText { + margin: 0; + color: $dv-text-color; +} diff --git a/src/sections/dataset/publish-dataset/PublishDatasetModal.tsx b/src/sections/dataset/publish-dataset/PublishDatasetModal.tsx index e2909fe40..220aa06b1 100644 --- a/src/sections/dataset/publish-dataset/PublishDatasetModal.tsx +++ b/src/sections/dataset/publish-dataset/PublishDatasetModal.tsx @@ -17,9 +17,11 @@ import { PublishDatasetHelpText } from './PublishDatasetHelpText' import { CollectionRepository } from '@/collection/domain/repositories/CollectionRepository' import { UpwardHierarchyNode } from '@/shared/hierarchy/domain/models/UpwardHierarchyNode' import { DatasetLicense } from '@/dataset/domain/models/Dataset' -import styles from './PublishDatasetModal.module.scss' import { PublishLicense } from '@/sections/dataset/publish-dataset/PublishLicense' import { CustomTerms } from '@/sections/dataset/dataset-terms/CustomTerms' +import { useSettings } from '@/sections/settings/SettingsContext' +import { SettingName } from '@/settings/domain/models/Setting' +import styles from './PublishDatasetModal.module.scss' interface PublishDatasetModalProps { show: boolean @@ -53,6 +55,7 @@ export function PublishDatasetModal({ const { t } = useTranslation('dataset') const { user } = useSession() const navigate = useNavigate() + const { getSettingByName } = useSettings() const { submissionStatus, submitPublish, publishError } = usePublishDataset( repository, collectionRepository, @@ -69,6 +72,19 @@ export function PublishDatasetModal({ } const nextMajorVersionString = nextMajorVersion ? nextMajorVersion : '' const nextMinorVersionString = nextMinorVersion ? nextMinorVersion : '' + + const publishDisclaimerText = getSettingByName( + SettingName.PUBLISH_DATASET_DISCLAIMER_TEXT + )?.value + + const datasetPublishPopupCustomText = getSettingByName( + SettingName.DATASET_PUBLISH_POPUP_CUSTOM_TEXT + )?.value + + const shouldShowCustomPopupText = Boolean(datasetPublishPopupCustomText?.trim()) + const shouldShowDisclaimer = Boolean(publishDisclaimerText?.trim()) + const [isDisclaimerAccepted, setIsDisclaimerAccepted] = useState(false) + function onPublishSucceed() { navigate( `${Route.DATASETS}?${QueryParamKey.PERSISTENT_ID}=${persistentId}&${QueryParamKey.VERSION}=${DatasetNonNumericVersionSearchParam.DRAFT}`, @@ -81,8 +97,13 @@ export function PublishDatasetModal({ } const modalTitle = t('publish.title') + const handleCloseWithReset = () => { + setIsDisclaimerAccepted(false) + handleClose() + } + return ( - + {t('publish.title')} @@ -97,6 +118,12 @@ export function PublishDatasetModal({ requiresMajorVersionUpdate={requiresMajorVersionUpdate ?? false} /> + {shouldShowCustomPopupText && ( +
+

{datasetPublishPopupCustomText}

+
+ )} + {releasedVersionExists && !requiresMajorVersionUpdate && ( <> @@ -139,10 +166,24 @@ export function PublishDatasetModal({ window.open(newUrl, '_blank') }} /> +

{t('publish.termsText')}

+ + {shouldShowDisclaimer && ( + + setIsDisclaimerAccepted(e.target.checked)} + label={publishDisclaimerText} + /> + + )} {submissionStatus === SubmissionStatus.Errored && @@ -159,7 +200,10 @@ export function PublishDatasetModal({ submitPublish(versionUpdateType) }} type="submit" - disabled={submissionStatus === SubmissionStatus.IsSubmitting}> + disabled={ + submissionStatus === SubmissionStatus.IsSubmitting || + (shouldShowDisclaimer && !isDisclaimerAccepted) + }> {t('publish.continueButton')} {submissionStatus === SubmissionStatus.IsSubmitting && ( @@ -171,7 +215,7 @@ export function PublishDatasetModal({ withSpacing variant="secondary" type="button" - onClick={handleClose} + onClick={handleCloseWithReset} disabled={submissionStatus === SubmissionStatus.IsSubmitting}> {t('publish.cancelButton')} diff --git a/src/sections/settings/SettingsProvider.tsx b/src/sections/settings/SettingsProvider.tsx index ce77eeb0a..3f470e09e 100644 --- a/src/sections/settings/SettingsProvider.tsx +++ b/src/sections/settings/SettingsProvider.tsx @@ -4,6 +4,8 @@ import { Setting, SettingName } from '../../settings/domain/models/Setting' import { DataverseInfoRepository } from '@/info/domain/repositories/DataverseInfoRepository' import { getZipDownloadLimit } from '@/info/domain/useCases/getZipDownloadLimit' import { getMaxEmbargoDurationInMonths } from '@/info/domain/useCases/getMaxEmbargoDurationInMonths' +import { getPublishDatasetDisclaimerText } from '@/info/domain/useCases/getPublishDatasetDisclaimerText' +import { getDatasetPublishPopupCustomText } from '@/info/domain/useCases/getDatasetPublishPopupCustomText' import { getHasPublicStore } from '@/info/domain/useCases/getHasPublicStore' import { getExternalStatusesAllowed } from '@/info/domain/useCases/getExternalStatusesAllowed' import { AppLoader } from '../shared/layout/app-loader/AppLoader' @@ -26,7 +28,9 @@ export function SettingsProvider({ getZipDownloadLimit(dataverseInfoRepository), getMaxEmbargoDurationInMonths(dataverseInfoRepository), getHasPublicStore(dataverseInfoRepository), - getExternalStatusesAllowed(dataverseInfoRepository) + getExternalStatusesAllowed(dataverseInfoRepository), + getDatasetPublishPopupCustomText(dataverseInfoRepository), + getPublishDatasetDisclaimerText(dataverseInfoRepository) ]) setSettings(settingsResponse) diff --git a/src/settings/domain/models/Setting.ts b/src/settings/domain/models/Setting.ts index 5492848a8..6ee0ff3af 100644 --- a/src/settings/domain/models/Setting.ts +++ b/src/settings/domain/models/Setting.ts @@ -2,7 +2,9 @@ export enum SettingName { ZIP_DOWNLOAD_LIMIT = 'ZIP_DOWNLOAD_LIMIT', ALLOWED_EXTERNAL_STATUSES = 'ALLOWED_EXTERNAL_STATUSES', HAS_PUBLIC_STORE = 'HAS_PUBLIC_STORE', - MAX_EMBARGO_DURATION_IN_MONTHS = 'MAX_EMBARGO_DURATION_IN_MONTHS' + MAX_EMBARGO_DURATION_IN_MONTHS = 'MAX_EMBARGO_DURATION_IN_MONTHS', + PUBLISH_DATASET_DISCLAIMER_TEXT = 'PUBLISH_DATASET_DISCLAIMER_TEXT', + DATASET_PUBLISH_POPUP_CUSTOM_TEXT = 'DATASET_PUBLISH_POPUP_CUSTOM_TEXT' } export interface Setting { diff --git a/src/stories/WithSettings.tsx b/src/stories/WithSettings.tsx index f025eccbf..c13051d31 100644 --- a/src/stories/WithSettings.tsx +++ b/src/stories/WithSettings.tsx @@ -25,6 +25,16 @@ export const WithSettings = (Story: StoryFn) => { case SettingName.MAX_EMBARGO_DURATION_IN_MONTHS: return SettingMother.createMaxEmbargoDurationInMonths(-1) as Setting + case SettingName.DATASET_PUBLISH_POPUP_CUSTOM_TEXT: + return SettingMother.createDatasetPublishPopupCustomText( + 'This is custom text for the dataset publish popup.' + ) as Setting + case SettingName.PUBLISH_DATASET_DISCLAIMER_TEXT: + return SettingMother.createPublishDatasetDisclaimerText( + 'This is custom text for the publish dataset disclaimer.' + ) as Setting + default: + throw new Error(`No mock implementation for setting`) } } diff --git a/src/stories/dataset/publish-dataset/PublishDatasetModal.stories.tsx b/src/stories/dataset/publish-dataset/PublishDatasetModal.stories.tsx index eea4ca804..501767a4a 100644 --- a/src/stories/dataset/publish-dataset/PublishDatasetModal.stories.tsx +++ b/src/stories/dataset/publish-dataset/PublishDatasetModal.stories.tsx @@ -8,6 +8,7 @@ import { CollectionMockRepository } from '@/stories/collection/CollectionMockRep import { UpwardHierarchyNodeMother } from '@tests/component/shared/hierarchy/domain/models/UpwardHierarchyNodeMother' import { CustomTermsMother } from '@tests/component/dataset/domain/models/TermsOfUseMother' import { LicenseMother } from '@tests/component/dataset/domain/models/LicenseMother' +import { WithSettings } from '@/stories/WithSettings' const meta: Meta = { title: 'Sections/Dataset Page/PublishDatasetModal', @@ -117,3 +118,33 @@ export const WithCustomTerms: Story = { handleClose={() => {}}> ) } +export const withTextSettings: Story = { + decorators: [WithLoggedInUser, WithSettings], + render: () => ( + {}}> + ) +} +export const withTextSettingsAndCustomTerms: Story = { + decorators: [WithLoggedInUser, WithSettings], + render: () => ( + {}}> + ) +} diff --git a/src/stories/shared-mock-repositories/info/DataverseInfoMockEmptyRepository.ts b/src/stories/shared-mock-repositories/info/DataverseInfoMockEmptyRepository.ts new file mode 100644 index 000000000..67dfc91e6 --- /dev/null +++ b/src/stories/shared-mock-repositories/info/DataverseInfoMockEmptyRepository.ts @@ -0,0 +1,86 @@ +import { DatasetMetadataExportFormats } from '@/info/domain/models/DatasetMetadataExportFormats' +import { DataverseVersion } from '@/info/domain/models/DataverseVersion' +import { TermsOfUse } from '@/info/domain/models/TermsOfUse' +import { DataverseInfoRepository } from '@/info/domain/repositories/DataverseInfoRepository' +import { Setting, SettingName } from '@/settings/domain/models/Setting' +import { ZipDownloadLimit } from '@/settings/domain/models/ZipDownloadLimit' +import { FileSizeUnit } from '@/files/domain/models/FileMetadata' + +export class DataverseInfoMockEmptyRepository implements DataverseInfoRepository { + private readonly delayMs = 100 + + getVersion(): Promise { + return new Promise((resolve) => { + setTimeout(() => { + resolve({} as DataverseVersion) + }, this.delayMs) + }) + } + + getTermsOfUse(): Promise { + return new Promise((resolve) => { + setTimeout(() => { + resolve('') + }, this.delayMs) + }) + } + + getZipDownloadLimit(): Promise> { + return new Promise((resolve) => { + setTimeout(() => { + resolve({ + name: SettingName.ZIP_DOWNLOAD_LIMIT, + value: new ZipDownloadLimit(0, FileSizeUnit.BYTES) + }) + }, this.delayMs) + }) + } + + getMaxEmbargoDurationInMonths(): Promise> { + return new Promise((resolve) => { + setTimeout(() => { + resolve({ name: SettingName.MAX_EMBARGO_DURATION_IN_MONTHS, value: 0 }) + }, this.delayMs) + }) + } + + getHasPublicStore(): Promise> { + return new Promise((resolve) => { + setTimeout(() => { + resolve({ name: SettingName.HAS_PUBLIC_STORE, value: false }) + }, this.delayMs) + }) + } + + getExternalStatusesAllowed(): Promise> { + return new Promise((resolve) => { + setTimeout(() => { + resolve({ name: SettingName.ALLOWED_EXTERNAL_STATUSES, value: [] }) + }, this.delayMs) + }) + } + + getAvailableDatasetMetadataExportFormats(): Promise { + return new Promise((resolve) => { + setTimeout(() => { + resolve({}) + }, this.delayMs) + }) + } + + getPublishDatasetDisclaimerText(): Promise> { + return new Promise((resolve) => { + setTimeout(() => { + resolve({ name: SettingName.PUBLISH_DATASET_DISCLAIMER_TEXT, value: '' }) + }, this.delayMs) + }) + } + + getDatasetPublishPopupCustomText(): Promise> { + return new Promise((resolve) => { + setTimeout(() => { + resolve({ name: SettingName.DATASET_PUBLISH_POPUP_CUSTOM_TEXT, value: '' }) + }, this.delayMs) + }) + } +} diff --git a/src/stories/shared-mock-repositories/info/DataverseInfoMockErrorRepository.ts b/src/stories/shared-mock-repositories/info/DataverseInfoMockErrorRepository.ts index 7ad95ecd3..9ffe94f07 100644 --- a/src/stories/shared-mock-repositories/info/DataverseInfoMockErrorRepository.ts +++ b/src/stories/shared-mock-repositories/info/DataverseInfoMockErrorRepository.ts @@ -61,4 +61,18 @@ export class DataverseInfoMockErrorRepository implements DataverseInfoMockReposi }, FakerHelper.loadingTimout()) }) } + getPublishDatasetDisclaimerText(): Promise> { + return new Promise((_resolve, reject) => { + setTimeout(() => { + reject() + }, FakerHelper.loadingTimout()) + }) + } + getDatasetPublishPopupCustomText(): Promise> { + return new Promise((_resolve, reject) => { + setTimeout(() => { + reject() + }, FakerHelper.loadingTimout()) + }) + } } diff --git a/src/stories/shared-mock-repositories/info/DataverseInfoMockLoadingkRepository.ts b/src/stories/shared-mock-repositories/info/DataverseInfoMockLoadingkRepository.ts index 4e3df43cd..f71384749 100644 --- a/src/stories/shared-mock-repositories/info/DataverseInfoMockLoadingkRepository.ts +++ b/src/stories/shared-mock-repositories/info/DataverseInfoMockLoadingkRepository.ts @@ -33,4 +33,10 @@ export class DataverseInfoMockLoadingRepository implements DataverseInfoMockRepo getAvailableDatasetMetadataExportFormats(): Promise { return new Promise(() => {}) } + getPublishDatasetDisclaimerText(): Promise> { + return new Promise(() => {}) + } + getDatasetPublishPopupCustomText(): Promise> { + return new Promise(() => {}) + } } diff --git a/src/stories/shared-mock-repositories/info/DataverseInfoMockRepository.ts b/src/stories/shared-mock-repositories/info/DataverseInfoMockRepository.ts index 174e31b30..8b5d48b72 100644 --- a/src/stories/shared-mock-repositories/info/DataverseInfoMockRepository.ts +++ b/src/stories/shared-mock-repositories/info/DataverseInfoMockRepository.ts @@ -75,4 +75,18 @@ export class DataverseInfoMockRepository implements DataverseInfoRepository { }, FakerHelper.loadingTimout()) }) } + getPublishDatasetDisclaimerText(): Promise> { + return new Promise((resolve) => { + setTimeout(() => { + resolve(SettingMother.createPublishDatasetDisclaimerText()) + }, FakerHelper.loadingTimout()) + }) + } + getDatasetPublishPopupCustomText(): Promise> { + return new Promise((resolve) => { + setTimeout(() => { + resolve(SettingMother.createDatasetPublishPopupCustomText()) + }, FakerHelper.loadingTimout()) + }) + } } diff --git a/tests/component/info/domain/hooks/useGetAvailableDatasetMetadataExportFormats.spec.tsx b/tests/component/info/domain/hooks/useGetAvailableDatasetMetadataExportFormats.spec.tsx index b2f26e3a0..b935b5cd4 100644 --- a/tests/component/info/domain/hooks/useGetAvailableDatasetMetadataExportFormats.spec.tsx +++ b/tests/component/info/domain/hooks/useGetAvailableDatasetMetadataExportFormats.spec.tsx @@ -3,8 +3,9 @@ import { ReadError } from '@iqss/dataverse-client-javascript' import { DataverseInfoRepository } from '@/info/domain/repositories/DataverseInfoRepository' import { useGetAvailableDatasetMetadataExportFormats } from '@/info/domain/hooks/useGetAvailableDatasetMetadataExportFormats' import { DatasetMetadataExportFormatsMother } from '../models/DatasetMetadataExportFormatsMother' +import { DataverseInfoMockEmptyRepository } from '@/stories/shared-mock-repositories/info/DataverseInfoMockEmptyRepository' -const dataverseInfoRepository: DataverseInfoRepository = {} as DataverseInfoRepository +const dataverseInfoRepository: DataverseInfoRepository = new DataverseInfoMockEmptyRepository() const availableDsMetadataExportFormats = DatasetMetadataExportFormatsMother.create() describe('useGetAvailableDatasetMetadataExportFormats', () => { diff --git a/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetPermissionsMenu.spec.tsx b/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetPermissionsMenu.spec.tsx index dfea23efa..e4f103f1c 100644 --- a/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetPermissionsMenu.spec.tsx +++ b/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetPermissionsMenu.spec.tsx @@ -3,20 +3,15 @@ import { DatasetMother, DatasetPermissionsMother } from '../../../../dataset/domain/models/DatasetMother' -import { DataverseInfoRepository } from '../../../../../../src/info/domain/repositories/DataverseInfoRepository' import { SettingMother } from '../../../../settings/domain/models/SettingMother' import { SettingsProvider } from '../../../../../../src/sections/settings/SettingsProvider' +import { DataverseInfoMockEmptyRepository } from '@/stories/shared-mock-repositories/info/DataverseInfoMockEmptyRepository' -const dataverseInfoRepository = {} as DataverseInfoRepository - +let dataverseInfoRepository: DataverseInfoMockEmptyRepository describe('EditDatasetPermissionsMenu', () => { beforeEach(() => { - dataverseInfoRepository.getHasPublicStore = cy.stub().resolves({}) - dataverseInfoRepository.getExternalStatusesAllowed = cy.stub().resolves({}) - dataverseInfoRepository.getMaxEmbargoDurationInMonths = cy.stub().resolves({}) - dataverseInfoRepository.getZipDownloadLimit = cy.stub().resolves({}) + dataverseInfoRepository = new DataverseInfoMockEmptyRepository() }) - it('renders the EditDatasetPermissionsMenu if the user has manage dataset permissions', () => { const dataset = DatasetMother.create({ permissions: DatasetPermissionsMother.createWithManageDatasetPermissionsAllowed(), diff --git a/tests/component/sections/dataset/dataset-action-buttons/publish-dataset-menu/ChangeCurationStatusMenu.spec.tsx b/tests/component/sections/dataset/dataset-action-buttons/publish-dataset-menu/ChangeCurationStatusMenu.spec.tsx index a96399010..e8fe78ca3 100644 --- a/tests/component/sections/dataset/dataset-action-buttons/publish-dataset-menu/ChangeCurationStatusMenu.spec.tsx +++ b/tests/component/sections/dataset/dataset-action-buttons/publish-dataset-menu/ChangeCurationStatusMenu.spec.tsx @@ -4,15 +4,13 @@ import { SettingMother } from '../../../../settings/domain/models/SettingMother' import { SettingsProvider } from '../../../../../../src/sections/settings/SettingsProvider' import { DataverseInfoRepository } from '@/info/domain/repositories/DataverseInfoRepository' import { NotImplementedModalProvider } from '../../../../../../src/sections/not-implemented/NotImplementedModalProvider' +import { DataverseInfoMockEmptyRepository } from '@/stories/shared-mock-repositories/info/DataverseInfoMockEmptyRepository' -const dataverseInfoRepository = {} as DataverseInfoRepository +let dataverseInfoRepository: DataverseInfoRepository describe('ChangeCurationStatusMenu', () => { beforeEach(() => { - dataverseInfoRepository.getHasPublicStore = cy.stub().resolves({}) - dataverseInfoRepository.getExternalStatusesAllowed = cy.stub().resolves({}) - dataverseInfoRepository.getMaxEmbargoDurationInMonths = cy.stub().resolves({}) - dataverseInfoRepository.getZipDownloadLimit = cy.stub().resolves({}) + dataverseInfoRepository = new DataverseInfoMockEmptyRepository() }) it('renders the ChangeCurationStatusMenu if external statuses are allowed and the user has update dataset permissions', () => { diff --git a/tests/component/sections/dataset/dataset-action-buttons/publish-dataset-menu/PublishDatasetMenu.spec.tsx b/tests/component/sections/dataset/dataset-action-buttons/publish-dataset-menu/PublishDatasetMenu.spec.tsx index c09e26e19..b51366b36 100644 --- a/tests/component/sections/dataset/dataset-action-buttons/publish-dataset-menu/PublishDatasetMenu.spec.tsx +++ b/tests/component/sections/dataset/dataset-action-buttons/publish-dataset-menu/PublishDatasetMenu.spec.tsx @@ -5,21 +5,19 @@ import { DatasetPermissionsMother, DatasetVersionMother } from '../../../../dataset/domain/models/DatasetMother' -import { DataverseInfoRepository } from '@/info/domain/repositories/DataverseInfoRepository' import { CollectionRepository } from '@/collection/domain/repositories/CollectionRepository' import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' import { SettingMother } from '../../../../settings/domain/models/SettingMother' import { SettingsProvider } from '../../../../../../src/sections/settings/SettingsProvider' +import { DataverseInfoMockEmptyRepository } from '@/stories/shared-mock-repositories/info/DataverseInfoMockEmptyRepository' +import { DataverseInfoRepository } from '@/info/domain/repositories/DataverseInfoRepository' const collectionRepository = {} as CollectionRepository const datasetRepository = {} as DatasetRepository -const dataverseInfoRepository = {} as DataverseInfoRepository +let dataverseInfoRepository: DataverseInfoRepository describe('PublishDatasetMenu', () => { beforeEach(() => { - dataverseInfoRepository.getHasPublicStore = cy.stub().resolves({}) - dataverseInfoRepository.getExternalStatusesAllowed = cy.stub().resolves({}) - dataverseInfoRepository.getMaxEmbargoDurationInMonths = cy.stub().resolves({}) - dataverseInfoRepository.getZipDownloadLimit = cy.stub().resolves({}) + dataverseInfoRepository = new DataverseInfoMockEmptyRepository() }) it('renders the PublishDatasetMenu if is dataset latest version and it is a draft and publishing is allowed', () => { diff --git a/tests/component/sections/dataset/dataset-files/DatasetFiles.spec.tsx b/tests/component/sections/dataset/dataset-files/DatasetFiles.spec.tsx index c14980054..84b514cab 100644 --- a/tests/component/sections/dataset/dataset-files/DatasetFiles.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/DatasetFiles.spec.tsx @@ -21,8 +21,8 @@ import { SettingsProvider } from '../../../../../src/sections/settings/SettingsP import { FilePaginationInfo } from '../../../../../src/files/domain/models/FilePaginationInfo' import { FilePreviewMother } from '../../../files/domain/models/FilePreviewMother' import { FilePreview } from '../../../../../src/files/domain/models/FilePreview' -import { DataverseInfoRepository } from '@/info/domain/repositories/DataverseInfoRepository' import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' +import { DataverseInfoMockEmptyRepository } from '@/stories/shared-mock-repositories/info/DataverseInfoMockEmptyRepository' const testFiles: FilePreview[] = FilePreviewMother.createMany(10) const datasetPersistentId = 'test-dataset-persistent-id' @@ -51,7 +51,7 @@ const testFilesCountInfo = FilesCountInfoMother.create({ ] }) const paginationInfo: FilePaginationInfo = new FilePaginationInfo(1, 10, 200) -const dataverseInfoRepository = {} as DataverseInfoRepository +const dataverseInfoRepository = new DataverseInfoMockEmptyRepository() describe('DatasetFiles', () => { beforeEach(() => { diff --git a/tests/component/sections/dataset/dataset-files/DatasetFilesScrollable.spec.tsx b/tests/component/sections/dataset/dataset-files/DatasetFilesScrollable.spec.tsx index 3bae068ff..2565483c2 100644 --- a/tests/component/sections/dataset/dataset-files/DatasetFilesScrollable.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/DatasetFilesScrollable.spec.tsx @@ -22,8 +22,8 @@ import { FilePreviewMother } from '../../../files/domain/models/FilePreviewMothe import { DatasetFilesScrollable } from '../../../../../src/sections/dataset/dataset-files/DatasetFilesScrollable' import { FilesWithCount } from '../../../../../src/files/domain/models/FilesWithCount' import { getCellStyle } from '../../../../../src/sections/dataset/dataset-files/files-table/FilesTableScrollable' -import { DataverseInfoRepository } from '@/info/domain/repositories/DataverseInfoRepository' import { DatasetMockRepository } from '../../../../../src/stories/dataset/DatasetMockRepository' +import { DataverseInfoMockEmptyRepository } from '@/stories/shared-mock-repositories/info/DataverseInfoMockEmptyRepository' const TOTAL_FILES_COUNT = 200 const ONLY_4_FILES_COUNT = 4 @@ -65,7 +65,7 @@ const testFilesCountInfo = FilesCountInfoMother.create({ { tag: new FileTag('code'), count: 10 } ] }) -const dataverseInfoRepository = {} as DataverseInfoRepository +const dataverseInfoRepository = new DataverseInfoMockEmptyRepository() describe('DatasetFilesScrollable', () => { beforeEach(() => { diff --git a/tests/component/sections/dataset/dataset-files/files-table/FilesTable.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/FilesTable.spec.tsx index 952f50bc6..7aa894063 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/FilesTable.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/FilesTable.spec.tsx @@ -12,8 +12,8 @@ import { FileCriteria } from '../../../../../../src/files/domain/models/FileCrit import { FilePaginationInfo } from '../../../../../../src/files/domain/models/FilePaginationInfo' import { FilePreviewMother } from '../../../../files/domain/models/FilePreviewMother' import { FileRepository } from '@/files/domain/repositories/FileRepository' -import { DataverseInfoRepository } from '@/info/domain/repositories/DataverseInfoRepository' import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' +import { DataverseInfoMockEmptyRepository } from '@/stories/shared-mock-repositories/info/DataverseInfoMockEmptyRepository' const fileRepository: FileRepository = {} as FileRepository const datasetRepository: DatasetRepository = {} as DatasetRepository @@ -199,14 +199,10 @@ describe('FilesTable', () => { }) ] - const dataverseInfoRepository = {} as DataverseInfoRepository - + const dataverseInfoRepository = new DataverseInfoMockEmptyRepository() dataverseInfoRepository.getZipDownloadLimit = cy .stub() .resolves(SettingMother.createZipDownloadLimit(new ZipDownloadLimit(500, FileSizeUnit.BYTES))) - dataverseInfoRepository.getHasPublicStore = cy.stub().resolves({}) - dataverseInfoRepository.getExternalStatusesAllowed = cy.stub().resolves({}) - dataverseInfoRepository.getMaxEmbargoDurationInMonths = cy.stub().resolves({}) cy.customMount( diff --git a/tests/component/sections/dataset/dataset-files/files-table/zip-download-limit-message/ZipDownloadLimitMessage.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/zip-download-limit-message/ZipDownloadLimitMessage.spec.tsx index 2a6f81425..a0d4af7bb 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/zip-download-limit-message/ZipDownloadLimitMessage.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/zip-download-limit-message/ZipDownloadLimitMessage.spec.tsx @@ -5,7 +5,7 @@ import { SettingMother } from '../../../../../settings/domain/models/SettingMoth import { ZipDownloadLimit } from '../../../../../../../src/settings/domain/models/ZipDownloadLimit' import { SettingsProvider } from '@/sections/settings/SettingsProvider' import { FilePreviewMother } from '../../../../../files/domain/models/FilePreviewMother' -import { DataverseInfoRepository } from '@/info/domain/repositories/DataverseInfoRepository' +import { DataverseInfoMockEmptyRepository } from '@/stories/shared-mock-repositories/info/DataverseInfoMockEmptyRepository' const fileSelection = { 0: FilePreviewMother.create({ @@ -18,16 +18,13 @@ const fileSelection = { const zipDownloadLimit = new ZipDownloadLimit(500, FileSizeUnit.BYTES) const filesTotalDownloadSize = 3072 // 3.0 KB -const dataverseInfoRepository = {} as DataverseInfoRepository +const dataverseInfoRepository = new DataverseInfoMockEmptyRepository() describe('ZipDownloadLimitMessage', () => { beforeEach(() => { dataverseInfoRepository.getZipDownloadLimit = cy .stub() .resolves(SettingMother.createZipDownloadLimit(zipDownloadLimit)) - dataverseInfoRepository.getHasPublicStore = cy.stub().resolves({}) - dataverseInfoRepository.getExternalStatusesAllowed = cy.stub().resolves({}) - dataverseInfoRepository.getMaxEmbargoDurationInMonths = cy.stub().resolves({}) }) it('should not render if there is less than 1 file selected', () => { diff --git a/tests/component/sections/dataset/dataset-publish/PublishDatasetModal.spec.tsx b/tests/component/sections/dataset/dataset-publish/PublishDatasetModal.spec.tsx index 6b0a9c59b..da2895324 100644 --- a/tests/component/sections/dataset/dataset-publish/PublishDatasetModal.spec.tsx +++ b/tests/component/sections/dataset/dataset-publish/PublishDatasetModal.spec.tsx @@ -5,27 +5,78 @@ import { CollectionRepository } from '../../../../../src/collection/domain/repos import { UpwardHierarchyNodeMother } from '../../../shared/hierarchy/domain/models/UpwardHierarchyNodeMother' import { CustomTermsMother } from '@tests/component/dataset/domain/models/TermsOfUseMother' import { LicenseMother } from '@tests/component/dataset/domain/models/LicenseMother' +import { SettingsProvider } from '../../../../../src/sections/settings/SettingsProvider' +import { SettingMother } from '@tests/component/settings/domain/models/SettingMother' +import { DataverseInfoMockRepository } from '@/stories/shared-mock-repositories/info/DataverseInfoMockRepository' +import { DataverseInfoRepository } from '@/info/domain/repositories/DataverseInfoRepository' -describe('PublishDatasetModal', () => { - it('display modal for never released dataset', () => { - const handleClose = cy.stub() - const repository = {} as DatasetRepository // Mock the repository as needed - repository.publish = cy.stub().as('repositoryPublish').resolves() - const collectionRepository = {} as CollectionRepository - collectionRepository.publish = cy.stub().as('collectionRepositoryPublish').resolves() - const parentCollection = UpwardHierarchyNodeMother.createCollection() - cy.mountAuthenticated( +const TEST_PERSISTENT_ID = 'testPersistentId' + +type CreateRepositoryOptions = { + publish?: sinon.SinonStub +} + +const createDatasetRepository = (options: CreateRepositoryOptions = {}) => { + const repository = {} as DatasetRepository + repository.publish = options.publish ?? cy.stub().as('repositoryPublish').resolves() + return repository +} + +const createCollectionRepository = (options: CreateRepositoryOptions = {}) => { + const collectionRepository = {} as CollectionRepository + collectionRepository.publish = + options.publish ?? cy.stub().as('collectionRepositoryPublish').resolves() + return collectionRepository +} + +type MountOptions = { + mountAs?: 'authenticated' | 'superuser' + repository?: DatasetRepository + collectionRepository?: CollectionRepository + parentCollection?: ReturnType + handleClose?: sinon.SinonStub + dataverseInfoRepository?: DataverseInfoRepository + props?: Partial> +} + +const mountPublishDatasetModal = ({ + mountAs = 'authenticated', + repository = createDatasetRepository(), + collectionRepository = createCollectionRepository(), + parentCollection = UpwardHierarchyNodeMother.createCollection(), + dataverseInfoRepository, + handleClose = cy.stub(), + props = {} +}: MountOptions = {}) => { + const mountFn = mountAs === 'superuser' ? cy.mountSuperuser : cy.mountAuthenticated + const dataverseInfoWithoutCustomText = new DataverseInfoMockRepository() + dataverseInfoWithoutCustomText.getDatasetPublishPopupCustomText = cy.stub().resolves('') + dataverseInfoWithoutCustomText.getPublishDatasetDisclaimerText = cy.stub().resolves('') + const resolvedDataverseInfoRepository = dataverseInfoRepository ?? dataverseInfoWithoutCustomText + + mountFn( + - ) + + ) + + return { repository, collectionRepository, parentCollection, handleClose } +} + +describe('PublishDatasetModal', () => { + it('display modal for never released dataset', () => { + mountPublishDatasetModal() + cy.findByText('Publish Dataset').should('exist') cy.findByText( 'Are you sure you want to publish this dataset? Once you do so, it must remain published.' @@ -37,31 +88,18 @@ describe('PublishDatasetModal', () => { cy.findByText('Continue').click() cy.get('@repositoryPublish').should( 'have.been.calledWith', - 'testPersistentId', + TEST_PERSISTENT_ID, VersionUpdateType.MAJOR ) }) it('displays an error message when publishDataset fails', () => { - const handleClose = cy.stub() - const repository = {} as DatasetRepository // Mock the repository as needed const errorMessage = 'Publishing failed' - repository.publish = cy.stub().as('repositoryPublish').rejects(new Error(errorMessage)) - const collectionRepository = {} as CollectionRepository - collectionRepository.publish = cy.stub().as('collectionRepositoryPublish').resolves() - const parentCollection = UpwardHierarchyNodeMother.createCollection() - cy.mountAuthenticated( - - ) + const repository = createDatasetRepository({ + publish: cy.stub().as('repositoryPublish').rejects(new Error(errorMessage)) + }) + + mountPublishDatasetModal({ repository }) // Trigger the Publish action cy.findByText('Continue').click() @@ -69,27 +107,14 @@ describe('PublishDatasetModal', () => { // Check if the error message is displayed cy.contains(errorMessage).should('exist') }) + it('displays an error message when publishCollection fails', () => { - const handleClose = cy.stub() - const repository = {} as DatasetRepository // Mock the repository as needed - const collectionRepository = {} as CollectionRepository - collectionRepository.publish = cy - .stub() - .as('collectionRepositoryPublish') - .rejects(new Error('collection error')) + const collectionRepository = createCollectionRepository({ + publish: cy.stub().as('collectionRepositoryPublish').rejects(new Error('collection error')) + }) const parentCollection = UpwardHierarchyNodeMother.createCollection({ isReleased: false }) - cy.mountAuthenticated( - - ) + + mountPublishDatasetModal({ collectionRepository, parentCollection }) // Trigger the Publish action cy.findByText('Continue').click() @@ -97,27 +122,15 @@ describe('PublishDatasetModal', () => { // Check if the error message is displayed cy.contains('collection error').should('exist') }) + it('renders the PublishDatasetModal for previously released dataset and triggers submitPublish on button click', () => { - const handleClose = cy.stub() - const repository = {} as DatasetRepository // Mock the repository as needed - repository.publish = cy.stub().as('repositoryPublish').resolves() - const collectionRepository = {} as CollectionRepository - collectionRepository.publish = cy.stub().as('collectionRepositoryPublish').resolves() - const parentCollection = UpwardHierarchyNodeMother.createCollection() - cy.mountAuthenticated( - - ) + mountPublishDatasetModal({ + props: { + releasedVersionExists: true, + nextMajorVersion: '2.0', + nextMinorVersion: '1.1' + } + }) // Check if the modal is rendered cy.findByText('Publish Dataset').should('exist') @@ -126,80 +139,45 @@ describe('PublishDatasetModal', () => { cy.findByText('Continue').click() cy.get('@repositoryPublish').should( 'have.been.calledWith', - 'testPersistentId', + TEST_PERSISTENT_ID, VersionUpdateType.MAJOR ) }) it('renders the third radio button when user.superuser is true', () => { - const handleClose = cy.stub() - const repository = {} as DatasetRepository // Mock the repository as needed - repository.publish = cy.stub().as('repositoryPublish').resolves() - const collectionRepository = {} as CollectionRepository - collectionRepository.publish = cy.stub().as('collectionRepositoryPublish').resolves() - const parentCollection = UpwardHierarchyNodeMother.createCollection() - cy.mountSuperuser( - - ) + mountPublishDatasetModal({ + mountAs: 'superuser', + props: { + releasedVersionExists: true, + nextMajorVersion: '2.0', + nextMinorVersion: '1.1' + } + }) + cy.findByText(/Update Current Version/).should('exist') }) it('does not display the third radio button when user.superuser is false', () => { - const handleClose = cy.stub() - const repository = {} as DatasetRepository // Mock the repository as needed - repository.publish = cy.stub().as('repositoryPublish').resolves() - const collectionRepository = {} as CollectionRepository - collectionRepository.publish = cy.stub().as('collectionRepositoryPublish').resolves() - const parentCollection = UpwardHierarchyNodeMother.createCollection() - cy.mountAuthenticated( - - ) + mountPublishDatasetModal({ + props: { + releasedVersionExists: true, + nextMajorVersion: '2.0', + nextMinorVersion: '1.1' + } + }) + cy.findByText(/Update Current Version/).should('not.exist') }) + it('renders the PublishDatasetModal for previously released dataset that requires major version update', () => { - const handleClose = cy.stub() - const repository = {} as DatasetRepository // Mock the repository as needed - repository.publish = cy.stub().as('repositoryPublish').resolves() - const collectionRepository = {} as CollectionRepository - collectionRepository.publish = cy.stub().as('collectionRepositoryPublish').resolves() - const parentCollection = UpwardHierarchyNodeMother.createCollection() - cy.mountAuthenticated( - - ) + mountPublishDatasetModal({ + props: { + releasedVersionExists: true, + nextMajorVersion: '2.0', + requiresMajorVersionUpdate: true, + nextMinorVersion: '1.1' + } + }) // Check if the modal is rendered cy.findByText('Publish Dataset').should('exist') @@ -211,30 +189,21 @@ describe('PublishDatasetModal', () => { cy.findByText('Continue').click() cy.get('@repositoryPublish').should( 'have.been.calledWith', - 'testPersistentId', + TEST_PERSISTENT_ID, VersionUpdateType.MAJOR ) }) it('Displays warning text for unreleased Collection', () => { - const handleClose = cy.stub() - const repository = {} as DatasetRepository // Mock the repository as needed - repository.publish = cy.stub().as('repositoryPublish').resolves() - const collectionRepository = {} as CollectionRepository - collectionRepository.publish = cy.stub().as('collectionRepositoryPublish').resolves() const parentCollection = UpwardHierarchyNodeMother.createCollection({ isReleased: false }) - cy.mountAuthenticated( - - ) + + mountPublishDatasetModal({ + parentCollection, + props: { + releasedVersionExists: false + } + }) + cy.findByText(/This dataset cannot be published until/).should('exist') cy.findByRole('link', { name: parentCollection.name }).should('exist') cy.findByRole('link', { name: parentCollection.name }) @@ -243,25 +212,59 @@ describe('PublishDatasetModal', () => { }) it('Displays custom terms when license is undefined', () => { - const handleClose = cy.stub() - const repository = {} as DatasetRepository // Mock the repository as needed - repository.publish = cy.stub().as('repositoryPublish').resolves() - const collectionRepository = {} as CollectionRepository - collectionRepository.publish = cy.stub().as('collectionRepositoryPublish').resolves() const parentCollection = UpwardHierarchyNodeMother.createCollection({ isReleased: false }) - cy.mountAuthenticated( - - ) + + mountPublishDatasetModal({ + parentCollection, + props: { + license: undefined, + customTerms: CustomTermsMother.create() + } + }) + cy.findByText(/Custom Dataset Terms/).should('exist') }) + + it('Displays disclaimer text from settings', () => { + const dataverseInfoRepository = new DataverseInfoMockRepository() + const disclaimerText = 'This is custom text for the dataset publish popup.' + + dataverseInfoRepository.getPublishDatasetDisclaimerText = cy + .stub() + .resolves(SettingMother.createPublishDatasetDisclaimerText(disclaimerText)) + + mountPublishDatasetModal({ dataverseInfoRepository }) + + cy.findByText(disclaimerText).should('exist') + }) + + it('Disables the continue button until the user checks the disclaimer text', () => { + const dataverseInfoRepository = new DataverseInfoMockRepository() + const disclaimerText = 'This is disclaimer text for the dataset publish popup.' + + dataverseInfoRepository.getPublishDatasetDisclaimerText = cy + .stub() + .resolves(SettingMother.createPublishDatasetDisclaimerText(disclaimerText)) + mountPublishDatasetModal({ dataverseInfoRepository }) + + cy.findByText(disclaimerText).should('exist') + cy.findByRole('button', { name: 'Continue' }).should('be.disabled') + cy.findByRole('checkbox', { name: disclaimerText }).click() + cy.findByRole('button', { name: 'Continue' }).should('not.be.disabled') + }) + + it('Displays the custom popup text if it is available', () => { + const dataverseInfoRepository = new DataverseInfoMockRepository() + const popupText = 'This is custom text for the popup.' + + dataverseInfoRepository.getDatasetPublishPopupCustomText = cy + .stub() + .resolves(SettingMother.createDatasetPublishPopupCustomText(popupText)) + dataverseInfoRepository.getPublishDatasetDisclaimerText = cy.stub().resolves('') + + mountPublishDatasetModal({ dataverseInfoRepository }) + + cy.findByText(popupText).should('exist') + cy.findByRole('button', { name: 'Continue' }).should('not.be.disabled') + }) }) diff --git a/tests/component/sections/layout/footer/Footer.spec.tsx b/tests/component/sections/layout/footer/Footer.spec.tsx index f43d5a080..6c0090f5d 100644 --- a/tests/component/sections/layout/footer/Footer.spec.tsx +++ b/tests/component/sections/layout/footer/Footer.spec.tsx @@ -1,8 +1,8 @@ import { createSandbox, SinonSandbox } from 'sinon' import { DataverseVersionMother } from '../../../info/domain/models/DataverseVersionMother' -import { DataverseInfoRepository } from '../../../../../src/info/domain/repositories/DataverseInfoRepository' import { FooterMother } from './FooterMother' import { Footer } from '../../../../../src/sections/layout/footer/Footer' +import { DataverseInfoMockEmptyRepository } from '@/stories/shared-mock-repositories/info/DataverseInfoMockEmptyRepository' describe('Footer component', () => { const sandbox: SinonSandbox = createSandbox() @@ -19,9 +19,8 @@ describe('Footer component', () => { }) it('should call dataverseInfoRepository.getVersion on mount', () => { - const dataverseInfoRepository: DataverseInfoRepository = { - getVersion: cy.stub().resolves(testVersion) - } + const dataverseInfoRepository = new DataverseInfoMockEmptyRepository() + dataverseInfoRepository.getVersion = cy.stub().resolves(testVersion) cy.customMount(