From 191c8ec100ee36c8ec2375da4fe6285d41b0d85c Mon Sep 17 00:00:00 2001 From: Cheng Shi Date: Thu, 23 Apr 2026 16:27:25 -0400 Subject: [PATCH 1/5] avoid datasetRepo props drilling --- CHANGELOG.md | 1 + src/sections/account/AccountFactory.tsx | 6 +- .../advanced-search/AdvancedSearchFactory.tsx | 6 +- src/sections/collection/CollectionFactory.tsx | 6 +- .../CreateCollectionFactory.tsx | 6 +- src/sections/create-dataset/CreateDataset.tsx | 4 - .../create-dataset/CreateDatasetFactory.tsx | 5 +- src/sections/dataset/Dataset.tsx | 22 +- src/sections/dataset/DatasetFactory.tsx | 10 +- .../DatasetActionButtons.tsx | 14 +- .../DeaccessionDatasetButton.tsx | 8 +- .../edit-dataset-menu/EditDatasetMenu.tsx | 10 +- .../DeleteDraftDatasetButton.tsx | 9 +- .../LinkAndUnlinkActions.tsx | 6 +- .../link-dataset-button/LinkDatasetButton.tsx | 10 +- .../UnlinkDatasetButton.tsx | 10 +- .../PublishDatasetMenu.tsx | 6 +- .../dataset-citation/DatasetCitation.tsx | 9 +- .../dataset/dataset-files/DatasetFiles.tsx | 6 +- .../dataset-files/DatasetFilesScrollable.tsx | 6 +- .../dataset-files/files-table/FilesTable.tsx | 7 +- .../FilesTableColumnsDefinition.tsx | 9 +- .../files-table/FilesTableScrollable.tsx | 7 +- .../file-actions/FileActionsHeader.tsx | 12 +- .../DatasetEditFileTagsButton.tsx | 6 +- .../edit-files-menu/EditFilesMenu.tsx | 10 +- .../edit-files-menu/EditFilesOptions.tsx | 7 +- .../file-actions-cell/FileActionsCell.tsx | 10 +- .../file-action-buttons/FileActionButtons.tsx | 14 +- .../file-options-menu/FileOptionsMenu.tsx | 5 +- .../dataset-metrics/DatasetMetrics.tsx | 6 +- .../dataset-versions/DatasetVersions.tsx | 7 +- .../DatasetViewDetailButton.tsx | 5 +- .../DatasetVersionViewDifferenceButton.tsx | 5 +- .../DeaccessionDatasetModal.tsx | 5 +- .../EditFeaturedItemsFactory.tsx | 6 +- .../edit-collection/EditCollectionFactory.tsx | 6 +- .../EditDatasetMetadata.tsx | 8 +- .../EditDatasetMetadataFactory.tsx | 20 +- .../edit-dataset-terms/EditDatasetTerms.tsx | 15 +- .../EditDatasetTermsFactory.tsx | 26 +- .../EditLicenseAndTerms.tsx | 5 +- .../EditTermsOfAccess.tsx | 9 +- .../featured-item/FeaturedItemFactory.tsx | 6 +- src/sections/file/File.tsx | 5 - src/sections/file/FileFactory.tsx | 24 +- .../edit-file-menu/EditFileMenu.tsx | 4 - .../edit-file-tags/EditFileTagsButton.tsx | 6 +- .../EditFileTagsModal.tsx | 5 +- src/sections/homepage/HomepageFactory.tsx | 6 +- src/sections/layout/header/HeaderFactory.tsx | 6 +- src/sections/replace-file/ReplaceFile.tsx | 4 - .../replace-file/ReplaceFileFactory.tsx | 22 +- .../CitationDownloadButton.tsx | 10 +- .../shared/file-uploader/FileUploader.tsx | 4 - .../file-uploader/FileUploaderPanel.tsx | 3 - .../file-upload-input/FileUploadInput.tsx | 4 +- .../MetadataForm/index.tsx | 5 +- .../shared/form/DatasetMetadataForm/index.tsx | 5 - .../UploadDatasetFiles.tsx | 8 +- .../UploadDatasetFilesFactory.tsx | 17 +- .../repositories/RepositoriesProvider.tsx | 16 +- src/stories/WithRepositories.tsx | 20 +- .../create-dataset/CreateDataset.stories.tsx | 14 +- src/stories/dataset/Dataset.stories.tsx | 64 +- .../DatasetActionButtons.stories.tsx | 15 +- .../EditDatasetMenu.stories.tsx | 12 +- .../LinkDatasetButton.stories.tsx | 15 +- .../PublishDatasetMenu.stories.tsx | 15 +- .../UnlinkDatasetButton.stories.tsx | 10 +- .../DatasetCitation.stories.tsx | 43 +- .../dataset-files/DatasetFiles.stories.tsx | 11 +- .../DatasetFilesScrollable.stories.tsx | 11 +- .../edit-files-menu/EditFilesMenu.stories.tsx | 10 +- .../FileOptionsMenu.stories.tsx | 13 +- .../DatasetMetrics.stories.tsx | 17 +- .../DatasetVersions.stories.tsx | 4 +- .../DeaccessionDatasetModal.stories.tsx | 40 +- .../EditDatasetMetadata.stories.tsx | 15 +- .../EditDatasetTerms.stories.tsx | 16 +- src/stories/file/File.stories.tsx | 15 +- .../EditFileDropdown.stories.tsx | 9 +- .../EditFileTagsModal.stories.tsx | 11 +- .../replace-file/ReplaceFile.stories.tsx | 16 +- .../DatasetMetadataForm.stories.tsx | 9 +- .../file-uploader/FileUploadInput.stories.tsx | 8 +- .../file-uploader/FileUploader.stories.tsx | 5 +- .../UploadDatasetFiles.stories.tsx | 10 +- tests/component/WithRepositories.tsx | 14 +- .../create-dataset/CreateDataset.spec.tsx | 16 +- .../sections/dataset/Dataset.spec.tsx | 22 +- .../DatasetActionButtons.spec.tsx | 30 +- .../DeaccessionDatasetButton.spec.tsx | 99 ++- .../DeleteDraftDatasetButton.spec.tsx | 128 ++-- .../EditDatasetMenu.spec.tsx | 61 +- .../LinkDatasetButton.spec.tsx | 82 +-- .../PublishDatasetMenu.spec.tsx | 60 +- .../UnlinkDatasetButton.spec.tsx | 82 +-- .../dataset-citation/DatasetCitation.spec.tsx | 30 +- .../dataset-files/DatasetFiles.spec.tsx | 303 ++++---- .../DatasetFilesScrollable.spec.tsx | 538 ++++++++------- .../files-table/FilesTable.spec.tsx | 195 +++--- .../file-actions/FileActionsHeader.spec.tsx | 18 +- .../edit-files-menu/EditFilesMenu.spec.tsx | 62 +- .../edit-files-menu/EditFilesOptions.spec.tsx | 361 +++++----- .../FileActionButtons.spec.tsx | 25 +- .../FileOptionsMenu.spec.tsx | 67 +- .../dataset-metrics/DatasetMetrics.spec.tsx | 29 +- .../dataset-versions/DatasetVersions.spec.tsx | 166 ++--- .../EditDatasetMetadata.spec.tsx | 29 +- .../EditDatasetTerms.spec.tsx | 46 +- .../EditLicenseAndTerms.spec.tsx | 132 +--- .../EditTermsOfAccess.spec.tsx | 86 +-- tests/component/sections/file/File.spec.tsx | 190 +++--- .../edit-file-tags/EditFileTagsModal.spec.tsx | 355 +++++----- .../edit-file-menu/EditFileMenu.spec.tsx | 646 +++++++++--------- .../citation/CitationDownloadButton.spec.tsx | 69 +- .../DatasetMetadataForm.spec.tsx | 500 +++++++------- .../file-uploader/FileUploader.spec.tsx | 9 +- .../UploadDatasetFiles.spec.tsx | 13 +- 120 files changed, 2690 insertions(+), 2731 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea30b500d..076a8d49b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ This changelog follows the principles of [Keep a Changelog](https://keepachangel - 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. - Dataset page Terms tab title now depends on permissions: users with dataset update permission see `Terms and Guestbook`, and read-only users see `Terms`. - Avoided prop-drilling for collection repository, so used context to share epository instances. +- Avoided prop-drilling for dataset repository, so used context to share repository instances. (#963) ### Fixed diff --git a/src/sections/account/AccountFactory.tsx b/src/sections/account/AccountFactory.tsx index 13315fe74..97f4ca544 100644 --- a/src/sections/account/AccountFactory.tsx +++ b/src/sections/account/AccountFactory.tsx @@ -4,12 +4,14 @@ import { AccountHelper } from './AccountHelper' import { Account } from './Account' import { UserJSDataverseRepository } from '@/users/infrastructure/repositories/UserJSDataverseRepository' import { CollectionJSDataverseRepository } from '@/collection/infrastructure/repositories/CollectionJSDataverseRepository' +import { DatasetJSDataverseRepository } from '@/dataset/infrastructure/repositories/DatasetJSDataverseRepository' import { RoleJSDataverseRepository } from '@/roles/infrastructure/repositories/RoleJSDataverseRepository' import { NotificationJSDataverseRepository } from '@/notifications/infrastructure/repositories/NotificationJSDataverseRepository' import { RepositoriesProvider } from '@/shared/contexts/repositories/RepositoriesProvider' const userRepository = new UserJSDataverseRepository() const collectionRepository = new CollectionJSDataverseRepository() +const datasetRepository = new DatasetJSDataverseRepository() const roleRepository = new RoleJSDataverseRepository() const notificationRepository = new NotificationJSDataverseRepository() @@ -24,7 +26,9 @@ function AccountWithSearchParams() { const defaultActiveTabKey = AccountHelper.defineSelectedTabKey(searchParams) return ( - + + + + () as { collectionId: string } return ( - + - + {(!isCurrentVersionDeaccessioned || canUpdateDataset) && ( - + )} @@ -168,7 +158,6 @@ export function Dataset({
) : ( )}
@@ -230,7 +217,6 @@ export function Dataset({
+ + - + - - + + - - {!isDeaccessioned && ( - - )} + + {!isDeaccessioned && } ) } diff --git a/src/sections/dataset/dataset-action-buttons/edit-dataset-menu/delete-draft-dataset/DeleteDraftDatasetButton.tsx b/src/sections/dataset/dataset-action-buttons/edit-dataset-menu/delete-draft-dataset/DeleteDraftDatasetButton.tsx index 22b1d873e..55fc3d342 100644 --- a/src/sections/dataset/dataset-action-buttons/edit-dataset-menu/delete-draft-dataset/DeleteDraftDatasetButton.tsx +++ b/src/sections/dataset/dataset-action-buttons/edit-dataset-menu/delete-draft-dataset/DeleteDraftDatasetButton.tsx @@ -6,19 +6,16 @@ import { RouteWithParams } from '@/sections/Route.enum' import { Dataset, DatasetPublishingStatus } from '../../../../../dataset/domain/models/Dataset' import { useDeleteDraftDataset } from './useDeleteDraftDataset' import { DropdownButtonItem, DropdownSeparator } from '@iqss/dataverse-design-system' -import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' import { QueryParamKey, Route } from '@/sections/Route.enum' import { DatasetNonNumericVersion } from '@/dataset/domain/models/Dataset' import { ConfirmDeleteDraftDatasetModal } from './ConfirmDeleteDraftDatasetModal' +import { useDatasetRepositories } from '@/shared/contexts/repositories/RepositoriesProvider' interface DeleteDraftDatasetButtonProps { dataset: Dataset - datasetRepository: DatasetRepository } -export function DeleteDraftDatasetButton({ - dataset, - datasetRepository -}: DeleteDraftDatasetButtonProps) { +export function DeleteDraftDatasetButton({ dataset }: DeleteDraftDatasetButtonProps) { + const { datasetRepository } = useDatasetRepositories() const [showConfirmationModal, setShowConfirmationModal] = useState(false) const navigate = useNavigate() const { t } = useTranslation('dataset') diff --git a/src/sections/dataset/dataset-action-buttons/link-and-unlink-actions/LinkAndUnlinkActions.tsx b/src/sections/dataset/dataset-action-buttons/link-and-unlink-actions/LinkAndUnlinkActions.tsx index dfa7de8cb..4e204a8a5 100644 --- a/src/sections/dataset/dataset-action-buttons/link-and-unlink-actions/LinkAndUnlinkActions.tsx +++ b/src/sections/dataset/dataset-action-buttons/link-and-unlink-actions/LinkAndUnlinkActions.tsx @@ -2,14 +2,12 @@ import { useState } from 'react' import { LinkDatasetButton } from './link-dataset-button/LinkDatasetButton' import { UnlinkDatasetButton } from './unlink-dataset-button/UnlinkDatasetButton' import { Dataset } from '@/dataset/domain/models/Dataset' -import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' interface LinkAndUnlinkActionsProps { dataset: Dataset - datasetRepository: DatasetRepository } -export const LinkAndUnlinkActions = ({ dataset, datasetRepository }: LinkAndUnlinkActionsProps) => { +export const LinkAndUnlinkActions = ({ dataset }: LinkAndUnlinkActionsProps) => { const [key, setKey] = useState(0) // This is a way to force remounting both components when either one of them successfully links or unlinks a dataset. @@ -20,13 +18,11 @@ export const LinkAndUnlinkActions = ({ dataset, datasetRepository }: LinkAndUnli <> diff --git a/src/sections/dataset/dataset-action-buttons/link-and-unlink-actions/link-dataset-button/LinkDatasetButton.tsx b/src/sections/dataset/dataset-action-buttons/link-and-unlink-actions/link-dataset-button/LinkDatasetButton.tsx index a272cfa3f..04fcaa21d 100644 --- a/src/sections/dataset/dataset-action-buttons/link-and-unlink-actions/link-dataset-button/LinkDatasetButton.tsx +++ b/src/sections/dataset/dataset-action-buttons/link-and-unlink-actions/link-dataset-button/LinkDatasetButton.tsx @@ -5,27 +5,23 @@ import { Button, Modal, Spinner, Stack } from '@iqss/dataverse-design-system' import { WriteError } from '@iqss/dataverse-client-javascript' import { Dataset, DatasetPublishingStatus } from '@/dataset/domain/models/Dataset' import { useSession } from '@/sections/session/SessionContext' -import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' import { CollectionLinkSelect } from '@/sections/collection/link-collection-dropdown/collection-link-select/CollectionLinkSelect' import { CollectionSummary } from '@/collection/domain/models/CollectionSummary' import { JSDataverseWriteErrorHandler } from '@/shared/helpers/JSDataverseWriteErrorHandler' import { linkDataset } from '@/dataset/domain/useCases/linkDataset' import { RouteWithParams } from '@/sections/Route.enum' import { useGetDatasetLinkedCollections } from '@/dataset/domain/hooks/useGetDatasetLinkedCollections' +import { useDatasetRepositories } from '@/shared/contexts/repositories/RepositoriesProvider' const BASENAME_URL = import.meta.env.BASE_URL ?? '' interface LinkDatasetButtonProps { dataset: Dataset - datasetRepository: DatasetRepository updateParent: () => void } -export function LinkDatasetButton({ - dataset, - datasetRepository, - updateParent -}: LinkDatasetButtonProps) { +export function LinkDatasetButton({ dataset, updateParent }: LinkDatasetButtonProps) { + const { datasetRepository } = useDatasetRepositories() const { t } = useTranslation('dataset') const { t: tShared } = useTranslation('shared') const { user } = useSession() diff --git a/src/sections/dataset/dataset-action-buttons/link-and-unlink-actions/unlink-dataset-button/UnlinkDatasetButton.tsx b/src/sections/dataset/dataset-action-buttons/link-and-unlink-actions/unlink-dataset-button/UnlinkDatasetButton.tsx index a2881a5ed..5ee4c6b9c 100644 --- a/src/sections/dataset/dataset-action-buttons/link-and-unlink-actions/unlink-dataset-button/UnlinkDatasetButton.tsx +++ b/src/sections/dataset/dataset-action-buttons/link-and-unlink-actions/unlink-dataset-button/UnlinkDatasetButton.tsx @@ -5,27 +5,23 @@ import { Button, Modal, Spinner, Stack } from '@iqss/dataverse-design-system' import { WriteError } from '@iqss/dataverse-client-javascript' import { Dataset, DatasetPublishingStatus } from '@/dataset/domain/models/Dataset' import { useSession } from '@/sections/session/SessionContext' -import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' import { CollectionLinkSelect } from '@/sections/collection/link-collection-dropdown/collection-link-select/CollectionLinkSelect' import { CollectionSummary } from '@/collection/domain/models/CollectionSummary' import { JSDataverseWriteErrorHandler } from '@/shared/helpers/JSDataverseWriteErrorHandler' import { unlinkDataset } from '@/dataset/domain/useCases/unlinkDataset' import { RouteWithParams } from '@/sections/Route.enum' import { useGetDatasetLinkedCollections } from '@/dataset/domain/hooks/useGetDatasetLinkedCollections' +import { useDatasetRepositories } from '@/shared/contexts/repositories/RepositoriesProvider' const BASENAME_URL = import.meta.env.BASE_URL ?? '' interface UnlinkDatasetButtonProps { dataset: Dataset - datasetRepository: DatasetRepository updateParent: () => void } -export function UnlinkDatasetButton({ - dataset, - datasetRepository, - updateParent -}: UnlinkDatasetButtonProps) { +export function UnlinkDatasetButton({ dataset, updateParent }: UnlinkDatasetButtonProps) { + const { datasetRepository } = useDatasetRepositories() const { t } = useTranslation('dataset') const { t: tShared } = useTranslation('shared') const modalTitle = t('datasetActionButtons.unlinkDataset.title') diff --git a/src/sections/dataset/dataset-action-buttons/publish-dataset-menu/PublishDatasetMenu.tsx b/src/sections/dataset/dataset-action-buttons/publish-dataset-menu/PublishDatasetMenu.tsx index d79768bb1..b424b453f 100644 --- a/src/sections/dataset/dataset-action-buttons/publish-dataset-menu/PublishDatasetMenu.tsx +++ b/src/sections/dataset/dataset-action-buttons/publish-dataset-menu/PublishDatasetMenu.tsx @@ -2,17 +2,17 @@ import { useState } from 'react' import { useTranslation } from 'react-i18next' import { DropdownButton, DropdownButtonItem } from '@iqss/dataverse-design-system' import { useSession } from '../../../session/SessionContext' -import { DatasetRepository } from '../../../../dataset/domain/repositories/DatasetRepository' import { Dataset, DatasetPublishingStatus } from '../../../../dataset/domain/models/Dataset' import { ChangeCurationStatusMenu } from './ChangeCurationStatusMenu' import { PublishDatasetModal } from '../../publish-dataset/PublishDatasetModal' +import { useDatasetRepositories } from '@/shared/contexts/repositories/RepositoriesProvider' interface PublishDatasetMenuProps { dataset: Dataset - datasetRepository: DatasetRepository } -export function PublishDatasetMenu({ dataset, datasetRepository }: PublishDatasetMenuProps) { +export function PublishDatasetMenu({ dataset }: PublishDatasetMenuProps) { + const { datasetRepository } = useDatasetRepositories() const { user } = useSession() const { t } = useTranslation('dataset') const [showModal, setShowModal] = useState(false) diff --git a/src/sections/dataset/dataset-citation/DatasetCitation.tsx b/src/sections/dataset/dataset-citation/DatasetCitation.tsx index 234886c1e..dcebb40fe 100644 --- a/src/sections/dataset/dataset-citation/DatasetCitation.tsx +++ b/src/sections/dataset/dataset-citation/DatasetCitation.tsx @@ -6,11 +6,9 @@ import { CitationDescription } from '../../shared/citation/CitationDescription' import { DatasetCitationTooltip } from './DatasetCitationTooltip' import { CitationLearnAbout } from '../../shared/citation/CitationLearnAbout' import { CitationDownloadButton } from '@/sections/shared/citation/citation-download/CitationDownloadButton' -import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' import styles from './DatasetCitation.module.scss' interface DatasetCitationProps { - datasetRepository: DatasetRepository datasetId: string thumbnail?: string version: DatasetVersion @@ -18,7 +16,6 @@ interface DatasetCitationProps { } export function DatasetCitation({ - datasetRepository, datasetId, thumbnail, version, @@ -49,11 +46,7 @@ export function DatasetCitation({ tooltip={} /> - + diff --git a/src/sections/dataset/dataset-files/DatasetFiles.tsx b/src/sections/dataset/dataset-files/DatasetFiles.tsx index 4a63331b0..df6a4820f 100644 --- a/src/sections/dataset/dataset-files/DatasetFiles.tsx +++ b/src/sections/dataset/dataset-files/DatasetFiles.tsx @@ -7,20 +7,17 @@ import { useFiles } from './useFiles' import { PaginationControls } from '../../shared/pagination/PaginationControls' import { DatasetVersion } from '../../../dataset/domain/models/Dataset' import { FilePaginationInfo } from '../../../files/domain/models/FilePaginationInfo' -import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' interface DatasetFilesProps { filesRepository: FileRepository datasetPersistentId: string datasetVersion: DatasetVersion - datasetRepository: DatasetRepository } export function DatasetFiles({ filesRepository, datasetPersistentId, - datasetVersion, - datasetRepository + datasetVersion }: DatasetFilesProps) { const [paginationInfo, setPaginationInfo] = useState(new FilePaginationInfo()) const [criteria, setCriteria] = useState(new FileCriteria()) @@ -47,7 +44,6 @@ export function DatasetFiles({ paginationInfo={paginationInfo} filesTotalDownloadSize={filesTotalDownloadSize} criteria={criteria} - datasetRepository={datasetRepository} /> (null) const criteriaContainerRef = useRef(null) @@ -187,7 +184,6 @@ export function DatasetFilesScrollable({ isEmptyFiles={isEmptyFiles} accumulatedCount={accumulatedCount} fileRepository={filesRepository} - datasetRepository={datasetRepository} />
diff --git a/src/sections/dataset/dataset-files/files-table/FilesTable.tsx b/src/sections/dataset/dataset-files/files-table/FilesTable.tsx index b87252693..319bd4ada 100644 --- a/src/sections/dataset/dataset-files/files-table/FilesTable.tsx +++ b/src/sections/dataset/dataset-files/files-table/FilesTable.tsx @@ -11,7 +11,7 @@ import { FileSelection } from './row-selection/useFileSelection' import { FileCriteria } from '../../../../files/domain/models/FileCriteria' import { FilePaginationInfo } from '../../../../files/domain/models/FilePaginationInfo' import { FileRepository } from '@/files/domain/repositories/FileRepository' -import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' +import { useDatasetRepositories } from '@/shared/contexts/repositories/RepositoriesProvider' interface FilesTableProps { files: FilePreview[] @@ -20,7 +20,6 @@ interface FilesTableProps { paginationInfo: FilePaginationInfo filesTotalDownloadSize: number criteria: FileCriteria - datasetRepository: DatasetRepository } export function FilesTable({ @@ -29,9 +28,9 @@ export function FilesTable({ paginationInfo, filesTotalDownloadSize, fileRepository, - criteria, - datasetRepository + criteria }: FilesTableProps) { + const { datasetRepository } = useDatasetRepositories() const { table, fileSelection, selectAllFiles, clearFileSelection } = useFilesTable( files, paginationInfo, diff --git a/src/sections/dataset/dataset-files/files-table/FilesTableColumnsDefinition.tsx b/src/sections/dataset/dataset-files/files-table/FilesTableColumnsDefinition.tsx index 373b8b92b..66c8d8083 100644 --- a/src/sections/dataset/dataset-files/files-table/FilesTableColumnsDefinition.tsx +++ b/src/sections/dataset/dataset-files/files-table/FilesTableColumnsDefinition.tsx @@ -57,16 +57,9 @@ export const createColumnsDefinition = ( files={table.getRowModel().rows.map((row) => row.original)} fileSelection={fileSelection} fileRepository={fileRepository} - datasetRepository={datasetRepository} /> ), accessorKey: 'status', - cell: (props) => ( - - ) + cell: (props) => } ] diff --git a/src/sections/dataset/dataset-files/files-table/FilesTableScrollable.tsx b/src/sections/dataset/dataset-files/files-table/FilesTableScrollable.tsx index 816fc6d92..72e9739bf 100644 --- a/src/sections/dataset/dataset-files/files-table/FilesTableScrollable.tsx +++ b/src/sections/dataset/dataset-files/files-table/FilesTableScrollable.tsx @@ -12,7 +12,7 @@ import { FilePaginationInfo } from '../../../../files/domain/models/FilePaginati import { type SentryRef } from '../DatasetFilesScrollable' import styles from './FilesTable.module.scss' import { FileRepository } from '@/files/domain/repositories/FileRepository' -import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' +import { useDatasetRepositories } from '@/shared/contexts/repositories/RepositoriesProvider' interface FilesTableScrollableProps { files: FilePreview[] @@ -25,7 +25,6 @@ interface FilesTableScrollableProps { isEmptyFiles: boolean fileRepository: FileRepository accumulatedCount: number - datasetRepository: DatasetRepository } export const FilesTableScrollable = ({ @@ -38,9 +37,9 @@ export const FilesTableScrollable = ({ showSentryRef, isEmptyFiles, fileRepository, - accumulatedCount, - datasetRepository + accumulatedCount }: FilesTableScrollableProps) => { + const { datasetRepository } = useDatasetRepositories() const { table, fileSelection, selectAllPossibleRows, clearRowsSelection } = useFilesTableScrollable( files, diff --git a/src/sections/dataset/dataset-files/files-table/file-actions/FileActionsHeader.tsx b/src/sections/dataset/dataset-files/files-table/file-actions/FileActionsHeader.tsx index a846cf0f2..e7eac554b 100644 --- a/src/sections/dataset/dataset-files/files-table/file-actions/FileActionsHeader.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-actions/FileActionsHeader.tsx @@ -5,30 +5,22 @@ import { useTranslation } from 'react-i18next' import { DownloadFilesButton } from './download-files/DownloadFilesButton' import { FileSelection } from '../row-selection/useFileSelection' import { FileRepository } from '@/files/domain/repositories/FileRepository' -import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' interface FileActionsHeaderProps { files: FilePreview[] fileSelection: FileSelection fileRepository: FileRepository - datasetRepository: DatasetRepository } export function FileActionsHeader({ files, fileSelection, - fileRepository, - datasetRepository + fileRepository }: FileActionsHeaderProps) { const { t } = useTranslation('files') return (
- +
) diff --git a/src/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/DatasetEditFileTagsButton.tsx b/src/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/DatasetEditFileTagsButton.tsx index f43fbc71c..27a308276 100644 --- a/src/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/DatasetEditFileTagsButton.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/DatasetEditFileTagsButton.tsx @@ -11,7 +11,6 @@ import { useFilesContext } from '@/sections/file/FilesContext' import { QueryParamKey, Route } from '@/sections/Route.enum' import { useNavigate, useSearchParams } from 'react-router-dom' import { DatasetNonNumericVersionSearchParam } from '@/dataset/domain/models/Dataset' -import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' interface EditFileTagsButtonProps { fileId: number @@ -19,7 +18,6 @@ interface EditFileTagsButtonProps { existingLabels?: FileLabel[] datasetPersistentId: string isTabularFile: boolean - datasetRepository: DatasetRepository } export const DatasetEditFileTagsButton = ({ @@ -27,8 +25,7 @@ export const DatasetEditFileTagsButton = ({ fileRepository, existingLabels, datasetPersistentId, - isTabularFile, - datasetRepository + isTabularFile }: EditFileTagsButtonProps) => { const [isModalOpen, setIsModalOpen] = useState(false) const { t } = useTranslation('file') @@ -91,7 +88,6 @@ export const DatasetEditFileTagsButton = ({ isUpdatingTabularTags={isUpdatingTabularTags} errorUpdatingTabularTags={errorUpdatingTabularTags} isTabularFile={isTabularFile} - datasetRepository={datasetRepository} datasetPersistentId={datasetPersistentId} /> diff --git a/src/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesMenu.tsx b/src/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesMenu.tsx index bd9f83472..df49cb577 100644 --- a/src/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesMenu.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesMenu.tsx @@ -9,21 +9,14 @@ import { FileSelection } from '../../row-selection/useFileSelection' import { useMediaQuery } from '../../../../../../shared/hooks/useMediaQuery' import { FileRepository } from '@/files/domain/repositories/FileRepository' import styles from './EditFilesMenu.module.scss' -import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' interface EditFilesMenuProps { files: FilePreview[] fileSelection: FileSelection fileRepository: FileRepository - datasetRepository: DatasetRepository } const MINIMUM_FILES_COUNT_TO_SHOW_EDIT_FILES_BUTTON = 1 -export function EditFilesMenu({ - files, - fileSelection, - fileRepository, - datasetRepository -}: EditFilesMenuProps) { +export function EditFilesMenu({ files, fileSelection, fileRepository }: EditFilesMenuProps) { const { t } = useTranslation('files') const { user } = useSession() const { dataset } = useDataset() @@ -52,7 +45,6 @@ export function EditFilesMenu({ fileSelection={fileSelection} fileRepository={fileRepository} isHeader={true} - datasetRepository={datasetRepository} /> ) diff --git a/src/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesOptions.tsx b/src/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesOptions.tsx index 1008c5c4e..62b46755b 100644 --- a/src/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesOptions.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesOptions.tsx @@ -15,7 +15,6 @@ import { EditFileMetadataReferrer } from '@/sections/edit-file-metadata/EditFile import { useSettings } from '@/sections/settings/SettingsContext' import { SettingName } from '@/settings/domain/models/Setting' import { DatasetEditFileTagsButton } from './DatasetEditFileTagsButton' -import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' type EditFilesOptionsProps = | { @@ -25,7 +24,6 @@ type EditFilesOptionsProps = fileRepository: FileRepository datasetInfo?: never isHeader: true - datasetRepository: DatasetRepository } | { files?: never @@ -34,7 +32,6 @@ type EditFilesOptionsProps = fileRepository: FileRepository datasetInfo: EditFilesMenuDatasetInfo isHeader: false - datasetRepository: DatasetRepository } export interface EditFilesMenuDatasetInfo { @@ -52,8 +49,7 @@ export function EditFilesOptions({ fileSelection, fileRepository, datasetInfo, - isHeader, - datasetRepository + isHeader }: EditFilesOptionsProps) { const { t } = useTranslation('files') const { t: tFile } = useTranslation('file') @@ -105,7 +101,6 @@ export function EditFilesOptions({ datasetPersistentId={datasetInfo.persistentId} existingLabels={file.metadata.labels} isTabularFile={file.metadata.isTabular} - datasetRepository={datasetRepository} /> - + ) } diff --git a/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/FileActionButtons.tsx b/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/FileActionButtons.tsx index 26d94cb57..8f1c891f6 100644 --- a/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/FileActionButtons.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/FileActionButtons.tsx @@ -1,7 +1,6 @@ import { useTranslation } from 'react-i18next' import { ButtonGroup } from '@iqss/dataverse-design-system' import { FileRepository } from '@/files/domain/repositories/FileRepository' -import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' import { FilePreview } from '@/files/domain/models/FilePreview' import { DatasetPublishingStatus } from '@/dataset/domain/models/Dataset' import { AccessFileMenu } from '@/sections/file/file-action-buttons/access-file-menu/AccessFileMenu' @@ -12,13 +11,8 @@ import { FileTools } from './FileTools' interface FileActionButtonsProps { file: FilePreview fileRepository: FileRepository - datasetRepository: DatasetRepository } -export function FileActionButtons({ - file, - fileRepository, - datasetRepository -}: FileActionButtonsProps) { +export function FileActionButtons({ file, fileRepository }: FileActionButtonsProps) { const { t } = useTranslation('files') const isBelow768px = useMediaQuery('(max-width: 768px)') @@ -36,11 +30,7 @@ export function FileActionButtons({ ingestInProgress={file.ingest.isInProgress} asIcon /> - + ) } diff --git a/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/file-options-menu/FileOptionsMenu.tsx b/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/file-options-menu/FileOptionsMenu.tsx index ae9d5182b..325e3adaa 100644 --- a/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/file-options-menu/FileOptionsMenu.tsx +++ b/src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/file-options-menu/FileOptionsMenu.tsx @@ -9,16 +9,14 @@ import { FileAlreadyDeletedModal } from './FileAlreadyDeletedModal' import { useDataset } from '../../../../../../DatasetContext' import { FileRepository } from '@/files/domain/repositories/FileRepository' import { EditFilesMenuDatasetInfo } from '../../../edit-files-menu/EditFilesOptions' -import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' import { FileConfigureToolsOptions } from '@/sections/file/file-action-buttons/access-file-menu/FileToolOptions' interface FileOptionsMenuProps { file: FilePreview fileRepository: FileRepository - datasetRepository: DatasetRepository } -export function FileOptionsMenu({ file, fileRepository, datasetRepository }: FileOptionsMenuProps) { +export function FileOptionsMenu({ file, fileRepository }: FileOptionsMenuProps) { const { t } = useTranslation('files') const { user } = useSession() const { dataset } = useDataset() @@ -78,7 +76,6 @@ export function FileOptionsMenu({ file, fileRepository, datasetRepository }: Fil fileRepository={fileRepository} datasetInfo={datasetInfo} isHeader={false} - datasetRepository={datasetRepository} /> diff --git a/src/sections/dataset/dataset-metrics/DatasetMetrics.tsx b/src/sections/dataset/dataset-metrics/DatasetMetrics.tsx index f3faf74f7..e8fe8985e 100644 --- a/src/sections/dataset/dataset-metrics/DatasetMetrics.tsx +++ b/src/sections/dataset/dataset-metrics/DatasetMetrics.tsx @@ -1,16 +1,16 @@ import { useTranslation } from 'react-i18next' import Skeleton, { SkeletonTheme } from 'react-loading-skeleton' import { QuestionMarkTooltip } from '@iqss/dataverse-design-system' -import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' import { useGetDatasetDownloadCount } from './useGetDatasetDownloadCount' +import { useDatasetRepositories } from '@/shared/contexts/repositories/RepositoriesProvider' import styles from './DatasetMetrics.module.scss' interface DatasetMetricsProps { - datasetRepository: DatasetRepository datasetId: number | string } -export const DatasetMetrics = ({ datasetRepository, datasetId }: DatasetMetricsProps) => { +export const DatasetMetrics = ({ datasetId }: DatasetMetricsProps) => { + const { datasetRepository } = useDatasetRepositories() const { t, i18n } = useTranslation('dataset') const { downloadCount: downloadCountIncludingMDC, diff --git a/src/sections/dataset/dataset-versions/DatasetVersions.tsx b/src/sections/dataset/dataset-versions/DatasetVersions.tsx index 271144053..e1baede7b 100644 --- a/src/sections/dataset/dataset-versions/DatasetVersions.tsx +++ b/src/sections/dataset/dataset-versions/DatasetVersions.tsx @@ -8,17 +8,16 @@ import { DatasetVersionSummaryInfo, DatasetVersionSummaryStringValues } from '@/dataset/domain/models/DatasetVersionSummaryInfo' -import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' import { QueryParamKey, Route } from '@/sections/Route.enum' import { useGetDatasetVersionsSummaries } from './useGetDatasetVersionsSummaries' import { DatasetVersionViewDifferenceButton } from './view-difference/DatasetVersionViewDifferenceButton' import { useDatasetVersionSummaryDescription } from './useDatasetVersionSummaryDescription' import { DatasetViewDetailButton } from './DatasetViewDetailButton' import { DatasetVersionState } from '@/dataset/domain/models/Dataset' +import { useDatasetRepositories } from '@/shared/contexts/repositories/RepositoriesProvider' import styles from './DatasetVersions.module.scss' interface DatasetVersionsProps { - datasetRepository: DatasetRepository datasetId: string currentVersionNumber: string canUpdateDataset: boolean @@ -32,13 +31,13 @@ const isVersionDeaccessioned = (version: DatasetVersionSummaryInfo) => 'deaccessioned' in version.summary export function DatasetVersions({ - datasetRepository, datasetId, currentVersionNumber, canUpdateDataset, isInView, isCurrentVersionDeaccessioned }: DatasetVersionsProps) { + const { datasetRepository } = useDatasetRepositories() const { t } = useTranslation('dataset') const [selectedVersions, setSelectedVersions] = useState([]) const { @@ -87,7 +86,6 @@ export function DatasetVersions({ <> {selectedVersions.length === 2 && ( @@ -169,7 +167,6 @@ export function DatasetVersions({ /> {showViewDetails && ( void } export function DeaccessionDatasetModal({ - datasetRepository, datasetPersistentId, show, handleCloseDeaccessionModal }: DeaccessionDatasetModalProps) { + const { datasetRepository } = useDatasetRepositories() const { t } = useTranslation(['dataset', 'shared']) const modalTitle = 'Deaccession Dataset' const [showConfirmationModal, setShowConfirmationModal] = useState(false) diff --git a/src/sections/edit-collection-featured-items/EditFeaturedItemsFactory.tsx b/src/sections/edit-collection-featured-items/EditFeaturedItemsFactory.tsx index d4622e20b..9c15bb043 100644 --- a/src/sections/edit-collection-featured-items/EditFeaturedItemsFactory.tsx +++ b/src/sections/edit-collection-featured-items/EditFeaturedItemsFactory.tsx @@ -1,10 +1,12 @@ import { ReactElement } from 'react' import { useParams } from 'react-router-dom' import { CollectionJSDataverseRepository } from '@/collection/infrastructure/repositories/CollectionJSDataverseRepository' +import { DatasetJSDataverseRepository } from '@/dataset/infrastructure/repositories/DatasetJSDataverseRepository' import { EditFeaturedItems } from './EditFeaturedItems' import { RepositoriesProvider } from '@/shared/contexts/repositories/RepositoriesProvider' const collectionRepository = new CollectionJSDataverseRepository() +const datasetRepository = new DatasetJSDataverseRepository() export class EditFeaturedItemsFactory { static create(): ReactElement { @@ -16,7 +18,9 @@ function EditFeaturedItemsWithSearchParams() { const { collectionId } = useParams<{ collectionId: string }>() return ( - + ) diff --git a/src/sections/edit-collection/EditCollectionFactory.tsx b/src/sections/edit-collection/EditCollectionFactory.tsx index e35bafbbb..dbd13e6b6 100644 --- a/src/sections/edit-collection/EditCollectionFactory.tsx +++ b/src/sections/edit-collection/EditCollectionFactory.tsx @@ -1,12 +1,14 @@ import { ReactElement } from 'react' import { useParams } from 'react-router-dom' import { CollectionJSDataverseRepository } from '@/collection/infrastructure/repositories/CollectionJSDataverseRepository' +import { DatasetJSDataverseRepository } from '@/dataset/infrastructure/repositories/DatasetJSDataverseRepository' import { MetadataBlockInfoJSDataverseRepository } from '@/metadata-block-info/infrastructure/repositories/MetadataBlockInfoJSDataverseRepository' import { EditCollection } from './EditCollection' import { RepositoriesProvider } from '@/shared/contexts/repositories/RepositoriesProvider' const collectionRepository = new CollectionJSDataverseRepository() const metadataBlockInfoRepository = new MetadataBlockInfoJSDataverseRepository() +const datasetRepository = new DatasetJSDataverseRepository() export class EditCollectionFactory { static create(): ReactElement { @@ -20,7 +22,9 @@ function EditCollectionWithParams() { } return ( - + { +export const EditDatasetMetadata = ({ metadataBlockInfoRepository }: EditDatasetMetadataProps) => { const { t } = useTranslation('editDatasetMetadata') const { dataset, isLoading } = useDataset() const { setIsLoading } = useLoading() @@ -66,7 +61,6 @@ export const EditDatasetMetadata = ({ - - + + + + + ) } diff --git a/src/sections/edit-dataset-terms/EditDatasetTerms.tsx b/src/sections/edit-dataset-terms/EditDatasetTerms.tsx index c5c9006a1..55c39a851 100644 --- a/src/sections/edit-dataset-terms/EditDatasetTerms.tsx +++ b/src/sections/edit-dataset-terms/EditDatasetTerms.tsx @@ -6,7 +6,6 @@ import { useLoading } from '../../shared/contexts/loading/LoadingContext' import { EditLicenseAndTerms } from './edit-license-and-terms/EditLicenseAndTerms' import { EditTermsOfAccess } from './edit-terms-of-access/EditTermsOfAccess' import { LicenseRepository } from '../../licenses/domain/repositories/LicenseRepository' -import { DatasetRepository } from '../../dataset/domain/repositories/DatasetRepository' import { EditGuestbook } from './edit-guestbook/EditGuestbook' import { GuestbookRepository } from '@/guestbooks/domain/repositories/GuestbookRepository' import { useDataset } from '../dataset/DatasetContext' @@ -22,14 +21,12 @@ const tabsKeys = EditDatasetTermsHelper.EDIT_DATASET_TERMS_TABS_KEYS interface EditDatasetTermsProps { defaultActiveTabKey: EditDatasetTermsTabKey licenseRepository: LicenseRepository - datasetRepository: DatasetRepository guestbookRepository: GuestbookRepository } export const EditDatasetTerms = ({ defaultActiveTabKey, licenseRepository, - datasetRepository, guestbookRepository }: EditDatasetTermsProps) => { const { t } = useTranslation('dataset') @@ -115,7 +112,6 @@ export const EditDatasetTerms = ({
@@ -126,10 +122,7 @@ export const EditDatasetTerms = ({ {t('editTerms.tabs.restrictedFilesTerms')}
- +
@@ -152,7 +145,6 @@ export const EditDatasetTerms = ({
@@ -162,10 +154,7 @@ export const EditDatasetTerms = ({ eventKey={tabsKeys.restrictedFilesTerms} title={t('editTerms.tabs.restrictedFilesTerms')}>
- +
diff --git a/src/sections/edit-dataset-terms/EditDatasetTermsFactory.tsx b/src/sections/edit-dataset-terms/EditDatasetTermsFactory.tsx index 3df3358fc..02e4afd9b 100644 --- a/src/sections/edit-dataset-terms/EditDatasetTermsFactory.tsx +++ b/src/sections/edit-dataset-terms/EditDatasetTermsFactory.tsx @@ -7,10 +7,13 @@ import { DatasetProvider } from '../dataset/DatasetProvider' import { ReactElement } from 'react' import { DatasetNonNumericVersion } from '@/dataset/domain/models/Dataset' import { GuestbookJSDataverseRepository } from '@/guestbooks/infrastructure/repositories/GuestbookJSDataverseRepository' +import { CollectionJSDataverseRepository } from '@/collection/infrastructure/repositories/CollectionJSDataverseRepository' +import { RepositoriesProvider } from '@/shared/contexts/repositories/RepositoriesProvider' const licenseRepository = new LicenseJSDataverseRepository() const datasetRepository = new DatasetJSDataverseRepository() const guestbookRepository = new GuestbookJSDataverseRepository() +const collectionRepository = new CollectionJSDataverseRepository() export class EditDatasetTermsFactory { static create(): ReactElement { @@ -26,15 +29,18 @@ function EditDatasetTermsWithSearchParams() { const version = DatasetNonNumericVersion.LATEST return ( - - - + + + + + ) } diff --git a/src/sections/edit-dataset-terms/edit-license-and-terms/EditLicenseAndTerms.tsx b/src/sections/edit-dataset-terms/edit-license-and-terms/EditLicenseAndTerms.tsx index 02abc4d56..ef5b96f84 100644 --- a/src/sections/edit-dataset-terms/edit-license-and-terms/EditLicenseAndTerms.tsx +++ b/src/sections/edit-dataset-terms/edit-license-and-terms/EditLicenseAndTerms.tsx @@ -7,7 +7,6 @@ import { Form, Row, Col, Button, Alert } from '@iqss/dataverse-design-system' import { CustomTerms } from '../../../dataset/domain/models/Dataset' import { LicenseRepository } from '../../../licenses/domain/repositories/LicenseRepository' import { useGetLicenses } from './useGetLicenses' -import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' import { useDataset } from '../../dataset/DatasetContext' import { useUpdateDatasetLicense } from './useUpdateDatasetLicense' import { Route, QueryParamKey } from '../../Route.enum' @@ -15,6 +14,7 @@ import { DatasetNonNumericVersionSearchParam, DatasetPublishingStatus } from '../../../dataset/domain/models/Dataset' +import { useDatasetRepositories } from '@/shared/contexts/repositories/RepositoriesProvider' import styles from './EditLicenseAndTerms.module.scss' const CUSTOM_LICENSE_VALUE = 'CUSTOM' as const @@ -26,15 +26,14 @@ interface EditLicenseAndTermsFormData { interface EditLicenseAndTermsProps { licenseRepository: LicenseRepository - datasetRepository: DatasetRepository onFormStateChange?: (isDirty: boolean) => void } export function EditLicenseAndTerms({ licenseRepository, - datasetRepository, onFormStateChange }: EditLicenseAndTermsProps) { + const { datasetRepository } = useDatasetRepositories() const { t } = useTranslation('dataset') const { t: tShared } = useTranslation('shared') const { dataset, refreshDataset } = useDataset() diff --git a/src/sections/edit-dataset-terms/edit-terms-of-access/EditTermsOfAccess.tsx b/src/sections/edit-dataset-terms/edit-terms-of-access/EditTermsOfAccess.tsx index fb39ee1df..bd96bdf24 100644 --- a/src/sections/edit-dataset-terms/edit-terms-of-access/EditTermsOfAccess.tsx +++ b/src/sections/edit-dataset-terms/edit-terms-of-access/EditTermsOfAccess.tsx @@ -9,21 +9,18 @@ import { DatasetPublishingStatus, TermsOfAccess } from '@/dataset/domain/models/Dataset' -import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' import { useDataset } from '../../dataset/DatasetContext' import { useUpdateTermsOfAccess } from './useUpdateTermsOfAccess' import { QueryParamKey, Route } from '@/sections/Route.enum' import { useNavigate } from 'react-router-dom' +import { useDatasetRepositories } from '@/shared/contexts/repositories/RepositoriesProvider' interface EditTermsOfAccessProps { - datasetRepository: DatasetRepository onFormStateChange?: (isDirty: boolean) => void } -export function EditTermsOfAccess({ - datasetRepository, - onFormStateChange -}: EditTermsOfAccessProps) { +export function EditTermsOfAccess({ onFormStateChange }: EditTermsOfAccessProps) { + const { datasetRepository } = useDatasetRepositories() const { t } = useTranslation('dataset') const { t: tShared } = useTranslation('shared') const { dataset, refreshDataset } = useDataset() diff --git a/src/sections/featured-item/FeaturedItemFactory.tsx b/src/sections/featured-item/FeaturedItemFactory.tsx index ebcf661b8..819b43328 100644 --- a/src/sections/featured-item/FeaturedItemFactory.tsx +++ b/src/sections/featured-item/FeaturedItemFactory.tsx @@ -1,10 +1,12 @@ import { ReactElement } from 'react' import { useParams } from 'react-router-dom' import { CollectionJSDataverseRepository } from '../../collection/infrastructure/repositories/CollectionJSDataverseRepository' +import { DatasetJSDataverseRepository } from '@/dataset/infrastructure/repositories/DatasetJSDataverseRepository' import { FeaturedItem } from './FeaturedItem' import { RepositoriesProvider } from '@/shared/contexts/repositories/RepositoriesProvider' const collectionRepository = new CollectionJSDataverseRepository() +const datasetRepository = new DatasetJSDataverseRepository() export class FeaturedItemFactory { static create(): ReactElement { @@ -19,7 +21,9 @@ function FeaturedItemWithParams() { } return ( - + @@ -177,7 +173,6 @@ export function File({ existingLabels={file.metadata.labels} isTabularFile={file.metadata.isTabular} fileType={file.metadata.type.value} - datasetRepository={datasetRepository} /> )} diff --git a/src/sections/file/FileFactory.tsx b/src/sections/file/FileFactory.tsx index 7db185050..b8d8326cf 100644 --- a/src/sections/file/FileFactory.tsx +++ b/src/sections/file/FileFactory.tsx @@ -12,6 +12,8 @@ import { AccessJSDataverseRepository } from '@/access/infrastructure/repositorie import { AccessRepositoryProvider } from '../access/AccessRepositoryProvider' import { GuestbookJSDataverseRepository } from '@/guestbooks/infrastructure/repositories/GuestbookJSDataverseRepository' import { GuestbookRepositoryProvider } from '../guestbooks/GuestbookRepositoryProvider' +import { CollectionJSDataverseRepository } from '@/collection/infrastructure/repositories/CollectionJSDataverseRepository' +import { RepositoriesProvider } from '@/shared/contexts/repositories/RepositoriesProvider' const repository = new FileJSDataverseRepository() const datasetRepository = new DatasetJSDataverseRepository() @@ -19,6 +21,7 @@ const dataverseInfoRepository = new DataverseInfoJSDataverseRepository() const contactRepository = new ContactJSDataverseRepository() const accessRepository = new AccessJSDataverseRepository() const guestbookRepository = new GuestbookJSDataverseRepository() +const collectionRepository = new CollectionJSDataverseRepository() export class FileFactory { static create(): ReactElement { @@ -46,14 +49,17 @@ function FileWithSearchParams() { } return ( - + + + ) } diff --git a/src/sections/file/file-action-buttons/edit-file-menu/EditFileMenu.tsx b/src/sections/file/file-action-buttons/edit-file-menu/EditFileMenu.tsx index 4dc6deb7b..fa7c18e9b 100644 --- a/src/sections/file/file-action-buttons/edit-file-menu/EditFileMenu.tsx +++ b/src/sections/file/file-action-buttons/edit-file-menu/EditFileMenu.tsx @@ -9,7 +9,6 @@ import { ReplaceFileReferrer } from '@/sections/replace-file/ReplaceFile' import { EditFileMetadataReferrer } from '@/sections/edit-file-metadata/EditFileMetadata' import { EditFileTagsButton } from './edit-file-tags/EditFileTagsButton' import { FileLabel } from '@/files/domain/models/FileMetadata' -import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' import { FileConfigureToolsOptions } from '../access-file-menu/FileToolOptions' interface EditFileMenuProps { @@ -19,7 +18,6 @@ interface EditFileMenuProps { datasetInfo: EditFileMenuDatasetInfo storageIdentifier: string | undefined existingLabels?: FileLabel[] - datasetRepository: DatasetRepository isTabularFile: boolean fileType: string } @@ -40,7 +38,6 @@ export const EditFileMenu = ({ storageIdentifier, existingLabels, isTabularFile, - datasetRepository, fileType }: EditFileMenuProps) => { const { t } = useTranslation('file') @@ -86,7 +83,6 @@ export const EditFileMenu = ({ existingLabels={existingLabels} datasetPersistentId={datasetInfo.persistentId} isTabularFile={isTabularFile} - datasetRepository={datasetRepository} /> diff --git a/src/sections/file/file-action-buttons/edit-file-menu/edit-file-tags/EditFileTagsButton.tsx b/src/sections/file/file-action-buttons/edit-file-menu/edit-file-tags/EditFileTagsButton.tsx index 8cf505eeb..385f3fbb0 100644 --- a/src/sections/file/file-action-buttons/edit-file-menu/edit-file-tags/EditFileTagsButton.tsx +++ b/src/sections/file/file-action-buttons/edit-file-menu/edit-file-tags/EditFileTagsButton.tsx @@ -10,7 +10,6 @@ import { useUpdateFileTabularTags } from './useUpdateFileTabularTags' import { FileRepository } from '@/files/domain/repositories/FileRepository' import { FileLabel } from '@/files/domain/models/FileMetadata' import { DatasetNonNumericVersionSearchParam } from '@/dataset/domain/models/Dataset' -import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' interface EditFileTagsButtonProps { fileId: number @@ -18,7 +17,6 @@ interface EditFileTagsButtonProps { existingLabels?: FileLabel[] datasetPersistentId: string isTabularFile: boolean - datasetRepository: DatasetRepository } export const EditFileTagsButton = ({ @@ -26,8 +24,7 @@ export const EditFileTagsButton = ({ fileRepository, existingLabels, datasetPersistentId, - isTabularFile, - datasetRepository + isTabularFile }: EditFileTagsButtonProps) => { const [isModalOpen, setIsModalOpen] = useState(false) const { t } = useTranslation('file') @@ -81,7 +78,6 @@ export const EditFileTagsButton = ({ isUpdatingTabularTags={isUpdatingTabularTags} errorUpdatingTabularTags={errorUpdatingTabularTags} isTabularFile={isTabularFile} - datasetRepository={datasetRepository} datasetPersistentId={datasetPersistentId} /> diff --git a/src/sections/file/file-action-buttons/edit-file-menu/edit-file-tags/edit-file-tags-modal/EditFileTagsModal.tsx b/src/sections/file/file-action-buttons/edit-file-menu/edit-file-tags/edit-file-tags-modal/EditFileTagsModal.tsx index 8fac80b7f..d79045e65 100644 --- a/src/sections/file/file-action-buttons/edit-file-menu/edit-file-tags/edit-file-tags-modal/EditFileTagsModal.tsx +++ b/src/sections/file/file-action-buttons/edit-file-menu/edit-file-tags/edit-file-tags-modal/EditFileTagsModal.tsx @@ -5,8 +5,8 @@ import { FileLabels } from '@/sections/file/file-labels/FileLabels' import { FileLabel, FileLabelType } from '@/files/domain/models/FileMetadata' import { useFilesContext } from '@/sections/file/FilesContext' import { Utils } from '@/shared/helpers/Utils' -import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' import { useGetAvailableCategories } from './useGetAvailableCategories' +import { useDatasetRepositories } from '@/shared/contexts/repositories/RepositoriesProvider' const TABULAR_TAG_OPTIONS = [ 'Survey', @@ -38,7 +38,6 @@ interface EditFileTagsModalProps { ) => Promise isUpdatingTabularTags: boolean errorUpdatingTabularTags: string | null - datasetRepository: DatasetRepository datasetPersistentId: string } @@ -54,9 +53,9 @@ export const EditFileTagsModal = ({ errorUpdatingFileCategories, isUpdatingTabularTags, errorUpdatingTabularTags, - datasetRepository, datasetPersistentId }: EditFileTagsModalProps) => { + const { datasetRepository } = useDatasetRepositories() const { t: tShared } = useTranslation('shared') const { t } = useTranslation('file') const modalTitle = t('editFileTagsModal.title') diff --git a/src/sections/homepage/HomepageFactory.tsx b/src/sections/homepage/HomepageFactory.tsx index 305d91a91..19b119a76 100644 --- a/src/sections/homepage/HomepageFactory.tsx +++ b/src/sections/homepage/HomepageFactory.tsx @@ -1,18 +1,22 @@ import { ReactElement } from 'react' import { CollectionJSDataverseRepository } from '@/collection/infrastructure/repositories/CollectionJSDataverseRepository' +import { DatasetJSDataverseRepository } from '@/dataset/infrastructure/repositories/DatasetJSDataverseRepository' import { ApiDataverseHubRepository } from '@/dataverse-hub/infrastructure/repositories/ApiDataverseHubRepository' import { SearchJSRepository } from '@/search/infrastructure/repositories/SearchJSRepository' import { RepositoriesProvider } from '@/shared/contexts/repositories/RepositoriesProvider' import Homepage from './Homepage' const collectionRepository = new CollectionJSDataverseRepository() +const datasetRepository = new DatasetJSDataverseRepository() const dataverseHubRepository = new ApiDataverseHubRepository() const searchRepository = new SearchJSRepository() export class HomepageFactory { static create(): ReactElement { return ( - + +
) diff --git a/src/sections/replace-file/ReplaceFile.tsx b/src/sections/replace-file/ReplaceFile.tsx index 401782721..ea8382456 100644 --- a/src/sections/replace-file/ReplaceFile.tsx +++ b/src/sections/replace-file/ReplaceFile.tsx @@ -1,7 +1,6 @@ import { useEffect } from 'react' import { useTranslation } from 'react-i18next' import { Col, Row, Tabs } from '@iqss/dataverse-design-system' -import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' import { FileRepository } from '@/files/domain/repositories/FileRepository' import { useFile } from '../file/useFile' import { useLoading } from '../../shared/contexts/loading/LoadingContext' @@ -14,7 +13,6 @@ import styles from './ReplaceFile.module.scss' interface ReplaceFileProps { fileRepository: FileRepository - datasetRepository: DatasetRepository fileIdFromParams: number datasetPidFromParams: string datasetVersionFromParams: string @@ -29,7 +27,6 @@ export enum ReplaceFileReferrer { export const ReplaceFile = ({ fileRepository, - datasetRepository, fileIdFromParams, datasetPidFromParams, datasetVersionFromParams, @@ -81,7 +78,6 @@ export const ReplaceFile = ({
+ + + ) } diff --git a/src/sections/shared/citation/citation-download/CitationDownloadButton.tsx b/src/sections/shared/citation/citation-download/CitationDownloadButton.tsx index f15e3f946..7cc5e902d 100644 --- a/src/sections/shared/citation/citation-download/CitationDownloadButton.tsx +++ b/src/sections/shared/citation/citation-download/CitationDownloadButton.tsx @@ -3,23 +3,19 @@ import { DropdownButton, DropdownButtonItem } from '@iqss/dataverse-design-syste import { ViewStyledCitationModal } from './ViewStyledCitationModal' import { useState } from 'react' import { CitationFormat } from '@/dataset/domain/models/DatasetCitation' -import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' import { useDownloadCitation } from './useDownloadCitation' import { FormattedCitation } from '@iqss/dataverse-client-javascript/dist/datasets/domain/models/FormattedCitation' import { toast } from 'react-toastify' +import { useDatasetRepositories } from '@/shared/contexts/repositories/RepositoriesProvider' import styles from '../Citation.module.scss' interface CitationDownloadProps { - datasetRepository: DatasetRepository datasetId: string version: string } -export function CitationDownloadButton({ - datasetRepository, - datasetId, - version -}: CitationDownloadProps) { +export function CitationDownloadButton({ datasetId, version }: CitationDownloadProps) { + const { datasetRepository } = useDatasetRepositories() const { t } = useTranslation('shared', { keyPrefix: 'downloadCitation' }) const [isModalOpen, setIsModalOpen] = useState(false) const [styledCitation, setStyledCitation] = useState(null) diff --git a/src/sections/shared/file-uploader/FileUploader.tsx b/src/sections/shared/file-uploader/FileUploader.tsx index 6631b2852..54d61b58e 100644 --- a/src/sections/shared/file-uploader/FileUploader.tsx +++ b/src/sections/shared/file-uploader/FileUploader.tsx @@ -12,7 +12,6 @@ import FileUploaderPanel from './FileUploaderPanel' export type FileUploaderProps = | { fileRepository: FileRepository - datasetRepository: DatasetRepository datasetPersistentId: string storageType: StorageType operationType: OperationType.REPLACE_FILE @@ -25,7 +24,6 @@ export type FileUploaderProps = } | { fileRepository: FileRepository - datasetRepository: DatasetRepository datasetPersistentId: string storageType: StorageType operationType: OperationType.ADD_FILES_TO_DATASET @@ -49,7 +47,6 @@ export enum OperationType { export const FileUploader = ({ fileRepository, - datasetRepository, datasetPersistentId, storageType, operationType, @@ -81,7 +78,6 @@ export const FileUploader = ({ diff --git a/src/sections/shared/file-uploader/file-upload-input/FileUploadInput.tsx b/src/sections/shared/file-uploader/file-upload-input/FileUploadInput.tsx index 4c385da67..02d7a445d 100644 --- a/src/sections/shared/file-uploader/file-upload-input/FileUploadInput.tsx +++ b/src/sections/shared/file-uploader/file-upload-input/FileUploadInput.tsx @@ -17,10 +17,10 @@ import { FileUploaderHelper } from '../FileUploaderHelper' import { SwalModal } from '../../swal-modal/SwalModal' import styles from './FileUploadInput.module.scss' import { useUploadLimit } from './useUploadLimit' +import { useDatasetRepositories } from '@/shared/contexts/repositories/RepositoriesProvider' type FileUploadInputProps = { fileRepository: FileRepository - datasetRepository: DatasetRepository datasetPersistentId: string fetchUploadLimits?: ( datasetId: string | number, @@ -35,10 +35,10 @@ const maxFilesPerUpload = 1000 const FileUploadInput = ({ fileRepository, - datasetRepository, datasetPersistentId, fetchUploadLimits }: FileUploadInputProps) => { + const { datasetRepository } = useDatasetRepositories() const { fileUploaderState, addFile, diff --git a/src/sections/shared/form/DatasetMetadataForm/MetadataForm/index.tsx b/src/sections/shared/form/DatasetMetadataForm/MetadataForm/index.tsx index cfa90943b..60d9413cd 100644 --- a/src/sections/shared/form/DatasetMetadataForm/MetadataForm/index.tsx +++ b/src/sections/shared/form/DatasetMetadataForm/MetadataForm/index.tsx @@ -4,7 +4,6 @@ import { useTranslation } from 'react-i18next' import { FieldErrors, FormProvider, useForm } from 'react-hook-form' import { useSession } from '@/sections/session/SessionContext' import { Accordion, Alert, Button } from '@iqss/dataverse-design-system' -import { type DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' import { type MetadataBlockInfo } from '@/metadata-block-info/domain/models/MetadataBlockInfo' import { type DatasetMetadataFormValues } from '../MetadataFieldsHelper' import { type DatasetMetadataFormMode } from '..' @@ -15,6 +14,7 @@ import { RouteWithParams } from '@/sections/Route.enum' import { SeparationLine } from '@/sections/shared/layout/SeparationLine/SeparationLine' import { usePrefillFieldsWithUserData } from './usePrefillFieldsWithUserData' import { DatasetTemplateInstruction } from '@/templates/domain/models/Template' +import { useDatasetRepositories } from '@/shared/contexts/repositories/RepositoriesProvider' import styles from './index.module.scss' interface FormProps { @@ -22,7 +22,6 @@ interface FormProps { collectionId: string formDefaultValues: DatasetMetadataFormValues metadataBlocksInfo: MetadataBlockInfo[] - datasetRepository: DatasetRepository datasetPersistentID?: string datasetLastUpdateTime?: string datasetTemplateInstructions?: DatasetTemplateInstruction[] @@ -33,11 +32,11 @@ export const MetadataForm = ({ collectionId, formDefaultValues, metadataBlocksInfo, - datasetRepository, datasetPersistentID, datasetLastUpdateTime, datasetTemplateInstructions }: FormProps) => { + const { datasetRepository } = useDatasetRepositories() const { user } = useSession() const navigate = useNavigate() const { t } = useTranslation('shared') diff --git a/src/sections/shared/form/DatasetMetadataForm/index.tsx b/src/sections/shared/form/DatasetMetadataForm/index.tsx index 1bd993f6a..71ff59017 100644 --- a/src/sections/shared/form/DatasetMetadataForm/index.tsx +++ b/src/sections/shared/form/DatasetMetadataForm/index.tsx @@ -1,7 +1,6 @@ import { useEffect } from 'react' import { useLoading } from '../../../../shared/contexts/loading/LoadingContext' import { useGetMetadataBlocksInfo } from './useGetMetadataBlocksInfo' -import { DatasetRepository } from '../../../../dataset/domain/repositories/DatasetRepository' import { MetadataBlockInfoRepository } from '../../../../metadata-block-info/domain/repositories/MetadataBlockInfoRepository' import { MetadataFieldsHelper } from './MetadataFieldsHelper' import { MetadataFormSkeleton } from './MetadataForm/MetadataFormSkeleton' @@ -14,7 +13,6 @@ type DatasetMetadataFormProps = | { mode: 'create' collectionId: string - datasetRepository: DatasetRepository datasetPersistentID?: never metadataBlockInfoRepository: MetadataBlockInfoRepository datasetMetadaBlocksCurrentValues?: never @@ -24,7 +22,6 @@ type DatasetMetadataFormProps = | { mode: 'edit' collectionId: string - datasetRepository: DatasetRepository datasetPersistentID: string metadataBlockInfoRepository: MetadataBlockInfoRepository datasetMetadaBlocksCurrentValues: DatasetMetadataBlocks @@ -37,7 +34,6 @@ export type DatasetMetadataFormMode = 'create' | 'edit' export const DatasetMetadataForm = ({ mode, collectionId, - datasetRepository, datasetPersistentID, metadataBlockInfoRepository, datasetMetadaBlocksCurrentValues, @@ -105,7 +101,6 @@ export const DatasetMetadataForm = ({ collectionId={collectionId} formDefaultValues={formDefaultValues} metadataBlocksInfo={metadataBlocksInfo} - datasetRepository={datasetRepository} datasetPersistentID={datasetPersistentID} datasetLastUpdateTime={datasetLastUpdateTime} datasetTemplateInstructions={datasetTemplate?.instructions} diff --git a/src/sections/upload-dataset-files/UploadDatasetFiles.tsx b/src/sections/upload-dataset-files/UploadDatasetFiles.tsx index 6457a1c7d..0f828b99d 100644 --- a/src/sections/upload-dataset-files/UploadDatasetFiles.tsx +++ b/src/sections/upload-dataset-files/UploadDatasetFiles.tsx @@ -1,7 +1,6 @@ import { useEffect } from 'react' import { useTranslation } from 'react-i18next' import { Tabs } from '@iqss/dataverse-design-system' -import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' import { FileRepository } from '../../files/domain/repositories/FileRepository' import { useLoading } from '../../shared/contexts/loading/LoadingContext' import { useDataset } from '../dataset/DatasetContext' @@ -13,13 +12,9 @@ import styles from './UploadDatasetFiles.module.scss' interface UploadDatasetFilesProps { fileRepository: FileRepository - datasetRepository: DatasetRepository } -export const UploadDatasetFiles = ({ - fileRepository: fileRepository, - datasetRepository -}: UploadDatasetFilesProps) => { +export const UploadDatasetFiles = ({ fileRepository: fileRepository }: UploadDatasetFilesProps) => { const { setIsLoading } = useLoading() const { dataset, isLoading: isLoadingDataset } = useDataset() const { t } = useTranslation('uploadDatasetFiles') @@ -49,7 +44,6 @@ export const UploadDatasetFiles = ({
- - + + + + + ) } diff --git a/src/shared/contexts/repositories/RepositoriesProvider.tsx b/src/shared/contexts/repositories/RepositoriesProvider.tsx index 526eabdc4..0141e274f 100644 --- a/src/shared/contexts/repositories/RepositoriesProvider.tsx +++ b/src/shared/contexts/repositories/RepositoriesProvider.tsx @@ -1,8 +1,10 @@ import React, { createContext, useContext, useMemo } from 'react' import { CollectionRepository } from '@/collection/domain/repositories/CollectionRepository' +import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' export interface RepositoriesContextValue { collectionRepository: CollectionRepository + datasetRepository: DatasetRepository } const RepositoriesContext = createContext(undefined) @@ -13,13 +15,15 @@ interface RepositoriesProviderProps extends RepositoriesContextValue { export function RepositoriesProvider({ children, - collectionRepository + collectionRepository, + datasetRepository }: RepositoriesProviderProps) { const value = useMemo( () => ({ - collectionRepository + collectionRepository, + datasetRepository }), - [collectionRepository] + [collectionRepository, datasetRepository] ) return {children} @@ -40,3 +44,9 @@ export function useCollectionRepositories() { return { collectionRepository } } + +export function useDatasetRepositories() { + const { datasetRepository } = useRepositories() + + return { datasetRepository } +} diff --git a/src/stories/WithRepositories.tsx b/src/stories/WithRepositories.tsx index ec47aef7e..2917e6109 100644 --- a/src/stories/WithRepositories.tsx +++ b/src/stories/WithRepositories.tsx @@ -1,16 +1,23 @@ import { StoryFn } from '@storybook/react' import { ReactNode } from 'react' import { CollectionRepository } from '@/collection/domain/repositories/CollectionRepository' +import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' import { RepositoriesProvider } from '@/shared/contexts/repositories/RepositoriesProvider' interface WithRepositoriesProps { - collectionRepository: CollectionRepository + collectionRepository?: CollectionRepository + datasetRepository?: DatasetRepository } -export function WithRepositories({ collectionRepository }: WithRepositoriesProps) { +export function WithRepositories({ + collectionRepository = {} as CollectionRepository, + datasetRepository = {} as DatasetRepository +}: WithRepositoriesProps) { function WithRepositoriesDecorator(Story: StoryFn) { return ( - + ) @@ -27,10 +34,13 @@ interface RepositoriesStoryProviderProps extends WithRepositoriesProps { export function RepositoriesStoryProvider({ children, - collectionRepository + collectionRepository = {} as CollectionRepository, + datasetRepository = {} as DatasetRepository }: RepositoriesStoryProviderProps) { return ( - + {children} ) diff --git a/src/stories/create-dataset/CreateDataset.stories.tsx b/src/stories/create-dataset/CreateDataset.stories.tsx index e7631117a..b074778c6 100644 --- a/src/stories/create-dataset/CreateDataset.stories.tsx +++ b/src/stories/create-dataset/CreateDataset.stories.tsx @@ -31,9 +31,10 @@ export const Default: Story = { }, render: () => ( - + ( - + export const NotAllowedToAddDataset: Story = { render: () => ( + collectionRepository={collectionRepositoryWithoutPermissionsToCreateDataset} + datasetRepository={new DatasetMockRepository()}> ( - + ( - + ( - + ( - + ( - + ( - + ( - + ( - + ( - + ( - + + + ) } diff --git a/src/stories/dataset/dataset-action-buttons/DatasetActionButtons.stories.tsx b/src/stories/dataset/dataset-action-buttons/DatasetActionButtons.stories.tsx index 6ac13ea5e..c766d6281 100644 --- a/src/stories/dataset/dataset-action-buttons/DatasetActionButtons.stories.tsx +++ b/src/stories/dataset/dataset-action-buttons/DatasetActionButtons.stories.tsx @@ -29,7 +29,9 @@ type Story = StoryObj export const WithPublishPermissions: Story = { render: () => ( - + @@ -51,7 +52,9 @@ export const WithPublishPermissions: Story = { export const WithNoDatasetPermissions: Story = { render: () => ( - + @@ -72,7 +74,9 @@ export const WithNoDatasetPermissions: Story = { export const WithUpdateAndNoPublishDatasetPermissions: Story = { render: () => ( - + diff --git a/src/stories/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetMenu.stories.tsx b/src/stories/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetMenu.stories.tsx index 5660587b8..56dc389d1 100644 --- a/src/stories/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetMenu.stories.tsx +++ b/src/stories/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetMenu.stories.tsx @@ -10,11 +10,17 @@ import { DatasetMockRepository } from '../../../dataset/DatasetMockRepository' import { EditDatasetMenu } from '../../../../sections/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetMenu' import { WithLoggedInUser } from '@/stories/WithLoggedInUser' import { DatasetPublishingStatus } from '@/dataset/domain/models/Dataset' +import { WithRepositories } from '@/stories/WithRepositories' const meta: Meta = { title: 'Sections/Dataset Page/DatasetActionButtons/EditDatasetMenu', component: EditDatasetMenu, - decorators: [WithI18next, WithSettings, WithLoggedInUser], + decorators: [ + WithI18next, + WithSettings, + WithLoggedInUser, + WithRepositories({ datasetRepository: new DatasetMockRepository() }) + ], parameters: { // Sets the delay for all stories. chromatic: { delay: 15000, pauseAnimationAtEnd: true } @@ -27,7 +33,6 @@ type Story = StoryObj export const WithAllPermissions: Story = { render: () => ( ( ( ( { export const Default: Story = { render: () => ( - + {}} /> @@ -57,10 +58,11 @@ export const Default: Story = { export const WithLinkedCollections: Story = { render: () => ( - + {}} /> @@ -90,10 +92,11 @@ withOnlyOneCollectionToLinkRepo.getForLinking = () => { export const WithOnlyOneCollectionToLink: Story = { render: () => ( - + {}} /> diff --git a/src/stories/dataset/dataset-action-buttons/publish-dataset-menu/PublishDatasetMenu.stories.tsx b/src/stories/dataset/dataset-action-buttons/publish-dataset-menu/PublishDatasetMenu.stories.tsx index 5a2829ff4..81cf6638e 100644 --- a/src/stories/dataset/dataset-action-buttons/publish-dataset-menu/PublishDatasetMenu.stories.tsx +++ b/src/stories/dataset/dataset-action-buttons/publish-dataset-menu/PublishDatasetMenu.stories.tsx @@ -27,7 +27,9 @@ type Story = StoryObj export const PublishingAllowed: Story = { render: () => ( - + ) @@ -44,7 +45,9 @@ export const PublishingAllowed: Story = { export const NoValidTermsOfAccess: Story = { render: () => ( - + ) @@ -61,7 +63,9 @@ export const NoValidTermsOfAccess: Story = { export const DatasetInReview: Story = { render: () => ( - + ) diff --git a/src/stories/dataset/dataset-action-buttons/unlink-dataset-button/UnlinkDatasetButton.stories.tsx b/src/stories/dataset/dataset-action-buttons/unlink-dataset-button/UnlinkDatasetButton.stories.tsx index 4ae57cd38..8258b1777 100644 --- a/src/stories/dataset/dataset-action-buttons/unlink-dataset-button/UnlinkDatasetButton.stories.tsx +++ b/src/stories/dataset/dataset-action-buttons/unlink-dataset-button/UnlinkDatasetButton.stories.tsx @@ -30,10 +30,11 @@ type Story = StoryObj export const Default: Story = { render: () => ( - + {}} /> @@ -67,10 +68,11 @@ withOnlyOneCollectionToUnlinkRepo.getForUnlinking = () => { export const WithOnlyOneCollectionToUnlink: Story = { render: () => ( - + {}} /> diff --git a/src/stories/dataset/dataset-citation/DatasetCitation.stories.tsx b/src/stories/dataset/dataset-citation/DatasetCitation.stories.tsx index 5bfc2827c..7c55a86b5 100644 --- a/src/stories/dataset/dataset-citation/DatasetCitation.stories.tsx +++ b/src/stories/dataset/dataset-citation/DatasetCitation.stories.tsx @@ -7,11 +7,12 @@ import { } from '../../../../tests/component/dataset/domain/models/DatasetMother' import { FakerHelper } from '../../../../tests/component/shared/FakerHelper' import { DatasetMockRepository } from '../DatasetMockRepository' +import { WithRepositories } from '../../WithRepositories' const meta: Meta = { title: 'Sections/Dataset Page/DatasetCitation', component: DatasetCitation, - decorators: [WithI18next] + decorators: [WithI18next, WithRepositories({ datasetRepository: new DatasetMockRepository() })] } export default meta @@ -24,11 +25,7 @@ export const Default: Story = {




- +
) } @@ -41,12 +38,7 @@ export const WithThumbnailImage: Story = {




- +
) } @@ -62,11 +54,7 @@ export const DraftVersion: Story = {




- +
) } @@ -83,11 +71,7 @@ export const Deaccessioned: Story = {




- +
) } @@ -104,11 +88,7 @@ export const Anonymized: Story = {




- +
) } @@ -117,13 +97,6 @@ export const Anonymized: Story = { export const WithoutThumbnail: Story = { render: () => { const dataset = DatasetMother.createRealistic() - return ( - - ) + return } } diff --git a/src/stories/dataset/dataset-files/DatasetFiles.stories.tsx b/src/stories/dataset/dataset-files/DatasetFiles.stories.tsx index ebcdf63ca..be915cd6e 100644 --- a/src/stories/dataset/dataset-files/DatasetFiles.stories.tsx +++ b/src/stories/dataset/dataset-files/DatasetFiles.stories.tsx @@ -8,11 +8,16 @@ import { WithSettings } from '../../WithSettings' import { FileMockNoFiltersRepository } from '../../file/FileMockNoFiltersRepository' import { DatasetMother } from '../../../../tests/component/dataset/domain/models/DatasetMother' import { DatasetMockRepository } from '../../dataset/DatasetMockRepository' +import { WithRepositories } from '../../WithRepositories' const meta: Meta = { title: 'Sections/Dataset Page/DatasetFiles', component: DatasetFiles, - decorators: [WithI18next, WithSettings] + decorators: [ + WithI18next, + WithSettings, + WithRepositories({ datasetRepository: new DatasetMockRepository() }) + ] } export default meta @@ -24,7 +29,6 @@ export const Default: Story = { render: () => ( @@ -35,7 +39,6 @@ export const Loading: Story = { render: () => ( @@ -46,7 +49,6 @@ export const NoFiles: Story = { render: () => ( @@ -57,7 +59,6 @@ export const NoFilters: Story = { render: () => ( diff --git a/src/stories/dataset/dataset-files/DatasetFilesScrollable.stories.tsx b/src/stories/dataset/dataset-files/DatasetFilesScrollable.stories.tsx index 1b5a02b93..564277756 100644 --- a/src/stories/dataset/dataset-files/DatasetFilesScrollable.stories.tsx +++ b/src/stories/dataset/dataset-files/DatasetFilesScrollable.stories.tsx @@ -8,11 +8,16 @@ import { WithSettings } from '../../WithSettings' import { FileMockNoFiltersRepository } from '../../file/FileMockNoFiltersRepository' import { DatasetMother } from '../../../../tests/component/dataset/domain/models/DatasetMother' import { DatasetMockRepository } from '../../dataset/DatasetMockRepository' +import { WithRepositories } from '../../WithRepositories' const meta: Meta = { title: 'Sections/Dataset Page/DatasetFilesScrollable', component: DatasetFilesScrollable, - decorators: [WithI18next, WithSettings], + decorators: [ + WithI18next, + WithSettings, + WithRepositories({ datasetRepository: new DatasetMockRepository() }) + ], parameters: { // Sets the delay for all stories. chromatic: { delay: 15000, pauseAnimationAtEnd: true } @@ -28,7 +33,6 @@ export const Default: Story = { render: () => ( @@ -39,7 +43,6 @@ export const Loading: Story = { render: () => ( @@ -50,7 +53,6 @@ export const NoFiles: Story = { render: () => ( @@ -61,7 +63,6 @@ export const NoFilters: Story = { render: () => ( diff --git a/src/stories/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesMenu.stories.tsx b/src/stories/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesMenu.stories.tsx index e5131401d..27d8ad7e6 100644 --- a/src/stories/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesMenu.stories.tsx +++ b/src/stories/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesMenu.stories.tsx @@ -7,11 +7,18 @@ import { WithDatasetAllPermissionsGranted } from '../../../../WithDatasetAllPerm import { FilePreviewMother } from '../../../../../../../tests/component/files/domain/models/FilePreviewMother' import { FileMockRepository } from '@/stories/file/FileMockRepository' import { DatasetMockRepository } from '@/stories/dataset/DatasetMockRepository' +import { WithRepositories } from '@/stories/WithRepositories' const meta: Meta = { title: 'Sections/Dataset Page/DatasetFiles/FilesTable/EditFilesMenu', component: EditFilesMenu, - decorators: [WithI18next, WithSettings, WithLoggedInUser, WithDatasetAllPermissionsGranted] + decorators: [ + WithI18next, + WithSettings, + WithLoggedInUser, + WithDatasetAllPermissionsGranted, + WithRepositories({ datasetRepository: new DatasetMockRepository() }) + ] } export default meta @@ -23,7 +30,6 @@ export const Default: Story = { files={FilePreviewMother.createMany(2)} fileSelection={{}} fileRepository={new FileMockRepository()} - datasetRepository={new DatasetMockRepository()} /> ) } diff --git a/src/stories/dataset/dataset-files/files-table/file-actions/file-action-buttons/file-options-menu/FileOptionsMenu.stories.tsx b/src/stories/dataset/dataset-files/files-table/file-actions/file-action-buttons/file-options-menu/FileOptionsMenu.stories.tsx index f3afe49b2..723ccef8b 100644 --- a/src/stories/dataset/dataset-files/files-table/file-actions/file-action-buttons/file-options-menu/FileOptionsMenu.stories.tsx +++ b/src/stories/dataset/dataset-files/files-table/file-actions/file-action-buttons/file-options-menu/FileOptionsMenu.stories.tsx @@ -12,12 +12,18 @@ import { ExternalToolsProvider } from '@/shared/contexts/external-tools/External import { ExternalToolsMockRepository } from '@/stories/shared-mock-repositories/externalTools/ExternalToolsMockRepository' import { FakerHelper } from '@tests/component/shared/FakerHelper' import { ExternalToolsMother } from '@tests/component/externalTools/domain/models/ExternalToolsMother' +import { WithRepositories } from '@/stories/WithRepositories' const meta: Meta = { title: 'Sections/Dataset Page/DatasetFiles/FilesTable/FileActionsCell/FileActionButtons/FileOptionsMenu', component: FileOptionsMenu, - decorators: [WithI18next, WithSettings, WithLoggedInUser] + decorators: [ + WithI18next, + WithSettings, + WithLoggedInUser, + WithRepositories({ datasetRepository: new DatasetMockRepository() }) + ] } export default meta @@ -29,7 +35,6 @@ export const DefaultWithLoggedInUser: Story = { ) } @@ -40,7 +45,6 @@ export const Restricted: Story = { ) } @@ -51,7 +55,6 @@ export const WithDatasetLocked: Story = { ) } @@ -62,7 +65,6 @@ export const WithFileAlreadyDeleted: Story = { ) } @@ -83,7 +85,6 @@ export const WithConfigureTool: Story = { ) diff --git a/src/stories/dataset/dataset-metrics/DatasetMetrics.stories.tsx b/src/stories/dataset/dataset-metrics/DatasetMetrics.stories.tsx index 10e77905a..95daccf04 100644 --- a/src/stories/dataset/dataset-metrics/DatasetMetrics.stories.tsx +++ b/src/stories/dataset/dataset-metrics/DatasetMetrics.stories.tsx @@ -4,6 +4,7 @@ import { Meta, StoryObj } from '@storybook/react' import { DatasetMockRepository } from '../DatasetMockRepository' import { FakerHelper } from '@tests/component/shared/FakerHelper' import { DatasetDownloadCountMother } from '@tests/component/dataset/domain/models/DatasetDownloadCountMother' +import { RepositoriesStoryProvider } from '@/stories/WithRepositories' const meta: Meta = { title: 'Sections/Dataset Page/DatasetMetrics', @@ -25,12 +26,18 @@ datasetMockRepoWithoutMakeDataCount.getDownloadCount = () => { export const WithoutMakeDataCountEnabled: Story = { render: () => ( - + + + ) } export const WithMakeDataCountEnabled: Story = { - render: () => + render: () => ( + + + + ) } export const WithBigNumbersMDCEnabled: Story = { @@ -60,6 +67,10 @@ export const WithBigNumbersMDCEnabled: Story = { }) } - return + return ( + + + + ) } } diff --git a/src/stories/dataset/dataset-versions/DatasetVersions.stories.tsx b/src/stories/dataset/dataset-versions/DatasetVersions.stories.tsx index bd6f67a23..b8e9f26ad 100644 --- a/src/stories/dataset/dataset-versions/DatasetVersions.stories.tsx +++ b/src/stories/dataset/dataset-versions/DatasetVersions.stories.tsx @@ -5,11 +5,12 @@ import { DatasetVersionsLoadingSkeleton } from '../../../sections/dataset/dataset-versions/DatasetVersions' import { DatasetMockRepository } from '../../dataset/DatasetMockRepository' +import { WithRepositories } from '../../WithRepositories' const meta: Meta = { title: 'Sections/Dataset Page/DatasetVersions', component: DatasetVersions, - decorators: [WithI18next] + decorators: [WithI18next, WithRepositories({ datasetRepository: new DatasetMockRepository() })] } export default meta @@ -18,7 +19,6 @@ type Story = StoryObj export const Default: Story = { render: () => ( = { title: 'Sections/Dataset Page/Deaccession Dataset/DeaccessionDatasetModal', @@ -20,12 +21,13 @@ export const Default: Story = { decorators: [WithLoggedInUser], render: () => { return ( - {}} - /> + + {}} + /> + ) } } @@ -54,12 +56,13 @@ export const WithOneVersion: Story = { } return ( - {}} - /> + + {}} + /> + ) } } @@ -67,11 +70,12 @@ export const WithOneVersion: Story = { export const LoadingDatasetVersionSummaries: Story = { decorators: [WithLoggedInUser], render: () => ( - {}} - /> + + {}} + /> + ) } diff --git a/src/stories/edit-dataset-metadata/EditDatasetMetadata.stories.tsx b/src/stories/edit-dataset-metadata/EditDatasetMetadata.stories.tsx index e2917c1d9..5c3d5118d 100644 --- a/src/stories/edit-dataset-metadata/EditDatasetMetadata.stories.tsx +++ b/src/stories/edit-dataset-metadata/EditDatasetMetadata.stories.tsx @@ -7,11 +7,18 @@ import { MetadataBlockInfoMockLoadingRepository } from '../shared-mock-repositor import { WithLoggedInUser } from '../WithLoggedInUser' import { EditDatasetMetadata } from '../../sections/edit-dataset-metadata/EditDatasetMetadata' import { WithDataset } from '../dataset/WithDataset' +import { WithRepositories } from '../WithRepositories' const meta: Meta = { title: 'Pages/Edit Dataset Metadata', component: EditDatasetMetadata, - decorators: [WithI18next, WithLayout, WithDataset, WithLoggedInUser], + decorators: [ + WithI18next, + WithLayout, + WithDataset, + WithLoggedInUser, + WithRepositories({ datasetRepository: new DatasetMockRepository() }) + ], parameters: { // Sets the delay for all stories. chromatic: { delay: 15000, pauseAnimationAtEnd: true } @@ -22,17 +29,13 @@ type Story = StoryObj export const Default: Story = { render: () => ( - + ) } export const Loading: Story = { render: () => ( ) diff --git a/src/stories/edit-dataset-terms/EditDatasetTerms.stories.tsx b/src/stories/edit-dataset-terms/EditDatasetTerms.stories.tsx index 32bea984b..04ae10a96 100644 --- a/src/stories/edit-dataset-terms/EditDatasetTerms.stories.tsx +++ b/src/stories/edit-dataset-terms/EditDatasetTerms.stories.tsx @@ -10,11 +10,17 @@ import { DatasetMockRepository } from '../dataset/DatasetMockRepository' import { LicenseRepository } from '@/licenses/domain/repositories/LicenseRepository' import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' import { GuestbookRepository } from '@/guestbooks/domain/repositories/GuestbookRepository' +import { WithRepositories } from '../WithRepositories' + +const licenseRepository: LicenseRepository = new LicenseMockRepository() as LicenseRepository +const datasetRepository: DatasetRepository = new DatasetMockRepository() as DatasetRepository +const guestbookRepository: GuestbookRepository = + new GuestbookMockRepository() as GuestbookRepository const meta: Meta = { title: 'Pages/EditDatasetTerms', component: EditDatasetTerms, - decorators: [WithI18next, WithLayout, WithDataset], + decorators: [WithI18next, WithLayout, WithDataset, WithRepositories({ datasetRepository })], parameters: { chromatic: { delay: 15000, pauseAnimationAtEnd: true } } @@ -23,17 +29,11 @@ const meta: Meta = { export default meta type Story = StoryObj -const licenseRepository: LicenseRepository = new LicenseMockRepository() as LicenseRepository -const datasetRepository: DatasetRepository = new DatasetMockRepository() as DatasetRepository -const guestbookRepository: GuestbookRepository = - new GuestbookMockRepository() as GuestbookRepository - export const EditLicenseAndTermsTab: Story = { render: () => ( ) @@ -44,7 +44,6 @@ export const EditTermsOfAccessTab: Story = { ) @@ -55,7 +54,6 @@ export const EditGuestbookTab: Story = { ) diff --git a/src/stories/file/File.stories.tsx b/src/stories/file/File.stories.tsx index b81d0dd1a..1d3b0eda0 100644 --- a/src/stories/file/File.stories.tsx +++ b/src/stories/file/File.stories.tsx @@ -13,11 +13,16 @@ import { FakerHelper } from '@tests/component/shared/FakerHelper' import { ExternalToolsMother } from '@tests/component/externalTools/domain/models/ExternalToolsMother' import { DataverseInfoMockRepository } from '../shared-mock-repositories/info/DataverseInfoMockRepository' import { ContactMockRepository } from '../shared-mock-repositories/contact/ContactMockRepository' +import { WithRepositories } from '../WithRepositories' const meta: Meta = { title: 'Pages/File', component: File, - decorators: [WithI18next, WithLayout], + decorators: [ + WithI18next, + WithLayout, + WithRepositories({ datasetRepository: new DatasetMockRepository() }) + ], parameters: { // Sets the delay for all stories. chromatic: { delay: 15000, pauseAnimationAtEnd: true } @@ -31,7 +36,6 @@ export const Default: Story = { render: () => ( ( ( ( ( = { title: 'Sections/File Page/Action Buttons/EditFileMenu', component: EditFileMenu, - decorators: [WithI18next, WithSettings] + decorators: [ + WithI18next, + WithSettings, + WithRepositories({ datasetRepository: new DatasetMockRepository() }) + ] } export default meta @@ -26,7 +31,6 @@ export const Default: Story = { = { title: 'Sections/File Page/Action Buttons/EditFileMenu/EditFileTagsModal', component: EditFileTagsModal, - decorators: [WithI18next, WithSettings] + decorators: [ + WithI18next, + WithSettings, + WithRepositories({ datasetRepository: new DatasetMockRepository() }) + ] } export default meta @@ -18,7 +23,6 @@ export const WithExistingLabels: Story = { {}} handleUpdateCategories={() => Promise.resolve()} @@ -37,7 +41,6 @@ export const WithLoading: Story = { {}} handleUpdateCategories={() => Promise.resolve()} @@ -56,7 +59,6 @@ export const WithError: Story = { {}} handleUpdateCategories={() => Promise.resolve()} @@ -75,7 +77,6 @@ export const NonTabularFile: Story = { {}} handleUpdateCategories={() => Promise.resolve()} diff --git a/src/stories/replace-file/ReplaceFile.stories.tsx b/src/stories/replace-file/ReplaceFile.stories.tsx index 63c2f586c..3e81775e1 100644 --- a/src/stories/replace-file/ReplaceFile.stories.tsx +++ b/src/stories/replace-file/ReplaceFile.stories.tsx @@ -6,6 +6,7 @@ import { WithDataset } from '../dataset/WithDataset' import { ReplaceFile } from '@/sections/replace-file/ReplaceFile' import { DatasetMockRepository } from '@/stories/dataset/DatasetMockRepository' import { WithToasts } from '../WithToasts' +import { RepositoriesStoryProvider } from '@/stories/WithRepositories' const meta: Meta = { title: 'Pages/Replace File', @@ -23,12 +24,13 @@ type Story = StoryObj export const Default: Story = { decorators: [WithLayout, WithDataset, WithToasts], render: () => ( - + + + ) } diff --git a/src/stories/shared/dataset-metadata-form/DatasetMetadataForm.stories.tsx b/src/stories/shared/dataset-metadata-form/DatasetMetadataForm.stories.tsx index efd1242e7..803d3ed5b 100644 --- a/src/stories/shared/dataset-metadata-form/DatasetMetadataForm.stories.tsx +++ b/src/stories/shared/dataset-metadata-form/DatasetMetadataForm.stories.tsx @@ -5,11 +5,16 @@ import { WithLoggedInUser } from '../../WithLoggedInUser' import { DatasetMockRepository } from '../../dataset/DatasetMockRepository' import { MetadataBlockInfoMockRepository } from '../../shared-mock-repositories/metadata-block-info/MetadataBlockInfoMockRepository' import { DatasetMother } from '../../../../tests/component/dataset/domain/models/DatasetMother' +import { WithRepositories } from '../../WithRepositories' const meta: Meta = { title: 'Sections/Shared/Dataset Metadata Form', component: DatasetMetadataForm, - decorators: [WithI18next, WithLoggedInUser], + decorators: [ + WithI18next, + WithLoggedInUser, + WithRepositories({ datasetRepository: new DatasetMockRepository() }) + ], parameters: { // Sets the delay for all stories. chromatic: { delay: 15000, pauseAnimationAtEnd: true } @@ -23,7 +28,6 @@ export const CreateMode: Story = { ) @@ -36,7 +40,6 @@ export const EditMode: Story = { = { title: 'Sections/Shared/File Uploader/File Upload Input', component: FileUploadInput, - decorators: [WithI18next], + decorators: [WithI18next, WithRepositories({ datasetRepository: new DatasetMockRepository() })], parameters: { // Sets the delay for all stories. chromatic: { delay: 15000, pauseAnimationAtEnd: true } @@ -28,7 +29,6 @@ export const ReplaceMode: Story = { ) @@ -41,7 +41,6 @@ export const AddMode: Story = { ) @@ -54,7 +53,6 @@ export const WithUploadLimits: Story = { Promise.resolve({ numberOfFilesRemaining: 5, storageQuotaRemaining: 1024 * 1024 * 1024 }) } @@ -102,7 +100,6 @@ export const WithUploadingFiles: Story = { ) @@ -131,7 +128,6 @@ export const WithFailedFile: Story = { ) diff --git a/src/stories/shared/file-uploader/FileUploader.stories.tsx b/src/stories/shared/file-uploader/FileUploader.stories.tsx index 4646eedeb..9e1836dcb 100644 --- a/src/stories/shared/file-uploader/FileUploader.stories.tsx +++ b/src/stories/shared/file-uploader/FileUploader.stories.tsx @@ -5,11 +5,12 @@ import { WithI18next } from '@/stories/WithI18next' import { WithToasts } from '@/stories/WithToasts' import { Meta, StoryObj } from '@storybook/react' import { FileMother } from '@tests/component/files/domain/models/FileMother' +import { WithRepositories } from '@/stories/WithRepositories' const meta: Meta = { title: 'Sections/Shared/File Uploader', component: FileUploader, - decorators: [WithI18next], + decorators: [WithI18next, WithRepositories({ datasetRepository: new DatasetMockRepository() })], parameters: { // Sets the delay for all stories. chromatic: { delay: 15000, pauseAnimationAtEnd: true } @@ -28,7 +29,6 @@ export const ReplaceMode: Story = { storageType="S3" operationType={OperationType.REPLACE_FILE} originalFile={FileMother.createRealistic()} - datasetRepository={new DatasetMockRepository()} /> ) } @@ -41,7 +41,6 @@ export const AddFilesToDataset: Story = { datasetPersistentId="doi:10.5072/FK2/8YOKQI" storageType="S3" operationType={OperationType.ADD_FILES_TO_DATASET} - datasetRepository={new DatasetMockRepository()} /> ) } diff --git a/src/stories/upload-dataset-files/UploadDatasetFiles.stories.tsx b/src/stories/upload-dataset-files/UploadDatasetFiles.stories.tsx index 8d3bf35d1..cd6fdcfa7 100644 --- a/src/stories/upload-dataset-files/UploadDatasetFiles.stories.tsx +++ b/src/stories/upload-dataset-files/UploadDatasetFiles.stories.tsx @@ -5,11 +5,12 @@ import { UploadDatasetFiles } from '../../sections/upload-dataset-files/UploadDa import { FileMockRepository } from '../file/FileMockRepository' import { DatasetMockRepository } from '../dataset/DatasetMockRepository' import { WithDataset } from '../dataset/WithDataset' +import { WithRepositories } from '../WithRepositories' const meta: Meta = { title: 'Pages/Upload Dataset Files', component: UploadDatasetFiles, - decorators: [WithI18next], + decorators: [WithI18next, WithRepositories({ datasetRepository: new DatasetMockRepository() })], parameters: { // Sets the delay for all stories. chromatic: { delay: 15000, pauseAnimationAtEnd: true } @@ -21,10 +22,5 @@ type Story = StoryObj export const Default: Story = { decorators: [WithLayout, WithDataset], - render: () => ( - - ) + render: () => } diff --git a/tests/component/WithRepositories.tsx b/tests/component/WithRepositories.tsx index e6d1b298d..aff66186a 100644 --- a/tests/component/WithRepositories.tsx +++ b/tests/component/WithRepositories.tsx @@ -1,15 +1,23 @@ import { ReactNode } from 'react' import { CollectionRepository } from '@/collection/domain/repositories/CollectionRepository' +import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' import { RepositoriesProvider } from '@/shared/contexts/repositories/RepositoriesProvider' interface WithRepositoriesProps { children: ReactNode - collectionRepository: CollectionRepository + collectionRepository?: CollectionRepository + datasetRepository?: DatasetRepository } -export function WithRepositories({ children, collectionRepository }: WithRepositoriesProps) { +export function WithRepositories({ + children, + collectionRepository = {} as CollectionRepository, + datasetRepository = {} as DatasetRepository +}: WithRepositoriesProps) { return ( - + {children} ) diff --git a/tests/component/sections/create-dataset/CreateDataset.spec.tsx b/tests/component/sections/create-dataset/CreateDataset.spec.tsx index ed25cda62..e06297350 100644 --- a/tests/component/sections/create-dataset/CreateDataset.spec.tsx +++ b/tests/component/sections/create-dataset/CreateDataset.spec.tsx @@ -27,7 +27,11 @@ const collection = CollectionMother.create({ name: COLLECTION_NAME, id: 'test-al const mountCreateDataset = (component: JSX.Element): void => { cy.customMount( - {component} + + {component} + ) } @@ -49,7 +53,6 @@ describe('Create Dataset', () => { collectionRepository.getById = cy.stub().resolves(null) mountCreateDataset( { mountCreateDataset( { it('should render the correct breadcrumbs', () => { mountCreateDataset( { mountCreateDataset( { mountCreateDataset( { it('should not show alert error message when user is allowed to create a dataset within the collection', () => { mountCreateDataset( { it('should not show template select when there are no templates', () => { mountCreateDataset( { mountCreateDataset( { mountCreateDataset( { mountCreateDataset( { cy.customMount( - + @@ -325,7 +327,6 @@ describe('Dataset', () => { it('renders skeleton while loading', () => { mountWithDataset( { mountWithDataset( { mountWithDataset( { it('renders the breadcrumbs', () => { mountWithDataset( { it('renders the Dataset page title and labels', () => { mountWithDataset( { it('renders the Dataset Metadata tab', () => { mountWithDataset( { it('renders the Dataset Terms tab', () => { mountWithDataset( { mountWithDataset( { it('renders the Dataset Files tab', () => { mountWithDataset( { mountWithDataset( { mountWithDataset( { mountWithDataset( { mountWithDataset( { it('renders the Dataset Action Buttons', () => { mountWithDataset( { it('renders the Dataset Files list table with infinite scrolling enabled', () => { mountWithDataset( { it('shows the toast when the information was sent to contact successfully', () => { mountWithDataset( { it('does not show the tooltip for contact owner button', () => { mountWithDataset( { mountWithDataset( { }) cy.mountAuthenticated( - - + + ) @@ -58,12 +56,10 @@ describe('DatasetActionButtons', () => { }) cy.mountAuthenticated( - - + + ) @@ -81,12 +77,10 @@ describe('DatasetActionButtons', () => { version: DatasetVersionMother.createDeaccessioned() }) cy.mountAuthenticated( - - + + ) diff --git a/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeaccessionDatasetButton.spec.tsx b/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeaccessionDatasetButton.spec.tsx index 72bb9f1a7..57e31d440 100644 --- a/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeaccessionDatasetButton.spec.tsx +++ b/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeaccessionDatasetButton.spec.tsx @@ -7,6 +7,7 @@ import { DeaccessionDatasetButton } from '../../../../../../src/sections/dataset import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' import { DatasetVersionSummaryInfoMother } from '@tests/component/dataset/domain/models/DatasetVersionSummaryInfoMother' import { DatasetVersionSummaryInfo } from '@/dataset/domain/models/DatasetVersionSummaryInfo' +import { WithRepositories } from '@tests/component/WithRepositories' describe('DeaccessionDatasetButton', () => { const repository: DatasetRepository = {} as DatasetRepository @@ -45,7 +46,11 @@ describe('DeaccessionDatasetButton', () => { version: DatasetVersionMother.createReleased() }) - cy.customMount() + cy.customMount( + + + + ) cy.findByRole('separator').should('exist') cy.findByRole('button', { name: 'Deaccession Dataset' }).should('exist') @@ -57,7 +62,11 @@ describe('DeaccessionDatasetButton', () => { version: DatasetVersionMother.createReleased() }) - cy.customMount() + cy.customMount( + + + + ) cy.findByRole('button', { name: 'Deaccession Dataset' }).should('not.exist') }) @@ -68,7 +77,11 @@ describe('DeaccessionDatasetButton', () => { version: DatasetVersionMother.createNotReleased() }) - cy.customMount() + cy.customMount( + + + + ) cy.findByRole('button', { name: 'Deaccession Dataset' }).should('not.exist') }) @@ -79,7 +92,11 @@ describe('DeaccessionDatasetButton', () => { version: DatasetVersionMother.createNotReleased() }) - cy.customMount() + cy.customMount( + + + + ) cy.findByRole('separator').should('not.exist') cy.findByRole('button', { name: 'Deaccession Dataset' }).should('not.exist') @@ -92,7 +109,11 @@ describe('DeaccessionDatasetButton', () => { version: DatasetVersionMother.createReleased() }) - cy.customMount() + cy.customMount( + + + + ) cy.findByRole('button', { name: 'Deaccession Dataset' }).should('exist') cy.findByRole('button', { name: 'Deaccession Dataset' }).click() @@ -112,9 +133,11 @@ describe('DeaccessionDatasetButton', () => { const parentClick = cy.stub().as('parentClick') cy.customMount( -
- -
+ +
+ +
+
) cy.findByRole('button', { name: 'Deaccession Dataset' }).click() @@ -128,7 +151,11 @@ describe('DeaccessionDatasetButton', () => { version: DatasetVersionMother.createReleased() }) - cy.customMount() + cy.customMount( + + + + ) cy.findByRole('button', { name: 'Deaccession Dataset' }).click() cy.findByRole('dialog').should('exist') @@ -142,7 +169,11 @@ describe('DeaccessionDatasetButton', () => { version: DatasetVersionMother.createReleased() }) - cy.customMount() + cy.customMount( + + + + ) cy.findByRole('button', { name: 'Deaccession Dataset' }).click() cy.get('select').select('IRB request.') @@ -175,7 +206,11 @@ describe('DeaccessionDatasetButton', () => { version: DatasetVersionMother.createReleased() }) - cy.customMount() + cy.customMount( + + + + ) cy.findByRole('button', { name: 'Deaccession Dataset' }).click() cy.get('form').should('exist') @@ -215,7 +250,11 @@ describe('DeaccessionDatasetButton', () => { version: DatasetVersionMother.createReleased() }) - cy.customMount() + cy.customMount( + + + + ) cy.findByRole('button', { name: 'Deaccession Dataset' }).click() cy.get('form').should('exist') @@ -230,7 +269,11 @@ describe('DeaccessionDatasetButton', () => { version: DatasetVersionMother.createReleased() }) - cy.customMount() + cy.customMount( + + + + ) cy.findByRole('button', { name: 'Deaccession Dataset' }).click() cy.get('form').should('exist') @@ -250,7 +293,11 @@ describe('DeaccessionDatasetButton', () => { version: DatasetVersionMother.createReleased() }) - cy.customMount() + cy.customMount( + + + + ) cy.findByRole('button', { name: 'Deaccession Dataset' }).click() cy.get('input[type="checkbox"]').first().check() @@ -278,7 +325,11 @@ describe('DeaccessionDatasetButton', () => { version: DatasetVersionMother.createReleased() }) - cy.customMount() + cy.customMount( + + + + ) cy.findByRole('button', { name: 'Deaccession Dataset' }).click() cy.get('input[type="checkbox"]').first().check() @@ -311,7 +362,11 @@ describe('DeaccessionDatasetButton', () => { version: DatasetVersionMother.createReleased() }) - cy.customMount() + cy.customMount( + + + + ) cy.findByRole('button', { name: 'Deaccession Dataset' }).click() cy.get('input[type="checkbox"]').first().check() @@ -361,7 +416,11 @@ describe('DeaccessionDatasetButton', () => { version: DatasetVersionMother.createReleased() }) - cy.customMount() + cy.customMount( + + + + ) cy.findByRole('button', { name: 'Deaccession Dataset' }).click() cy.get('form').should('exist') @@ -403,7 +462,11 @@ describe('DeaccessionDatasetButton', () => { version: DatasetVersionMother.createReleased() }) - cy.customMount() + cy.customMount( + + + + ) cy.findByRole('button', { name: 'Deaccession Dataset' }).click() cy.get('form').should('exist') diff --git a/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeleteDraftDatasetButton.spec.tsx b/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeleteDraftDatasetButton.spec.tsx index c93af4efa..416f75f02 100644 --- a/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeleteDraftDatasetButton.spec.tsx +++ b/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeleteDraftDatasetButton.spec.tsx @@ -6,6 +6,7 @@ import { DatasetVersionMother } from '../../../../dataset/domain/models/DatasetMother' import { WriteError } from '@iqss/dataverse-client-javascript' +import { WithRepositories } from '@tests/component/WithRepositories' describe('DeleteDraftDatasetButton', () => { const repository: DatasetRepository = {} as DatasetRepository @@ -17,7 +18,11 @@ describe('DeleteDraftDatasetButton', () => { version: DatasetVersionMother.createReleasedWithLatestVersionIsADraft() }) - cy.customMount() + cy.customMount( + + + + ) cy.findByRole('separator').should('exist') cy.findByRole('button', { name: /Delete/ }).should('exist') @@ -30,7 +35,11 @@ describe('DeleteDraftDatasetButton', () => { version: DatasetVersionMother.createNotReleased() }) - cy.customMount() + cy.customMount( + + + + ) cy.findByRole('button', { name: 'Delete Dataset' }).should('exist') }) @@ -42,7 +51,11 @@ describe('DeleteDraftDatasetButton', () => { version: DatasetVersionMother.createReleasedWithLatestVersionIsADraft() }) - cy.customMount() + cy.customMount( + + + + ) cy.findByRole('button', { name: 'Delete Draft Version' }).should('exist') }) @@ -54,7 +67,11 @@ describe('DeleteDraftDatasetButton', () => { version: DatasetVersionMother.createReleasedWithLatestVersionIsADraft() }) - cy.customMount() + cy.customMount( + + + + ) cy.findByRole('button', { name: /Delete/ }).should('not.exist') }) @@ -66,7 +83,11 @@ describe('DeleteDraftDatasetButton', () => { version: DatasetVersionMother.createDraftWithLatestVersionIsReleased() }) - cy.customMount() + cy.customMount( + + + + ) cy.findByRole('button', { name: /Delete/ }).should('not.exist') }) @@ -78,7 +99,11 @@ describe('DeleteDraftDatasetButton', () => { version: DatasetVersionMother.createNotReleased() }) - cy.customMount() + cy.customMount( + + + + ) cy.findByRole('button', { name: 'Delete Dataset' }).click() @@ -93,7 +118,11 @@ describe('DeleteDraftDatasetButton', () => { version: DatasetVersionMother.createNotReleased() }) - cy.customMount() + cy.customMount( + + + + ) cy.findByRole('button', { name: 'Delete Dataset' }).click() cy.findByRole('button', { name: /Cancel/i }).click() @@ -104,14 +133,15 @@ describe('DeleteDraftDatasetButton', () => { it('should delete dataset if delete button clicked', () => { repository.deleteDatasetDraft = cy.stub().resolves() cy.customMount( - + + + ) cy.findByRole('button', { name: 'Delete Dataset' }).click() @@ -124,14 +154,15 @@ describe('DeleteDraftDatasetButton', () => { it('shows draft-specific messaging and toast when a released dataset draft is deleted', () => { repository.deleteDatasetDraft = cy.stub().resolves() cy.customMount( - + + + ) cy.findByRole('button', { name: 'Delete Draft Version' }).click() @@ -144,14 +175,15 @@ describe('DeleteDraftDatasetButton', () => { it('should not delete dataset if delete button clicked and repository fails', () => { repository.deleteDatasetDraft = cy.stub().rejects(new Error('Some unknown error')) cy.customMount( - + + + ) cy.findByRole('button', { name: 'Delete Dataset' }).click() @@ -165,14 +197,15 @@ describe('DeleteDraftDatasetButton', () => { repository.deleteDatasetDraft = cy.stub().rejects(err) cy.customMount( - + + + ) cy.findByRole('button', { name: 'Delete Dataset' }).click() @@ -187,14 +220,15 @@ describe('DeleteDraftDatasetButton', () => { .callsFake(() => new Promise((resolve) => setTimeout(resolve, 1000))) cy.customMount( - + + + ) cy.findByRole('button', { name: 'Delete Dataset' }).click() diff --git a/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetMenu.spec.tsx b/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetMenu.spec.tsx index 641a5f865..a4d864941 100644 --- a/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetMenu.spec.tsx +++ b/tests/component/sections/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetMenu.spec.tsx @@ -8,6 +8,7 @@ import { EditDatasetMenu } from '../../../../../../src/sections/dataset/dataset- import { DatasetMockRepository } from '@/stories/dataset/DatasetMockRepository' import { QueryParamKey } from '@/sections/Route.enum' import { DatasetNonNumericVersion } from '@/dataset/domain/models/Dataset' +import { WithRepositories } from '@tests/component/WithRepositories' describe('EditDatasetMenu', () => { it('renders the EditDatasetMenu if the user has update dataset permissions', () => { @@ -19,7 +20,9 @@ describe('EditDatasetMenu', () => { }) cy.mountAuthenticated( - + + + ) cy.findByRole('button', { name: 'Edit Dataset' }).should('exist').should('be.enabled').click() @@ -42,7 +45,9 @@ describe('EditDatasetMenu', () => { }) cy.customMount( - + + + ) cy.findByRole('button', { name: 'Edit Dataset' }).should('not.exist') @@ -55,7 +60,9 @@ describe('EditDatasetMenu', () => { }) cy.mountAuthenticated( - + + + ) cy.findByRole('button', { name: 'Edit Dataset' }).should('not.exist') @@ -68,7 +75,9 @@ describe('EditDatasetMenu', () => { }) cy.mountAuthenticated( - + + + ) cy.findByRole('button', { name: 'Edit Dataset' }).should('exist').should('be.disabled') @@ -82,7 +91,9 @@ describe('EditDatasetMenu', () => { }) cy.mountAuthenticated( - + + + ) cy.findByRole('button', { name: 'Edit Dataset' }).click() @@ -102,7 +113,9 @@ describe('EditDatasetMenu', () => { }) cy.mountAuthenticated( - + + + ) cy.findByRole('button', { name: 'Edit Dataset' }).click() @@ -120,7 +133,9 @@ describe('EditDatasetMenu', () => { }) cy.mountAuthenticated( - + + + ) cy.findByRole('button', { name: 'Edit Dataset' }).click() @@ -136,7 +151,9 @@ describe('EditDatasetMenu', () => { }) cy.mountAuthenticated( - + + + ) cy.findByRole('button', { name: 'Edit Dataset' }).click() @@ -151,7 +168,9 @@ describe('EditDatasetMenu', () => { }) cy.mountAuthenticated( - + + + ) cy.findByRole('button', { name: 'Edit Dataset' }).click() @@ -167,7 +186,9 @@ describe('EditDatasetMenu', () => { }) cy.mountAuthenticated( - + + + ) cy.findByRole('button', { name: 'Edit Dataset' }).click() @@ -184,7 +205,9 @@ describe('EditDatasetMenu', () => { }) cy.mountAuthenticated( - + + + ) cy.findByRole('button', { name: 'Edit Dataset' }).click() @@ -199,7 +222,9 @@ describe('EditDatasetMenu', () => { hasValidTermsOfAccess: true }) cy.mountAuthenticated( - + + + ) cy.findByRole('button', { name: 'Edit Dataset' }).click() cy.findByRole('button', { name: /Delete/ }).click() @@ -226,7 +251,9 @@ describe('EditDatasetMenu', () => { }) cy.mountAuthenticated( - + + + ) cy.findByRole('button', { name: 'Edit Dataset' }).click() @@ -242,7 +269,9 @@ describe('EditDatasetMenu', () => { }) cy.mountAuthenticated( - + + + ) cy.findByRole('button', { name: 'Edit Dataset' }).click() @@ -261,7 +290,9 @@ describe('EditDatasetMenu', () => { }) cy.mountAuthenticated( - + + + ) cy.findByRole('button', { name: 'Edit Dataset' }).click() diff --git a/tests/component/sections/dataset/dataset-action-buttons/link-dataset-button/LinkDatasetButton.spec.tsx b/tests/component/sections/dataset/dataset-action-buttons/link-dataset-button/LinkDatasetButton.spec.tsx index 6ab8d2309..ab542f20b 100644 --- a/tests/component/sections/dataset/dataset-action-buttons/link-dataset-button/LinkDatasetButton.spec.tsx +++ b/tests/component/sections/dataset/dataset-action-buttons/link-dataset-button/LinkDatasetButton.spec.tsx @@ -28,14 +28,20 @@ const mountAuthenticatedLinkDatasetButton = ( repository: CollectionRepository = collectionRepository ) => cy.mountAuthenticated( - {component} + + {component} + ) const mountUnauthenticatedLinkDatasetButton = ( component: JSX.Element, repository: CollectionRepository = collectionRepository ) => - cy.customMount({component}) + cy.customMount( + + {component} + + ) describe('LinkDatasetButton', () => { beforeEach(() => { @@ -54,11 +60,7 @@ describe('LinkDatasetButton', () => { it('renders the LinkDatasetButton if the user is authenticated and the dataset version is not deaccessioned and the dataset is released', () => { mountAuthenticatedLinkDatasetButton( - {}} - /> + {}} /> ) cy.findByRole('button', { name: 'Link Dataset' }).should('exist') @@ -66,11 +68,7 @@ describe('LinkDatasetButton', () => { it('does not render the LinkDatasetButton if the user is not authenticated', () => { mountUnauthenticatedLinkDatasetButton( - {}} - /> + {}} /> ) cy.findByRole('button', { name: 'Link Dataset' }).should('not.exist') @@ -82,11 +80,7 @@ describe('LinkDatasetButton', () => { }) mountAuthenticatedLinkDatasetButton( - {}} - /> + {}} /> ) cy.findByRole('button', { name: 'Link Dataset' }).should('not.exist') @@ -96,11 +90,7 @@ describe('LinkDatasetButton', () => { const updateParentSpy = cy.spy().as('updateParentSpy') mountAuthenticatedLinkDatasetButton( - + ) clickLinkDatasetButton() @@ -138,11 +128,7 @@ describe('LinkDatasetButton', () => { it('searchs for a collection to link', () => { mountAuthenticatedLinkDatasetButton( - {}} - />, + {}} />, new CollectionMockRepository() ) @@ -173,11 +159,7 @@ describe('LinkDatasetButton', () => { collectionRepository.getForLinking = cy.stub().resolves([]) mountAuthenticatedLinkDatasetButton( - {}} - /> + {}} /> ) clickLinkDatasetButton() @@ -203,11 +185,7 @@ describe('LinkDatasetButton', () => { ]) mountAuthenticatedLinkDatasetButton( - {}} - /> + {}} /> ) clickLinkDatasetButton() @@ -240,11 +218,7 @@ describe('LinkDatasetButton', () => { datasetRepository.link = cy.stub().as('linkDataset').rejects(new Error('Linking failed')) mountAuthenticatedLinkDatasetButton( - {}} - /> + {}} /> ) clickLinkDatasetButton() @@ -282,11 +256,7 @@ describe('LinkDatasetButton', () => { .rejects(new WriteError('A WriteError received')) mountAuthenticatedLinkDatasetButton( - {}} - /> + {}} /> ) clickLinkDatasetButton() @@ -321,11 +291,7 @@ describe('LinkDatasetButton', () => { collectionRepository.getForLinking = cy.stub().rejects(new Error('Fetching collections failed')) mountAuthenticatedLinkDatasetButton( - {}} - /> + {}} /> ) clickLinkDatasetButton() @@ -343,11 +309,7 @@ describe('LinkDatasetButton', () => { collectionRepository.getForLinking = cy.stub().rejects(new ReadError('A ReadError received')) mountAuthenticatedLinkDatasetButton( - {}} - /> + {}} /> ) clickLinkDatasetButton() @@ -373,11 +335,7 @@ describe('LinkDatasetButton', () => { .resolves(linked) mountAuthenticatedLinkDatasetButton( - {}} - /> + {}} /> ) clickLinkDatasetButton() 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 3e78aa8e2..d9238ce4e 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 @@ -22,14 +22,20 @@ const mountAuthenticatedPublishDatasetMenu = ( repository: CollectionRepository = collectionRepository ) => cy.mountAuthenticated( - {component} + + {component} + ) const mountUnauthenticatedPublishDatasetMenu = ( component: JSX.Element, repository: CollectionRepository = collectionRepository ) => - cy.customMount({component}) + cy.customMount( + + {component} + + ) describe('PublishDatasetMenu', () => { beforeEach(() => { dataverseInfoRepository = new DataverseInfoMockEmptyRepository() @@ -44,9 +50,7 @@ describe('PublishDatasetMenu', () => { isValid: true }) - mountAuthenticatedPublishDatasetMenu( - - ) + mountAuthenticatedPublishDatasetMenu() cy.findByRole('button', { name: 'Publish Dataset' }) .should('exist') @@ -71,7 +75,7 @@ describe('PublishDatasetMenu', () => { mountAuthenticatedPublishDatasetMenu( - + ) @@ -89,9 +93,7 @@ describe('PublishDatasetMenu', () => { isValid: true }) - mountUnauthenticatedPublishDatasetMenu( - - ) + mountUnauthenticatedPublishDatasetMenu() cy.findByRole('button', { name: 'Publish Dataset' }).should('not.exist') }) @@ -103,9 +105,7 @@ describe('PublishDatasetMenu', () => { locks: [] }) - mountAuthenticatedPublishDatasetMenu( - - ) + mountAuthenticatedPublishDatasetMenu() cy.findByRole('button', { name: 'Publish Dataset' }).should('not.exist') }) @@ -117,9 +117,7 @@ describe('PublishDatasetMenu', () => { locks: [] }) - mountAuthenticatedPublishDatasetMenu( - - ) + mountAuthenticatedPublishDatasetMenu() cy.findByRole('button', { name: 'Publish Dataset' }).should('not.exist') }) @@ -131,9 +129,7 @@ describe('PublishDatasetMenu', () => { locks: [] }) - mountAuthenticatedPublishDatasetMenu( - - ) + mountAuthenticatedPublishDatasetMenu() cy.findByRole('button', { name: 'Publish Dataset' }).should('not.exist') }) @@ -147,9 +143,7 @@ describe('PublishDatasetMenu', () => { isValid: true }) - mountAuthenticatedPublishDatasetMenu( - - ) + mountAuthenticatedPublishDatasetMenu() cy.findByRole('button', { name: 'Publish Dataset' }).should('be.enabled') }) @@ -163,9 +157,7 @@ describe('PublishDatasetMenu', () => { isValid: true }) - mountAuthenticatedPublishDatasetMenu( - - ) + mountAuthenticatedPublishDatasetMenu() cy.findByRole('button', { name: 'Publish Dataset' }).should('be.disabled') }) @@ -179,9 +171,7 @@ describe('PublishDatasetMenu', () => { isValid: true }) - mountAuthenticatedPublishDatasetMenu( - - ) + mountAuthenticatedPublishDatasetMenu() cy.findByRole('button', { name: 'Publish Dataset' }).should('be.disabled') }) @@ -195,9 +185,7 @@ describe('PublishDatasetMenu', () => { isValid: false }) - mountAuthenticatedPublishDatasetMenu( - - ) + mountAuthenticatedPublishDatasetMenu() cy.findByRole('button', { name: 'Publish Dataset' }).should('be.disabled') }) @@ -211,9 +199,7 @@ describe('PublishDatasetMenu', () => { isValid: true }) - mountAuthenticatedPublishDatasetMenu( - - ) + mountAuthenticatedPublishDatasetMenu() cy.findByRole('button', { name: 'Publish Dataset' }) .should('exist') @@ -232,9 +218,7 @@ describe('PublishDatasetMenu', () => { isValid: true }) - mountAuthenticatedPublishDatasetMenu( - - ) + mountAuthenticatedPublishDatasetMenu() cy.findByRole('button', { name: 'Publish Dataset' }).click() cy.findByRole('button', { name: 'Publish' }).click() @@ -250,9 +234,7 @@ describe('PublishDatasetMenu', () => { isValid: true }) - mountAuthenticatedPublishDatasetMenu( - - ) + mountAuthenticatedPublishDatasetMenu() cy.findByRole('button', { name: 'Publish Dataset' }).click() cy.findByRole('button', { name: 'Publish' }).click() diff --git a/tests/component/sections/dataset/dataset-action-buttons/unlink-dataset-button/UnlinkDatasetButton.spec.tsx b/tests/component/sections/dataset/dataset-action-buttons/unlink-dataset-button/UnlinkDatasetButton.spec.tsx index 72064730c..b85bd0046 100644 --- a/tests/component/sections/dataset/dataset-action-buttons/unlink-dataset-button/UnlinkDatasetButton.spec.tsx +++ b/tests/component/sections/dataset/dataset-action-buttons/unlink-dataset-button/UnlinkDatasetButton.spec.tsx @@ -28,14 +28,20 @@ const mountAuthenticatedUnlinkDatasetButton = ( repository: CollectionRepository = collectionRepository ) => cy.mountAuthenticated( - {component} + + {component} + ) const mountUnauthenticatedUnlinkDatasetButton = ( component: JSX.Element, repository: CollectionRepository = collectionRepository ) => - cy.customMount({component}) + cy.customMount( + + {component} + + ) describe('UnlinkDatasetButton', () => { beforeEach(() => { @@ -54,11 +60,7 @@ describe('UnlinkDatasetButton', () => { it('renders the UnlinkDatasetButton if the user is authenticated and the dataset version is not deaccessioned and the dataset is released', () => { mountAuthenticatedUnlinkDatasetButton( - {}} - /> + {}} /> ) cy.findByRole('button', { name: 'Unlink Dataset' }).should('exist') @@ -66,11 +68,7 @@ describe('UnlinkDatasetButton', () => { it('does not render the UnlinkDatasetButton if the user is not authenticated', () => { mountUnauthenticatedUnlinkDatasetButton( - {}} - /> + {}} /> ) cy.findByRole('button', { name: 'Unlink Dataset' }).should('not.exist') @@ -82,11 +80,7 @@ describe('UnlinkDatasetButton', () => { }) mountAuthenticatedUnlinkDatasetButton( - {}} - /> + {}} /> ) cy.findByRole('button', { name: 'Unlink Dataset' }).should('not.exist') @@ -99,11 +93,7 @@ describe('UnlinkDatasetButton', () => { .resolves([]) mountAuthenticatedUnlinkDatasetButton( - {}} - /> + {}} /> ) cy.findByRole('button', { name: 'Unlink Dataset' }).should('not.exist') @@ -116,11 +106,7 @@ describe('UnlinkDatasetButton', () => { const updateParentSpy = cy.spy().as('updateParentSpy') mountAuthenticatedUnlinkDatasetButton( - + ) clickUnlinkDatasetButton() @@ -158,11 +144,7 @@ describe('UnlinkDatasetButton', () => { it('searchs for a collection to link', () => { mountAuthenticatedUnlinkDatasetButton( - {}} - />, + {}} />, new CollectionMockRepository() ) @@ -193,11 +175,7 @@ describe('UnlinkDatasetButton', () => { collectionRepository.getForUnlinking = cy.stub().resolves([]) mountAuthenticatedUnlinkDatasetButton( - {}} - /> + {}} /> ) clickUnlinkDatasetButton() @@ -223,11 +201,7 @@ describe('UnlinkDatasetButton', () => { ]) mountAuthenticatedUnlinkDatasetButton( - {}} - /> + {}} /> ) clickUnlinkDatasetButton() @@ -260,11 +234,7 @@ describe('UnlinkDatasetButton', () => { datasetRepository.unlink = cy.stub().as('unlinkDataset').rejects(new Error('Unlinking failed')) mountAuthenticatedUnlinkDatasetButton( - {}} - /> + {}} /> ) clickUnlinkDatasetButton() @@ -302,11 +272,7 @@ describe('UnlinkDatasetButton', () => { .rejects(new WriteError('A WriteError received')) mountAuthenticatedUnlinkDatasetButton( - {}} - /> + {}} /> ) clickUnlinkDatasetButton() @@ -343,11 +309,7 @@ describe('UnlinkDatasetButton', () => { .rejects(new Error('Fetching collections failed')) mountAuthenticatedUnlinkDatasetButton( - {}} - /> + {}} /> ) clickUnlinkDatasetButton() @@ -365,11 +327,7 @@ describe('UnlinkDatasetButton', () => { collectionRepository.getForUnlinking = cy.stub().rejects(new ReadError('A ReadError received')) mountAuthenticatedUnlinkDatasetButton( - {}} - /> + {}} /> ) clickUnlinkDatasetButton() diff --git a/tests/component/sections/dataset/dataset-citation/DatasetCitation.spec.tsx b/tests/component/sections/dataset/dataset-citation/DatasetCitation.spec.tsx index 2227051e4..8b8fe13c4 100644 --- a/tests/component/sections/dataset/dataset-citation/DatasetCitation.spec.tsx +++ b/tests/component/sections/dataset/dataset-citation/DatasetCitation.spec.tsx @@ -1,13 +1,16 @@ import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' import { DatasetCitation } from '../../../../../src/sections/dataset/dataset-citation/DatasetCitation' import { DatasetVersionMother } from '../../../dataset/domain/models/DatasetMother' +import { WithRepositories } from '@tests/component/WithRepositories' const datasetRepository: DatasetRepository = {} as DatasetRepository describe('DatasetCitation', () => { it('renders the DatasetCitation fields of released Dataset', () => { const version = DatasetVersionMother.createRealistic() cy.customMount( - + + + ) cy.findByText('Data Citation Standards.').should('exist') @@ -27,7 +30,9 @@ describe('DatasetCitation', () => { it('shows the draft tooltip when version is draft', () => { const version = DatasetVersionMother.createDraft() cy.customMount( - + + + ) cy.findByRole('img', { name: 'tooltip icon' }).should('exist').trigger('mouseover') @@ -39,7 +44,9 @@ describe('DatasetCitation', () => { it('shows the deaccessioned tooltip when version is deaccessioned', () => { const version = DatasetVersionMother.createDeaccessioned() cy.customMount( - + + + ) cy.findByRole('img', { name: 'tooltip icon' }).should('exist').trigger('mouseover') @@ -51,7 +58,9 @@ describe('DatasetCitation', () => { it('shows the deaccessioned reason when version is deaccessioned', () => { const version = DatasetVersionMother.createDeaccessioned() cy.customMount( - + + + ) cy.findByText(/Deaccession Reason/).should('exist') @@ -60,12 +69,9 @@ describe('DatasetCitation', () => { it('does not render the thumbnail when withoutThumbnail prop is true', () => { const version = DatasetVersionMother.createRealistic() cy.customMount( - + + + ) cy.findByLabelText('icon-dataset').should('not.exist') @@ -74,7 +80,9 @@ describe('DatasetCitation', () => { it('renders the Cite Dataset button', () => { const version = DatasetVersionMother.createRealistic() cy.customMount( - + + + ) cy.findByRole('button', { name: 'Cite Dataset' }).should('exist') diff --git a/tests/component/sections/dataset/dataset-files/DatasetFiles.spec.tsx b/tests/component/sections/dataset/dataset-files/DatasetFiles.spec.tsx index 84b514cab..42e943b75 100644 --- a/tests/component/sections/dataset/dataset-files/DatasetFiles.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/DatasetFiles.spec.tsx @@ -23,6 +23,7 @@ import { FilePreviewMother } from '../../../files/domain/models/FilePreviewMothe import { FilePreview } from '../../../../../src/files/domain/models/FilePreview' import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' import { DataverseInfoMockEmptyRepository } from '@/stories/shared-mock-repositories/info/DataverseInfoMockEmptyRepository' +import { WithRepositories } from '@tests/component/WithRepositories' const testFiles: FilePreview[] = FilePreviewMother.createMany(10) const datasetPersistentId = 'test-dataset-persistent-id' @@ -71,12 +72,13 @@ describe('DatasetFiles', () => { it('renders the files table', () => { cy.customMount( - + + + ) cy.findByRole('table').should('exist') @@ -86,12 +88,13 @@ describe('DatasetFiles', () => { describe('Pagination navigation', () => { it('renders the files table with the correct header on a page different than the first one ', () => { cy.customMount( - + + + ) cy.findByRole('button', { name: '6' }).click() @@ -101,12 +104,13 @@ describe('DatasetFiles', () => { it('renders the files table with the correct page selected after updating the pageSize', () => { cy.customMount( - + + + ) cy.findByRole('button', { name: '3' }).click() @@ -120,12 +124,13 @@ describe('DatasetFiles', () => { it('renders the files table with the correct header with a different page size ', () => { cy.customMount( - + + + ) cy.findByLabelText('Files per page').select('50') @@ -143,12 +148,13 @@ describe('DatasetFiles', () => { fileRepository.getFilesTotalDownloadSizeByDatasetPersistentId = cy.stub().resolves(19900) cy.customMount( - + + + ) cy.findByRole('button', { name: '1' }).should('not.exist') @@ -178,12 +184,13 @@ describe('DatasetFiles', () => { fileRepository.getFilesTotalDownloadSizeByDatasetPersistentId = cy.stub().resolves(19900) cy.customMount( - + + + ) cy.findByRole('button', { name: '1' }).should('not.exist') @@ -210,12 +217,13 @@ describe('DatasetFiles', () => { it('maintains the selection when the page changes', () => { cy.customMount( - + + + ) cy.findByRole('columnheader', { name: '1 to 10 of 200 Files' }).should('exist') @@ -244,12 +252,13 @@ describe('DatasetFiles', () => { it('maintains the selection when the page size changes', () => { cy.customMount( - + + + ) cy.findByRole('columnheader', { name: '1 to 10 of 200 Files' }).should('exist') @@ -269,12 +278,13 @@ describe('DatasetFiles', () => { it('removes the selection when the filters change', () => { cy.customMount( - + + + ) cy.findByRole('columnheader', { name: '1 to 10 of 200 Files' }).should('exist') @@ -290,12 +300,13 @@ describe('DatasetFiles', () => { it('removes the selection when the Sort by changes', () => { cy.customMount( - + + + ) cy.findByRole('columnheader', { name: '1 to 10 of 200 Files' }).should('exist') @@ -311,12 +322,13 @@ describe('DatasetFiles', () => { it('removes the selection when the Search bar is used', () => { cy.customMount( - + + + ) cy.findByRole('columnheader', { name: '1 to 10 of 200 Files' }).should('exist') @@ -341,14 +353,15 @@ describe('DatasetFiles', () => { }) cy.customMount( - - - + + + + + ) cy.get('table > tbody > tr:nth-child(2) > td:nth-child(1) > input[type=checkbox]').click() @@ -368,14 +381,15 @@ describe('DatasetFiles', () => { it('renders the zip download limit message when selecting all rows', () => { cy.customMount( - - - + + + + + ) cy.get('table > thead > tr > th > input[type=checkbox]').click() @@ -387,14 +401,15 @@ describe('DatasetFiles', () => { it('renders the zip download limit message when selecting all rows and then navigating to other page', () => { cy.customMount( - - - + + + + + ) cy.get('table > thead > tr > th > input[type=checkbox]').click() @@ -409,12 +424,13 @@ describe('DatasetFiles', () => { describe('Calling use cases', () => { it('calls the useFiles hook with the correct parameters', () => { cy.customMount( - + + + ) cy.wrap(fileRepository.getAllByDatasetPersistentId).should( @@ -432,12 +448,13 @@ describe('DatasetFiles', () => { it('calls the useFiles hook with the correct parameters when sortBy criteria changes', () => { cy.customMount( - + + + ) cy.findByRole('button', { name: /Sort/ }).click() @@ -453,12 +470,13 @@ describe('DatasetFiles', () => { it('calls the useFiles hook with the correct parameters when filterByType criteria changes', () => { cy.customMount( - + + + ) cy.findByRole('button', { name: 'File Type: All' }).click() @@ -474,12 +492,13 @@ describe('DatasetFiles', () => { it('calls the useFiles hook with the correct parameters when filterByAccess criteria changes', () => { cy.customMount( - + + + ) cy.findByRole('button', { name: 'Access: All' }).click() @@ -495,12 +514,13 @@ describe('DatasetFiles', () => { it('calls the useFiles hook with the correct parameters when filterByTag criteria changes', () => { cy.customMount( - + + + ) cy.findByRole('button', { name: 'File Tags: All' }).click() @@ -516,12 +536,13 @@ describe('DatasetFiles', () => { it('calls the useFiles hook with the correct parameters when searchText criteria changes', () => { cy.customMount( - + + + ) cy.findByLabelText('Search').type('test{enter}') @@ -536,12 +557,13 @@ describe('DatasetFiles', () => { it('calls the useFiles hook with the correct parameters when paginationInfo changes', () => { cy.customMount( - + + + ) cy.findByRole('button', { name: '5' }).click() @@ -555,14 +577,15 @@ describe('DatasetFiles', () => { it('calls getFilesTotalDownloadSizeByDatasetPersistentId with the correct parameters when applying search file criteria', () => { cy.customMount( - - - + + + + + ) cy.findByRole('button', { name: 'File Type: All' }).click() diff --git a/tests/component/sections/dataset/dataset-files/DatasetFilesScrollable.spec.tsx b/tests/component/sections/dataset/dataset-files/DatasetFilesScrollable.spec.tsx index 2565483c2..006189e31 100644 --- a/tests/component/sections/dataset/dataset-files/DatasetFilesScrollable.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/DatasetFilesScrollable.spec.tsx @@ -24,6 +24,7 @@ import { FilesWithCount } from '../../../../../src/files/domain/models/FilesWith import { getCellStyle } from '../../../../../src/sections/dataset/dataset-files/files-table/FilesTableScrollable' import { DatasetMockRepository } from '../../../../../src/stories/dataset/DatasetMockRepository' import { DataverseInfoMockEmptyRepository } from '@/stories/shared-mock-repositories/info/DataverseInfoMockEmptyRepository' +import { WithRepositories } from '@tests/component/WithRepositories' const TOTAL_FILES_COUNT = 200 const ONLY_4_FILES_COUNT = 4 @@ -92,12 +93,13 @@ describe('DatasetFilesScrollable', () => { it('renders the scrollable files table', () => { cy.customMount( - + + + ) cy.wait(1000) @@ -107,13 +109,14 @@ describe('DatasetFilesScrollable', () => { it('check that the files sections are rendered even without edit permissions', () => { cy.customMount( - + + + ) cy.wait(1000) @@ -139,12 +142,13 @@ describe('DatasetFilesScrollable', () => { it('renders the first 10 files', () => { cy.customMount( - + + + ) cy.findByText('10 of 200 Files displayed').should('exist') @@ -161,12 +165,13 @@ describe('DatasetFilesScrollable', () => { totalFilesCount: 0 }) cy.customMount( - + + + ) cy.findByText('There are no files in this dataset.').should('exist') @@ -177,12 +182,13 @@ describe('DatasetFilesScrollable', () => { fileRepository.getAllByDatasetPersistentIdWithCount = cy.stub().resolves(only4Files) cy.customMount( - + + + ) cy.findByText(`${ONLY_4_FILES_COUNT} Files`).should('exist') @@ -196,12 +202,13 @@ describe('DatasetFilesScrollable', () => { it('loads more files when scrolling to the bottom ', () => { cy.customMount( - + + + ) cy.findByText('10 of 200 Files displayed').should('exist') @@ -218,12 +225,13 @@ describe('DatasetFilesScrollable', () => { it('scrolls to the top when criteria changes', () => { cy.customMount( - + + + ) cy.findByText('10 of 200 Files displayed').should('exist') @@ -243,12 +251,13 @@ describe('DatasetFilesScrollable', () => { describe('Sticky elements', () => { it('should stick the header table when scrolling down', () => { cy.customMount( - + + + ) cy.findByText('10 of 200 Files displayed').should('exist') @@ -269,14 +278,15 @@ describe('DatasetFilesScrollable', () => { it('should stick the table top messages on top of the table header when scrolling down with selected files', () => { cy.customMount( - - - + + + + + ) cy.findByText('10 of 200 Files displayed').should('exist') @@ -303,14 +313,15 @@ describe('DatasetFilesScrollable', () => { it('table header should have css top value according to criteria container height', () => { cy.customMount( - - - + + + + + ) cy.findByText('10 of 200 Files displayed').should('exist') @@ -340,14 +351,15 @@ describe('DatasetFilesScrollable', () => { it('table header should have css top value according to criteria container height + top messages container height when selected files ,top messages container should have top value only according to criteria container height', () => { cy.customMount( - - - + + + + + ) cy.findByRole('columnheader', { name: '10 of 200 Files displayed' }).should('exist') @@ -407,12 +419,13 @@ describe('DatasetFilesScrollable', () => { describe('File selection', () => { it('selects first 10 files when clicking the top header checkbox', () => { cy.customMount( - + + + ) cy.findByRole('columnheader', { name: '10 of 200 Files displayed' }).should('exist') cy.findByTestId('header-checkbox').should('be.visible').check({ force: true }) @@ -426,12 +439,13 @@ describe('DatasetFilesScrollable', () => { it('selects all files when clicking the select all button', () => { cy.customMount( - + + + ) cy.findByRole('columnheader', { name: '10 of 200 Files displayed' }).should('exist') cy.findByTestId('header-checkbox').should('be.visible').check({ force: true }) @@ -449,12 +463,13 @@ describe('DatasetFilesScrollable', () => { it('selects all files when clicking the select all button and mantains selection when loading more on scroll to bottom', () => { cy.customMount( - + + + ) cy.findByRole('columnheader', { name: '10 of 200 Files displayed' }).should('exist') cy.findByTestId('header-checkbox').should('be.visible').check({ force: true }) @@ -489,12 +504,13 @@ describe('DatasetFilesScrollable', () => { it('maintains the selection when scrolling to bottom and loading more files', () => { cy.customMount( - + + + ) cy.findByRole('columnheader', { name: '10 of 200 Files displayed' }).should('exist') cy.get('table > tbody > tr:nth-child(2) > td:nth-child(1) > input[type=checkbox]').click() @@ -534,12 +550,13 @@ describe('DatasetFilesScrollable', () => { it('removes the selection when the header checkbox is clicked again', () => { cy.customMount( - + + + ) cy.findByRole('columnheader', { name: '10 of 200 Files displayed' }).should('exist') cy.findByTestId('header-checkbox').should('be.visible').check({ force: true }) @@ -557,12 +574,13 @@ describe('DatasetFilesScrollable', () => { it('selects all loaded by scroll files when clicking the header checkbox', () => { cy.customMount( - + + + ) cy.findByText('10 of 200 Files displayed').should('exist') @@ -585,12 +603,13 @@ describe('DatasetFilesScrollable', () => { it('all new loaded files should be checked if selecting all files when only displayed 10 and then scrolling to bottom to load 10 more files', () => { cy.customMount( - + + + ) cy.findByRole('columnheader', { name: '10 of 200 Files displayed' }).should('exist') cy.findByTestId('header-checkbox').should('be.visible').check({ force: true }) @@ -621,12 +640,13 @@ describe('DatasetFilesScrollable', () => { it('removes the selection when the filters change', () => { cy.customMount( - + + + ) cy.findByRole('columnheader', { name: '10 of 200 Files displayed' }).should('exist') cy.get('table > tbody > tr:nth-child(2) > td:nth-child(1) > input[type=checkbox]').click() @@ -638,12 +658,13 @@ describe('DatasetFilesScrollable', () => { it('removes the selection when the Sort by changes', () => { cy.customMount( - + + + ) cy.findByRole('columnheader', { name: '10 of 200 Files displayed' }).should('exist') cy.get('table > tbody > tr:nth-child(2) > td:nth-child(1) > input[type=checkbox]').click() @@ -655,12 +676,13 @@ describe('DatasetFilesScrollable', () => { it('removes the selection when the Search bar is used', () => { cy.customMount( - + + + ) cy.findByRole('columnheader', { name: '10 of 200 Files displayed' }).should('exist') cy.get('table > tbody > tr:nth-child(2) > td:nth-child(1) > input[type=checkbox]').click() @@ -671,12 +693,13 @@ describe('DatasetFilesScrollable', () => { it('removes the selection when the clear all button is clicked', () => { cy.customMount( - + + + ) cy.findByRole('columnheader', { name: '10 of 200 Files displayed' }).should('exist') cy.get('table > tbody > tr:nth-child(2) > td:nth-child(1) > input[type=checkbox]').click() @@ -695,14 +718,15 @@ describe('DatasetFilesScrollable', () => { metadata: FileMetadataMother.create({ size: new FileSize(2, FileSizeUnit.BYTES) }) }) cy.customMount( - - - + + + + + ) cy.get('table > tbody > tr:nth-child(2) > td:nth-child(1) > input[type=checkbox]').click() @@ -721,14 +745,15 @@ describe('DatasetFilesScrollable', () => { it('renders the zip download limit message when selecting all rows', () => { cy.customMount( - - - + + + + + ) cy.findByRole('columnheader', { name: '10 of 200 Files displayed' }).should('exist') @@ -741,14 +766,15 @@ describe('DatasetFilesScrollable', () => { it('renders the zip download limit message when selecting all rows and then scrolling to bottom to load more files', () => { cy.customMount( - - - + + + + + ) cy.findByRole('columnheader', { name: '10 of 200 Files displayed' }).should('exist') @@ -769,12 +795,13 @@ describe('DatasetFilesScrollable', () => { describe('Calling use cases', () => { it('calls the useGetAccumulatedFiles hook with the correct parameters', () => { cy.customMount( - + + + ) cy.wrap(fileRepository.getAllByDatasetPersistentIdWithCount).should( 'be.calledWith', @@ -789,12 +816,13 @@ describe('DatasetFilesScrollable', () => { }) it('calls the useGetAccumulatedFiles hook with the correct parameters when sortBy criteria changes', () => { cy.customMount( - + + + ) cy.findByRole('button', { name: /Sort/ }).click() cy.findByText('Name (Z-A)').should('exist').click() @@ -808,12 +836,13 @@ describe('DatasetFilesScrollable', () => { }) it('calls the useGetAccumulatedFiles hook with the correct parameters when filterByType criteria changes', () => { cy.customMount( - + + + ) cy.findByRole('button', { name: 'File Type: All' }).click() cy.findByText('PNG Image (485)').should('exist').click() @@ -827,12 +856,13 @@ describe('DatasetFilesScrollable', () => { }) it('calls the useGetAccumulatedFiles hook with the correct parameters when filterByAccess criteria changes', () => { cy.customMount( - + + + ) cy.findByRole('button', { name: 'Access: All' }).click() cy.findByText('Public (222)').should('exist').click() @@ -846,12 +876,13 @@ describe('DatasetFilesScrollable', () => { }) it('calls the useGetAccumulatedFiles hook with the correct parameters when filterByTag criteria changes', () => { cy.customMount( - + + + ) cy.findByRole('button', { name: 'File Tags: All' }).click() cy.findByText('Document (5)').should('exist').click() @@ -865,12 +896,13 @@ describe('DatasetFilesScrollable', () => { }) it('calls the useGetAccumulatedFiles hook with the correct parameters when searchText criteria changes', () => { cy.customMount( - + + + ) cy.findByLabelText('Search').type('test{enter}') cy.wrap(fileRepository.getAllByDatasetPersistentIdWithCount).should( @@ -883,12 +915,13 @@ describe('DatasetFilesScrollable', () => { }) it('calls the useGetAccumulatedFiles hook with the correct parameters when scrolling to bottom', () => { cy.customMount( - + + + ) cy.wrap(fileRepository.getAllByDatasetPersistentIdWithCount).should( @@ -914,14 +947,15 @@ describe('DatasetFilesScrollable', () => { }) it('calls getFilesTotalDownloadSizeByDatasetPersistentId with the correct parameters when applying search file criteria', () => { cy.customMount( - - - + + + + + ) cy.findByRole('button', { name: 'File Type: All' }).click() @@ -949,12 +983,13 @@ describe('DatasetFilesScrollable', () => { .rejects(new Error('Some error on getAllByDatasetPersistentIdWithCount')) cy.customMount( - + + + ) cy.findByText('Error').should('exist') }) @@ -963,12 +998,13 @@ describe('DatasetFilesScrollable', () => { fileRepository.getAllByDatasetPersistentIdWithCount = cy.stub().rejects(new Error()) cy.customMount( - + + + ) cy.findByText(/There was an error getting the files total download size/).should('exist') }) @@ -979,12 +1015,13 @@ describe('DatasetFilesScrollable', () => { .rejects(new Error('Some error on getFilesTotalDownloadSizeByDatasetPersistentId')) cy.customMount( - + + + ) cy.findByText('Error').should('exist') }) @@ -993,12 +1030,13 @@ describe('DatasetFilesScrollable', () => { fileRepository.getFilesTotalDownloadSizeByDatasetPersistentId = cy.stub().rejects(new Error()) cy.customMount( - + + + ) cy.findByText(/There was an error getting the files total download size/).should('exist') }) @@ -1009,12 +1047,13 @@ describe('DatasetFilesScrollable', () => { .rejects(new Error('Some error on getFilesCountInfoByDatasetPersistentId')) cy.customMount( - + + + ) cy.findByText('Error').should('exist') }) @@ -1023,12 +1062,13 @@ describe('DatasetFilesScrollable', () => { fileRepository.getFilesCountInfoByDatasetPersistentId = cy.stub().rejects(new Error()) cy.customMount( - + + + ) cy.findByText(/There was an error getting the files count info/).should('exist') }) 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 7aa894063..eaf2b0529 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 @@ -14,6 +14,7 @@ import { FilePreviewMother } from '../../../../files/domain/models/FilePreviewMo import { FileRepository } from '@/files/domain/repositories/FileRepository' import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' import { DataverseInfoMockEmptyRepository } from '@/stories/shared-mock-repositories/info/DataverseInfoMockEmptyRepository' +import { WithRepositories } from '@tests/component/WithRepositories' const fileRepository: FileRepository = {} as FileRepository const datasetRepository: DatasetRepository = {} as DatasetRepository @@ -24,15 +25,16 @@ const defaultCriteria = new FileCriteria() describe('FilesTable', () => { it('renders the files table', () => { cy.customMount( - + + + ) cy.findByRole('table').should('exist') @@ -46,15 +48,16 @@ describe('FilesTable', () => { it('renders the spinner when the data isLoading', () => { cy.customMount( - + + + ) cy.findByLabelText('Files loading spinner symbol').should('exist') @@ -62,15 +65,16 @@ describe('FilesTable', () => { it('renders the no files message when there are no files', () => { cy.customMount( - + + + ) cy.findByText('There are no files in this dataset.').should('exist') @@ -79,15 +83,16 @@ describe('FilesTable', () => { describe('Row selection', () => { it('selects all rows in the current page when the header checkbox is clicked', () => { cy.customMount( - + + + ) cy.wait(1000) // wait for the table to load @@ -101,15 +106,16 @@ describe('FilesTable', () => { it('clears row selection for the current page when the header checkbox is clicked', () => { cy.customMount( - + + + ) cy.wait(1000) // wait for the table to load @@ -127,15 +133,16 @@ describe('FilesTable', () => { it("selects all rows when the 'Select all' button is clicked", () => { cy.customMount( - + + + ) cy.get('table > tbody > tr:nth-child(2) > td:nth-child(1) > input[type=checkbox]').click() @@ -149,15 +156,16 @@ describe('FilesTable', () => { it('clears the selection when the clear selection button is clicked', () => { cy.customMount( - + + + ) cy.get('table > tbody > tr:nth-child(2) > td:nth-child(1) > input[type=checkbox]').click() @@ -173,15 +181,16 @@ describe('FilesTable', () => { it('highlights the selected rows', () => { cy.customMount( - + + + ) cy.get('table > tbody > tr:nth-child(2) > td:nth-child(1) > input[type=checkbox]').click() @@ -205,17 +214,18 @@ describe('FilesTable', () => { .resolves(SettingMother.createZipDownloadLimit(new ZipDownloadLimit(500, FileSizeUnit.BYTES))) cy.customMount( - - - + + + + + ) cy.findByText( @@ -231,15 +241,16 @@ describe('FilesTable', () => { it('renders the file actions column', () => { cy.customMount( - + + + ) cy.findByRole('columnheader', { name: 'File Actions' }).should('exist') diff --git a/tests/component/sections/dataset/dataset-files/files-table/file-actions/FileActionsHeader.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/file-actions/FileActionsHeader.spec.tsx index e229257c5..c443dd856 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/file-actions/FileActionsHeader.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/file-actions/FileActionsHeader.spec.tsx @@ -7,6 +7,7 @@ import { } from '../../../../../dataset/domain/models/DatasetMother' import { FilePreviewMother } from '../../../../../files/domain/models/FilePreviewMother' import { FileRepository } from '@/files/domain/repositories/FileRepository' +import { WithRepositories } from '@tests/component/WithRepositories' describe('FileActionsHeader', () => { it('renders the file actions header', () => { @@ -19,16 +20,13 @@ describe('FileActionsHeader', () => { datasetRepository.getByPersistentId = cy.stub().resolves(datasetWithUpdatePermissions) const files = FilePreviewMother.createMany(2) cy.mountAuthenticated( - - - + + + + + ) cy.get('#edit-files-menu').should('exist') diff --git a/tests/component/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesMenu.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesMenu.spec.tsx index 0ba86c8a2..0200ace9b 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesMenu.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesMenu.spec.tsx @@ -10,6 +10,7 @@ import { } from '../../../../../../dataset/domain/models/DatasetMother' import { FilePreviewMother } from '../../../../../../files/domain/models/FilePreviewMother' import { FileRepository } from '@/files/domain/repositories/FileRepository' +import { WithRepositories } from '@tests/component/WithRepositories' const datasetRepository: DatasetRepository = {} as DatasetRepository const fileRepository: FileRepository = {} as FileRepository @@ -24,23 +25,20 @@ describe('EditFilesMenu', () => { datasetRepository.getByPrivateUrlToken = cy.stub().resolves(dataset) return ( - - {component} - + + + {component} + + ) } it('renders the Edit Files menu', () => { cy.mountAuthenticated( withDataset( - , + , datasetWithUpdatePermissions ) ) @@ -51,12 +49,7 @@ describe('EditFilesMenu', () => { it('does not render the Edit Files menu when the user is not authenticated', () => { cy.customMount( withDataset( - , + , datasetWithUpdatePermissions ) ) @@ -67,12 +60,7 @@ describe('EditFilesMenu', () => { it('does not render the Edit Files menu when there are no files in the dataset', () => { cy.mountAuthenticated( withDataset( - , + , datasetWithUpdatePermissions ) ) @@ -83,12 +71,7 @@ describe('EditFilesMenu', () => { it('renders the Edit Files options', () => { cy.mountAuthenticated( withDataset( - , + , datasetWithUpdatePermissions ) ) @@ -104,12 +87,7 @@ describe('EditFilesMenu', () => { cy.mountAuthenticated( withDataset( - , + , datasetWithNoUpdatePermissions ) ) @@ -125,12 +103,7 @@ describe('EditFilesMenu', () => { cy.mountAuthenticated( withDataset( - , + , datasetWithUpdatePermissions ) ) @@ -146,12 +119,7 @@ describe('EditFilesMenu', () => { cy.mountAuthenticated( withDataset( - , + , datasetWithUpdatePermissions ) ) diff --git a/tests/component/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesOptions.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesOptions.spec.tsx index 7ad135e6a..05c60829f 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesOptions.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesOptions.spec.tsx @@ -4,6 +4,7 @@ import { FilePreviewMother } from '../../../../../../files/domain/models/FilePre import { FileRepository } from '@/files/domain/repositories/FileRepository' import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' import { FileAccessMother } from '@tests/component/files/domain/models/FileAccessMother' +import { WithRepositories } from '@tests/component/WithRepositories' const files = FilePreviewMother.createMany(2, { access: FileAccessMother.createPublic() }) const fileRepository: FileRepository = {} as FileRepository @@ -20,13 +21,14 @@ const datasetInfo = { describe('EditFilesOptions', () => { it('renders the EditFilesOptions', () => { cy.customMount( - + + + ) cy.findByRole('button', { name: 'Metadata' }).should('exist') @@ -39,13 +41,14 @@ describe('EditFilesOptions', () => { it('renders the restrict option if some file is unrestricted', () => { const fileUnrestricted = FilePreviewMother.createDefault() cy.customMount( - + + + ) cy.findByRole('button', { name: 'Restrict' }).should('exist').click() @@ -56,13 +59,14 @@ describe('EditFilesOptions', () => { it('renders the unrestrict option if some file is restricted', () => { const fileRestricted = FilePreviewMother.createRestricted() cy.customMount( - + + + ) cy.findByRole('button', { name: 'Unrestrict' }).should('exist').click() @@ -72,13 +76,14 @@ describe('EditFilesOptions', () => { it.skip('renders the embargo option if the embargo is allowed by settings', () => { cy.customMount( - + + + ) cy.findByRole('button', { name: 'Embargo' }).should('exist').click() @@ -88,13 +93,14 @@ describe('EditFilesOptions', () => { it.skip('renders provenance option if provenance is enabled in config', () => { cy.customMount( - + + + ) cy.findByRole('button', { name: 'Provenance' }).should('exist').click() @@ -104,13 +110,14 @@ describe('EditFilesOptions', () => { it('shows the No Selected Files message when no files are selected and one option is clicked', () => { cy.customMount( - + + + ) cy.findByRole('button', { name: 'Metadata' }).click() @@ -124,13 +131,14 @@ describe('EditFilesOptions', () => { it('does not show the No Selected Files message when files are selected and one option is clicked', () => { cy.customMount( - + + + ) cy.findByRole('button', { name: 'Metadata' }).click() @@ -145,13 +153,14 @@ describe('EditFilesOptions for a single file', () => { it('renders the EditFilesOptions', () => { const fileUnrestricted = FilePreviewMother.createDefault() cy.customMount( - + + + ) cy.findByRole('button', { name: 'Restrict' }).should('exist') @@ -173,13 +182,14 @@ describe('EditFilesOptions for a single file', () => { it('renders the restrict option if some file is unrestricted', () => { const fileUnrestricted = FilePreviewMother.createDefault() cy.customMount( - + + + ) cy.findByRole('button', { name: 'Restrict' }).should('exist').click() @@ -192,13 +202,14 @@ describe('EditFilesOptions for a single file', () => { it('renders the unrestrict option if file is restricted', () => { const fileRestricted = FilePreviewMother.createRestricted() cy.customMount( - + + + ) cy.findByRole('button', { name: 'Unrestrict' }).should('exist').click() @@ -212,13 +223,14 @@ describe('EditFilesOptions for a single file', () => { it('renders delete modal', () => { const fileUnrestricted = FilePreviewMother.createDefault() cy.customMount( - + + + ) cy.findByRole('button', { name: 'Delete' }).should('exist').click() @@ -231,13 +243,14 @@ describe('EditFilesOptions for a single file', () => { it('should delete file if delete button clicked', () => { fileRepository.delete = cy.stub().resolves() cy.customMount( - + + + ) cy.findByRole('button', { name: 'Delete' }).click() @@ -250,13 +263,14 @@ describe('EditFilesOptions for a single file', () => { it('should reset the modal if cancel is clicked in delete modal', () => { const fileUnrestricted = FilePreviewMother.createDefault() cy.customMount( - + + + ) cy.findByRole('button', { name: 'Delete' }).click() @@ -278,13 +292,14 @@ describe('EditFilesOptions for a single file', () => { const fileToDelete = FilePreviewMother.createDefault() cy.customMount( - , + + + , [ `${Route.DATASETS}?${QueryParamKey.PERSISTENT_ID}=${datasetInfo.persistentId}&${QueryParamKey.VERSION}=DRAFT` ] @@ -309,13 +324,14 @@ describe('EditFilesOptions for a single file', () => { it('should restrict file if restrict button clicked', () => { fileRepository.restrict = cy.stub().resolves() cy.customMount( - + + + ) cy.findByRole('button', { name: 'Restrict' }).click() @@ -330,13 +346,14 @@ describe('EditFilesOptions for a single file', () => { const fileRestricted = FilePreviewMother.createRestricted() cy.customMount( - + + + ) cy.findByRole('button', { name: 'Unrestrict' }).click() @@ -350,13 +367,14 @@ describe('EditFilesOptions for a single file', () => { it('should restrict file and call refreshFiles if restrict button clicked in draft version', () => { fileRepository.restrict = cy.stub().resolves() cy.customMount( - , + + + , [ `${Route.DATASETS}?${QueryParamKey.PERSISTENT_ID}=${datasetInfo.persistentId}&${QueryParamKey.VERSION}=DRAFT` ] @@ -372,13 +390,14 @@ describe('EditFilesOptions for a single file', () => { it('should reset the modal if cancel is clicked in restrict modal', () => { const fileUnrestricted = FilePreviewMother.createDefault() cy.customMount( - + + + ) cy.findByRole('button', { name: 'Restrict' }).click() @@ -394,13 +413,14 @@ describe('EditFilesOptions for a single file', () => { it('opens and closes the edit file tags modal', () => { const fileUnrestricted = FilePreviewMother.createDefault() cy.customMount( - + + + ) cy.findByRole('button', { name: 'Tags' }).click() @@ -414,13 +434,14 @@ describe('EditFilesOptions for a single file', () => { const fileWithTags = FilePreviewMother.createWithLabels() cy.customMount( - + + + ) cy.findByRole('button', { name: 'Tags' }).click() @@ -439,13 +460,14 @@ describe('EditFilesOptions for a single file', () => { const fileUnrestricted = FilePreviewMother.createDefault() cy.customMount( - + + + ) cy.findByRole('button', { name: 'Restrict' }).click() @@ -460,13 +482,14 @@ describe('EditFilesOptions for a single file', () => { const fileRestricted = FilePreviewMother.createRestricted() cy.customMount( - + + + ) cy.findByRole('button', { name: 'Unrestrict' }).click() @@ -481,13 +504,14 @@ describe('EditFilesOptions for a single file', () => { const fileToDelete = FilePreviewMother.createDefault() cy.customMount( - + + + ) cy.findByRole('button', { name: 'Delete' }).click() @@ -504,13 +528,14 @@ describe('EditFilesOptions for a single file', () => { fileRepository.updateCategories = cy.stub().resolves() cy.customMount( - + + + ) cy.findByRole('button', { name: 'Tags' }).click() diff --git a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/FileActionButtons.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/FileActionButtons.spec.tsx index 3e62ab49d..9240bdfb8 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/FileActionButtons.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/FileActionButtons.spec.tsx @@ -7,6 +7,7 @@ import { import { DatasetProvider } from '../../../../../../../../../src/sections/dataset/DatasetProvider' import { FilePreviewMother } from '../../../../../../../files/domain/models/FilePreviewMother' import { FileRepository } from '@/files/domain/repositories/FileRepository' +import { WithRepositories } from '@tests/component/WithRepositories' const file = FilePreviewMother.createDefault() const fileRepository: FileRepository = {} as FileRepository @@ -15,11 +16,9 @@ const datasetRepository: DatasetRepository = {} as DatasetRepository describe('FileActionButtons', () => { it('renders the file action buttons', () => { cy.customMount( - + + + ) cy.findByRole('group', { name: 'File Action Buttons' }).should('exist') @@ -36,15 +35,13 @@ describe('FileActionButtons', () => { datasetRepository.getByPrivateUrlToken = cy.stub().resolves(datasetWithUpdatePermissions) cy.mountAuthenticated( - - - + + + + + ) cy.findByRole('group', { name: 'File Action Buttons' }).should('exist') diff --git a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/file-options-menu/FileOptionsMenu.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/file-options-menu/FileOptionsMenu.spec.tsx index 147da222e..8340d0c92 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/file-options-menu/FileOptionsMenu.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/file-options-menu/FileOptionsMenu.spec.tsx @@ -11,6 +11,7 @@ import { import { FilePreviewMother } from '../../../../../../../../files/domain/models/FilePreviewMother' import { FileRepository } from '@/files/domain/repositories/FileRepository' import { DatasetMockRepository } from '@/stories/dataset/DatasetMockRepository' +import { WithRepositories } from '@tests/component/WithRepositories' const file = FilePreviewMother.createDefault() const datasetRepository: DatasetRepository = {} as DatasetRepository @@ -25,22 +26,20 @@ describe('FileOptionsMenu', () => { datasetRepository.getByPrivateUrlToken = cy.stub().resolves(dataset) return ( - - {component} - + + + {component} + + ) } it('renders the FileOptionsMenu', () => { cy.mountAuthenticated( withDataset( - , + , datasetWithUpdatePermissions ) ) @@ -50,11 +49,7 @@ describe('FileOptionsMenu', () => { it('renders the file options menu with tooltip', () => { cy.mountAuthenticated( withDataset( - , + , datasetWithUpdatePermissions ) ) @@ -66,11 +61,7 @@ describe('FileOptionsMenu', () => { it('renders the dropdown header', () => { cy.mountAuthenticated( withDataset( - , + , datasetWithUpdatePermissions ) ) @@ -82,11 +73,7 @@ describe('FileOptionsMenu', () => { it('does not render is the user is not authenticated', () => { cy.customMount( withDataset( - , + , datasetWithUpdatePermissions ) ) @@ -100,11 +87,7 @@ describe('FileOptionsMenu', () => { }) cy.mountAuthenticated( withDataset( - , + , datasetWithNoUpdatePermissions ) ) @@ -117,11 +100,7 @@ describe('FileOptionsMenu', () => { }) cy.mountAuthenticated( withDataset( - , + , datasetWithNoTermsOfAccess ) ) @@ -136,11 +115,7 @@ describe('FileOptionsMenu', () => { }) cy.mountAuthenticated( withDataset( - , + , datasetLockedFromEdits ) ) @@ -153,11 +128,7 @@ describe('FileOptionsMenu', () => { cy.mountAuthenticated( withDataset( - , + , datasetWithUpdatePermissions ) ) @@ -174,11 +145,7 @@ describe('FileOptionsMenu', () => { it('renders the menu options', () => { cy.mountAuthenticated( withDataset( - , + , datasetWithUpdatePermissions ) ) diff --git a/tests/component/sections/dataset/dataset-metrics/DatasetMetrics.spec.tsx b/tests/component/sections/dataset/dataset-metrics/DatasetMetrics.spec.tsx index e8cf8eb52..13a66a053 100644 --- a/tests/component/sections/dataset/dataset-metrics/DatasetMetrics.spec.tsx +++ b/tests/component/sections/dataset/dataset-metrics/DatasetMetrics.spec.tsx @@ -3,6 +3,7 @@ import { DatasetMetrics } from '@/sections/dataset/dataset-metrics/DatasetMetric import { DatasetMockRepository } from '@/stories/dataset/DatasetMockRepository' import { ReadError } from '@iqss/dataverse-client-javascript' import { DatasetDownloadCountMother } from '@tests/component/dataset/domain/models/DatasetDownloadCountMother' +import { WithRepositories } from '@tests/component/WithRepositories' const datasetRepository: DatasetRepository = {} as DatasetRepository @@ -15,7 +16,11 @@ describe('DatasetMetrics', () => { return Cypress.Promise.delay(DELAYED_TIME).then(() => datasetCountWihtoutMDC) }) - cy.customMount() + cy.customMount( + + + + ) cy.clock() @@ -37,7 +42,9 @@ describe('DatasetMetrics', () => { } cy.customMount( - + + + ) cy.findByTestId('classic-download-count').should('exist').should('be.visible') @@ -47,7 +54,11 @@ describe('DatasetMetrics', () => { }) it('should render MDC downloads when calling download count with MDC and receiving MDCStartDate', () => { - cy.customMount() + cy.customMount( + + + + ) cy.findByTestId('mdc-download-count').should('exist').should('be.visible') cy.findByTestId('classic-download-count').should('not.exist') @@ -62,7 +73,11 @@ describe('DatasetMetrics', () => { it('should not render anything when there is an unknown error while loading download count', () => { datasetRepository.getDownloadCount = cy.stub().rejects() - cy.customMount() + cy.customMount( + + + + ) cy.findByTestId('dataset-metrics-skeleton').should('not.exist') cy.findByTestId('classic-download-count').should('not.exist') @@ -72,7 +87,11 @@ describe('DatasetMetrics', () => { it('should not render anything when there is an ReadError instance error while loading download count', () => { datasetRepository.getDownloadCount = cy.stub().rejects(new ReadError('Some error')) - cy.customMount() + cy.customMount( + + + + ) cy.findByTestId('dataset-metrics-skeleton').should('not.exist') cy.findByTestId('classic-download-count').should('not.exist') diff --git a/tests/component/sections/dataset/dataset-versions/DatasetVersions.spec.tsx b/tests/component/sections/dataset/dataset-versions/DatasetVersions.spec.tsx index a6f8a6a13..7c85c14b8 100644 --- a/tests/component/sections/dataset/dataset-versions/DatasetVersions.spec.tsx +++ b/tests/component/sections/dataset/dataset-versions/DatasetVersions.spec.tsx @@ -8,6 +8,7 @@ import { DatasetVersionDiff } from '@/dataset/domain/models/DatasetVersionDiff' import { DatasetVersionState } from '@/dataset/domain/models/Dataset' import { DatasetVersionsSummariesMother } from '../../../dataset/domain/models/DatasetVersionsSummariesMother' import { DatasetVersionDiffMother } from '../../../dataset/domain/models/DatasetVersionDiffMother' +import { WithRepositories } from '@tests/component/WithRepositories' const datasetsRepository: DatasetRepository = {} as DatasetRepository @@ -64,13 +65,14 @@ describe('DatasetVersions', () => { it('should not show view detail buttons if the version is deaccessioned', () => { cy.customMount( - + + + ) datasetsRepository.getDatasetVersionsSummaries = cy .stub() @@ -82,13 +84,14 @@ describe('DatasetVersions', () => { it('should show view detail buttons if previous version is deaccessioned', () => { cy.customMount( - + + + ) const versionSummaryInfoNoPreviousVersion = [ { @@ -111,13 +114,14 @@ describe('DatasetVersions', () => { beforeEach(() => { cy.customMount( - + + + ) datasetsRepository.getDatasetVersionsSummaries = cy.stub().resolves(versionSummariesSubset) datasetsRepository.getVersionDiff = cy.stub().resolves(datasetVersionDiff) @@ -202,13 +206,14 @@ describe('DatasetVersions', () => { it('should not render the dataset version table if dataset is undefined', () => { cy.customMount( - + + + ) cy.findByTestId('dataset-versions-table').should('not.exist') }) @@ -218,13 +223,14 @@ describe('DatasetVersions', () => { .stub() .returns(new Promise(() => {})) cy.customMount( - + + + ) cy.findByTestId('dataset-loading-skeleton').should('exist') cy.findByTestId('dataset-versions-table').should('not.exist') @@ -232,13 +238,14 @@ describe('DatasetVersions', () => { it('should render view differences button, open a modal if click', () => { cy.customMount( - + + + ) cy.findAllByTestId('select-checkbox').first().should('exist').check().should('be.checked') @@ -250,13 +257,14 @@ describe('DatasetVersions', () => { it('should render view differences button, close modal if cancel', () => { cy.customMount( - + + + ) cy.findAllByTestId('select-checkbox').first().should('exist').check().should('be.checked') @@ -270,13 +278,14 @@ describe('DatasetVersions', () => { it('should render view differences button, close modal if click outside', () => { cy.customMount( - + + + ) cy.get('input[type="checkbox"]').first().check() @@ -294,13 +303,14 @@ describe('DatasetVersions', () => { .resolves(DatasetVersionsSummariesMother.createDeaccessioned()) cy.customMount( - + + + ) cy.get('input[type="checkbox"]').first().should('be.disabled') @@ -334,13 +344,14 @@ describe('DatasetVersions', () => { )) cy.customMount( - + + + ) cy.findAllByTestId('select-checkbox').eq(0).check().should('be.checked') @@ -380,13 +391,14 @@ describe('DatasetVersions', () => { )) cy.customMount( - + + + ) cy.findAllByTestId('select-checkbox').eq(0).check().should('be.checked') diff --git a/tests/component/sections/edit-dataset-metadata/EditDatasetMetadata.spec.tsx b/tests/component/sections/edit-dataset-metadata/EditDatasetMetadata.spec.tsx index eab26285c..2637d3fc3 100644 --- a/tests/component/sections/edit-dataset-metadata/EditDatasetMetadata.spec.tsx +++ b/tests/component/sections/edit-dataset-metadata/EditDatasetMetadata.spec.tsx @@ -7,6 +7,7 @@ import { DatasetProvider } from '../../../../src/sections/dataset/DatasetProvide import { MetadataBlockInfoMother } from '../../metadata-block-info/domain/models/MetadataBlockInfoMother' import { EditDatasetMetadata } from '../../../../src/sections/edit-dataset-metadata/EditDatasetMetadata' import { MetadataBlockInfoRepository } from '../../../../src/metadata-block-info/domain/repositories/MetadataBlockInfoRepository' +import { WithRepositories } from '@tests/component/WithRepositories' const datasetRepository: DatasetRepository = {} as DatasetRepository const metadataBlockInfoRepository: MetadataBlockInfoRepository = {} as MetadataBlockInfoRepository @@ -33,19 +34,18 @@ describe('EditDatasetMetadata', () => { cy.customMount( - - {component} - + + + {component} + + ) } it('renders the correct breadcrumbs', () => { mountWithDataset( - , + , dataset ) @@ -61,10 +61,7 @@ describe('EditDatasetMetadata', () => { it('renders skeleton while loading', () => { mountWithDataset( - , + , dataset ) @@ -75,10 +72,7 @@ describe('EditDatasetMetadata', () => { const emptyDataset = DatasetMother.createEmpty() mountWithDataset( - , + , emptyDataset ) @@ -87,10 +81,7 @@ describe('EditDatasetMetadata', () => { it('renders the Host Collection', () => { mountWithDataset( - , + , dataset ) diff --git a/tests/component/sections/edit-dataset-terms/EditDatasetTerms.spec.tsx b/tests/component/sections/edit-dataset-terms/EditDatasetTerms.spec.tsx index 7d91af925..852104e6b 100644 --- a/tests/component/sections/edit-dataset-terms/EditDatasetTerms.spec.tsx +++ b/tests/component/sections/edit-dataset-terms/EditDatasetTerms.spec.tsx @@ -13,6 +13,7 @@ import { Dataset } from '@/dataset/domain/models/Dataset' import { License } from '@/licenses/domain/models/License' import { Guestbook } from '@/guestbooks/domain/models/Guestbook' import { GuestbookRepository } from '@/guestbooks/domain/repositories/GuestbookRepository' +import { WithRepositories } from '@tests/component/WithRepositories' const licenseRepository: LicenseRepository = {} as LicenseRepository const datasetRepository: DatasetRepository = {} as DatasetRepository @@ -89,11 +90,13 @@ describe('EditDatasetTerms', () => { datasetRepository.getByPersistentId = cy.stub().resolves(dataset) datasetRepository.getByPrivateUrlToken = cy.stub().resolves(dataset) return ( - - {component} - + + + {component} + + ) } @@ -146,7 +149,6 @@ describe('EditDatasetTerms', () => { , dataset @@ -169,7 +171,6 @@ describe('EditDatasetTerms', () => { , dataset @@ -203,7 +204,6 @@ describe('EditDatasetTerms', () => { EditDatasetTermsHelper.EDIT_DATASET_TERMS_TABS_KEYS.restrictedFilesTerms } licenseRepository={licenseRepository} - datasetRepository={datasetRepository} guestbookRepository={guestbookRepository} />, dataset @@ -229,7 +229,6 @@ describe('EditDatasetTerms', () => { , dataset @@ -249,7 +248,6 @@ describe('EditDatasetTerms', () => { , dataset @@ -289,7 +287,6 @@ describe('EditDatasetTerms', () => { , dataset @@ -325,7 +322,6 @@ describe('EditDatasetTerms', () => { , dataset @@ -347,7 +343,6 @@ describe('EditDatasetTerms', () => { , dataset @@ -378,7 +373,6 @@ describe('EditDatasetTerms', () => { EditDatasetTermsHelper.EDIT_DATASET_TERMS_TABS_KEYS.restrictedFilesTerms } licenseRepository={licenseRepository} - datasetRepository={datasetRepository} guestbookRepository={guestbookRepository} />, dataset @@ -408,7 +402,6 @@ describe('EditDatasetTerms', () => { EditDatasetTermsHelper.EDIT_DATASET_TERMS_TABS_KEYS.restrictedFilesTerms } licenseRepository={licenseRepository} - datasetRepository={datasetRepository} guestbookRepository={guestbookRepository} />, dataset @@ -453,7 +446,6 @@ describe('EditDatasetTerms', () => { , dataset @@ -478,7 +470,6 @@ describe('EditDatasetTerms', () => { , dataset @@ -501,7 +492,6 @@ describe('EditDatasetTerms', () => { , dataset @@ -540,7 +530,6 @@ describe('EditDatasetTerms', () => { , undefined @@ -559,7 +548,6 @@ describe('EditDatasetTerms', () => { EditDatasetTermsHelper.EDIT_DATASET_TERMS_TABS_KEYS.restrictedFilesTerms } licenseRepository={licenseRepository} - datasetRepository={datasetRepository} guestbookRepository={guestbookRepository} />, dataset @@ -582,7 +570,6 @@ describe('EditDatasetTerms', () => { , dataset @@ -601,7 +588,6 @@ describe('EditDatasetTerms', () => { , dataset @@ -621,7 +607,6 @@ describe('EditDatasetTerms', () => { , dataset @@ -644,7 +629,6 @@ describe('EditDatasetTerms', () => { , dataset @@ -670,7 +654,6 @@ describe('EditDatasetTerms', () => { , dataset @@ -687,11 +670,13 @@ describe('EditDatasetTerms Mobile View', () => { datasetRepository.getByPersistentId = cy.stub().resolves(dataset) datasetRepository.getByPrivateUrlToken = cy.stub().resolves(dataset) return ( - - {component} - + + + {component} + + ) } @@ -707,7 +692,6 @@ describe('EditDatasetTerms Mobile View', () => { , dataset diff --git a/tests/component/sections/edit-dataset-terms/EditLicenseAndTerms.spec.tsx b/tests/component/sections/edit-dataset-terms/EditLicenseAndTerms.spec.tsx index 3c776f751..cf9aa55cf 100644 --- a/tests/component/sections/edit-dataset-terms/EditLicenseAndTerms.spec.tsx +++ b/tests/component/sections/edit-dataset-terms/EditLicenseAndTerms.spec.tsx @@ -11,6 +11,7 @@ import { import { TermsOfUseMother } from '@tests/component/dataset/domain/models/TermsOfUseMother' import { Dataset } from '@/dataset/domain/models/Dataset' import { License } from '@/licenses/domain/models/License' +import { WithRepositories } from '@tests/component/WithRepositories' const licenseRepository: LicenseRepository = {} as LicenseRepository const datasetRepository: DatasetRepository = {} as DatasetRepository @@ -67,11 +68,13 @@ describe('EditLicenseAndTerms', () => { datasetRepository.getByPrivateUrlToken = cy.stub().resolves(dataset) return ( - - {component} - + + + {component} + + ) } @@ -80,11 +83,13 @@ describe('EditLicenseAndTerms', () => { datasetRepository.getByPrivateUrlToken = cy.stub().returns(new Promise(() => {})) return ( - - {component} - + + + {component} + + ) } @@ -95,13 +100,7 @@ describe('EditLicenseAndTerms', () => { describe('License Selection', () => { it('renders license dropdown with available licenses', () => { cy.customMount( - withProviders( - , - mockDataset - ) + withProviders(, mockDataset) ) cy.findByRole('option', { name: 'CC0 1.0' }).should('exist') @@ -112,10 +111,7 @@ describe('EditLicenseAndTerms', () => { it('allows user to change license selection', () => { cy.customMount( withProviders( - , + , mockDatasetWithLicense ) ) @@ -130,13 +126,7 @@ describe('EditLicenseAndTerms', () => { describe('Custom Terms', () => { it('shows custom terms fields when "Custom Dataset Terms" is selected', () => { cy.customMount( - withProviders( - , - mockDataset - ) + withProviders(, mockDataset) ) cy.findByTestId('customTerms.termsOfUse').should('exist') @@ -153,13 +143,7 @@ describe('EditLicenseAndTerms', () => { datasetRepository.updateDatasetLicense = cy.stub().resolves() cy.customMount( - withProviders( - , - mockDataset - ) + withProviders(, mockDataset) ) cy.findByTestId('customTerms.termsOfUse').clear() @@ -172,13 +156,7 @@ describe('EditLicenseAndTerms', () => { it('allows switching between license and custom terms', () => { cy.customMount( - withProviders( - , - mockDataset - ) + withProviders(, mockDataset) ) cy.get('select').select('Custom Dataset Terms') @@ -191,13 +169,7 @@ describe('EditLicenseAndTerms', () => { describe('Form Actions', () => { it('enables save button when form is valid', () => { cy.customMount( - withProviders( - , - mockDataset - ) + withProviders(, mockDataset) ) cy.findByRole('button', { name: 'Save Changes' }).should('be.enabled') @@ -207,12 +179,7 @@ describe('EditLicenseAndTerms', () => { datasetRepository.updateDatasetLicense = cy.stub().as('updateDatasetLicense') cy.customMount( - withLoadingDataset( - - ) + withLoadingDataset() ) cy.get('select').select('CC0 1.0') @@ -232,10 +199,7 @@ describe('EditLicenseAndTerms', () => { cy.customMount( withProviders( <> - + , draftDataset @@ -253,10 +217,7 @@ describe('EditLicenseAndTerms', () => { cy.customMount( withLoadingDataset( <> - + ), @@ -274,13 +235,7 @@ describe('EditLicenseAndTerms', () => { licenseRepository.getAvailableStandardLicenses = cy.stub().returns(new Promise(() => {})) cy.customMount( - withProviders( - , - mockDataset - ) + withProviders(, mockDataset) ) cy.findByRole('option', { name: 'Custom Dataset Terms' }).should('exist') @@ -292,13 +247,7 @@ describe('EditLicenseAndTerms', () => { datasetRepository.updateDatasetLicense = cy.stub().returns(new Promise(() => {})) cy.customMount( - withProviders( - , - mockDataset - ) + withProviders(, mockDataset) ) cy.findByRole('option', { name: 'Custom Dataset Terms' }).should('exist') @@ -317,13 +266,7 @@ describe('EditLicenseAndTerms', () => { .rejects(new Error('Failed to load licenses')) cy.customMount( - withProviders( - , - mockDataset - ) + withProviders(, mockDataset) ) cy.findByText(/Something went wrong getting the licenses. Try again later./i).should('exist') @@ -333,13 +276,7 @@ describe('EditLicenseAndTerms', () => { datasetRepository.updateDatasetLicense = cy.stub().rejects(new Error()) cy.customMount( - withProviders( - , - mockDataset - ) + withProviders(, mockDataset) ) cy.findByRole('option', { name: 'Custom Dataset Terms' }).should('exist') @@ -357,10 +294,7 @@ describe('EditLicenseAndTerms', () => { cy.customMount( withProviders( - , + , mockDatasetWithLicense ) ) @@ -377,13 +311,7 @@ describe('EditLicenseAndTerms', () => { datasetRepository.updateDatasetLicense = cy.stub().resolves() cy.customMount( - withProviders( - , - mockDataset - ) + withProviders(, mockDataset) ) cy.findByTestId('customTerms.termsOfUse').clear().type('Updated custom terms') diff --git a/tests/component/sections/edit-dataset-terms/EditTermsOfAccess.spec.tsx b/tests/component/sections/edit-dataset-terms/EditTermsOfAccess.spec.tsx index eb1a023e8..fb413d032 100644 --- a/tests/component/sections/edit-dataset-terms/EditTermsOfAccess.spec.tsx +++ b/tests/component/sections/edit-dataset-terms/EditTermsOfAccess.spec.tsx @@ -12,6 +12,7 @@ import { } from '@tests/component/dataset/domain/models/TermsOfUseMother' import { Dataset } from '@/dataset/domain/models/Dataset' import { useLocation } from 'react-router-dom' +import { WithRepositories } from '@tests/component/WithRepositories' const LocationDisplay = () => { const location = useLocation() @@ -42,11 +43,13 @@ describe('EditTermsOfAccess', () => { datasetRepository.getByPrivateUrlToken = cy.stub().resolves(dataset) return ( - - {component} - + + + {component} + + ) } @@ -55,28 +58,26 @@ describe('EditTermsOfAccess', () => { datasetRepository.getByPrivateUrlToken = cy.stub().returns(new Promise(() => {})) return ( - - {component} - + + + {component} + + ) } describe('Request Access Section', () => { it('renders the request access checkbox', () => { - cy.customMount( - withProviders(, mockDataset) - ) + cy.customMount(withProviders(, mockDataset)) cy.findByLabelText('Enable access request').should('exist') cy.findByLabelText('Enable access request').should('be.checked') }) it('shows info alert', () => { - cy.customMount( - withProviders(, mockDataset) - ) + cy.customMount(withProviders(, mockDataset)) cy.findByText(/Restricting limits access to published files/).should('exist') }) @@ -84,9 +85,7 @@ describe('EditTermsOfAccess', () => { describe('Terms of Access Fields', () => { it('renders all terms of access fields', () => { - cy.customMount( - withProviders(, mockDataset) - ) + cy.customMount(withProviders(, mockDataset)) cy.findByLabelText('Terms of Access for Restricted Files').should('exist') cy.findByLabelText('Data Access Place').should('exist') @@ -98,9 +97,7 @@ describe('EditTermsOfAccess', () => { }) it('pre-fills fields with initial values', () => { - cy.customMount( - withProviders(, mockDataset) - ) + cy.customMount(withProviders(, mockDataset)) cy.findByDisplayValue('Access requires approval').should('exist') cy.findByDisplayValue('Main office').should('exist') cy.findByDisplayValue('University archive').should('exist') @@ -111,9 +108,7 @@ describe('EditTermsOfAccess', () => { }) it('allows editing of terms of access fields', () => { - cy.customMount( - withProviders(, mockDataset) - ) + cy.customMount(withProviders(, mockDataset)) cy.findByLabelText('Terms of Access for Restricted Files') .clear() @@ -125,26 +120,20 @@ describe('EditTermsOfAccess', () => { describe('Form Actions', () => { it('renders save and cancel buttons', () => { - cy.customMount( - withProviders(, mockDataset) - ) + cy.customMount(withProviders(, mockDataset)) cy.findByRole('button', { name: 'Save Changes' }).should('exist') cy.findByRole('button', { name: 'Cancel' }).should('exist') }) it('enables save button when form is valid', () => { - cy.customMount( - withProviders(, mockDataset) - ) + cy.customMount(withProviders(, mockDataset)) cy.findByRole('button', { name: 'Save Changes' }).should('be.enabled') }) it('disables save button when request access is disabled and terms are empty', () => { - cy.customMount( - withProviders(, mockDataset) - ) + cy.customMount(withProviders(, mockDataset)) cy.findByRole('button', { name: 'Save Changes' }).should('be.disabled') cy.findByLabelText(/Terms of Access for Restricted Files/i).type('Provide contact details') @@ -152,9 +141,7 @@ describe('EditTermsOfAccess', () => { }) it('submits form data when save is clicked', () => { - cy.customMount( - withProviders(, mockDataset) - ) + cy.customMount(withProviders(, mockDataset)) cy.findByLabelText('Terms of Access for Restricted Files').clear().type('New terms') cy.findByRole('button', { name: 'Save Changes' }).click() @@ -163,9 +150,7 @@ describe('EditTermsOfAccess', () => { it('shows "Saving" while terms are being submitted and disables the button', () => { datasetRepository.updateTermsOfAccess = cy.stub().returns(new Promise(() => {})) - cy.customMount( - withProviders(, mockDataset) - ) + cy.customMount(withProviders(, mockDataset)) cy.findByRole('button', { name: 'Save Changes' }).click() cy.findByRole('button', { name: 'Saving' }).should('exist').and('be.disabled') @@ -173,9 +158,7 @@ describe('EditTermsOfAccess', () => { }) it('handles empty initial terms of access', () => { - cy.customMount( - withProviders(, mockDataset) - ) + cy.customMount(withProviders(, mockDataset)) cy.findByLabelText('Enable access request').should('exist') cy.findByLabelText('Terms of Access for Restricted Files').should('exist') @@ -191,12 +174,7 @@ describe('EditTermsOfAccess', () => { }) }) - cy.customMount( - withProviders( - , - datasetWithUndefinedRequest - ) - ) + cy.customMount(withProviders(, datasetWithUndefinedRequest)) cy.findByRole('button', { name: 'Save Changes' }).should('be.enabled') }) @@ -206,7 +184,7 @@ describe('EditTermsOfAccess', () => { cy.customMount( withLoadingDataset( <> - + ), @@ -227,7 +205,7 @@ describe('EditTermsOfAccess', () => { cy.customMount( withProviders( <> - + , draftDataset @@ -250,7 +228,7 @@ describe('EditTermsOfAccess', () => { cy.customMount( withProviders( <> - + , releasedDataset @@ -274,7 +252,7 @@ describe('EditTermsOfAccess', () => { cy.customMount( withProviders( - , + , DatasetMother.create({ id: 123, termsOfUse: { termsOfAccess } @@ -298,7 +276,7 @@ describe('EditTermsOfAccess', () => { cy.customMount( withProviders( - , + , DatasetMother.create({ id: 123, termsOfUse: { termsOfAccess } diff --git a/tests/component/sections/file/File.spec.tsx b/tests/component/sections/file/File.spec.tsx index 67ba5585a..eaecc1e7e 100644 --- a/tests/component/sections/file/File.spec.tsx +++ b/tests/component/sections/file/File.spec.tsx @@ -9,6 +9,7 @@ import { FileExternalToolResolvedMother } from '@tests/component/externalTools/d import { DataverseInfoMockRepository } from '@/stories/shared-mock-repositories/info/DataverseInfoMockRepository' import { ContactMockRepository } from '@/stories/shared-mock-repositories/contact/ContactMockRepository' import { DatasetVersionMother } from '@tests/component/dataset/domain/models/DatasetMother' +import { WithRepositories } from '@tests/component/WithRepositories' const fileRepository: FileRepository = {} as FileRepository @@ -18,13 +19,14 @@ describe('File', () => { fileRepository.getById = cy.stub().resolves(testFile) cy.customMount( - + + + ) cy.wrap(fileRepository.getById).should('be.calledWith', 19) @@ -52,13 +54,14 @@ describe('File', () => { fileRepository.getById = cy.stub().resolves(testFile) cy.customMount( - + + + ) cy.findByTestId('file-skeleton').should('exist') @@ -70,13 +73,14 @@ describe('File', () => { fileRepository.getById = cy.stub().resolves(undefined) cy.customMount( - + + + ) cy.findByTestId('not-found-page').should('exist') @@ -87,13 +91,14 @@ describe('File', () => { fileRepository.getById = cy.stub().resolves(testFile) cy.customMount( - + + + ) cy.findByText('Restricted File Icon').should('exist') @@ -104,14 +109,15 @@ describe('File', () => { fileRepository.getById = cy.stub().resolves(testFile) cy.customMount( - + + + ) cy.findByText('Version 1.0').should('exist') @@ -131,14 +137,15 @@ describe('File', () => { fileRepository.getById = cy.stub().as('getFile').resolves(testFile) cy.customMount( - + + + ) cy.findByText('Deaccessioned').should('exist') cy.findByRole('button', { name: 'Share' }).should('not.exist') @@ -160,15 +167,16 @@ describe('File', () => { it('renders the External Tools tab with "Preview" title if only one tool applicable and is a preview tool', () => { cy.customMount( - - - + + + + + ) cy.findByRole('tab', { name: 'Preview' }).should('exist') @@ -180,15 +188,16 @@ describe('File', () => { .resolves([ExternalToolsMother.createFileQueryTool()]) cy.customMount( - - - + + + + + ) cy.findByRole('tab', { name: 'Query' }).should('exist') @@ -203,15 +212,16 @@ describe('File', () => { ]) cy.customMount( - - - + + + + + ) cy.findByRole('tab', { name: 'File Tools' }).should('exist') @@ -221,15 +231,16 @@ describe('File', () => { externalToolsRepository.getExternalTools = cy.stub().resolves([]) cy.customMount( - - - + + + + + ) cy.findByRole('tab', { name: 'File Tools' }).should('not.exist') @@ -242,15 +253,16 @@ describe('File', () => { fileRepository.getById = cy.stub().resolves(testFile) cy.customMount( - - - + + + + + ) cy.findByRole('tab', { name: 'File Tools' }).should('not.exist') diff --git a/tests/component/sections/file/edit-file-tags/EditFileTagsModal.spec.tsx b/tests/component/sections/file/edit-file-tags/EditFileTagsModal.spec.tsx index 8273e4206..208156751 100644 --- a/tests/component/sections/file/edit-file-tags/EditFileTagsModal.spec.tsx +++ b/tests/component/sections/file/edit-file-tags/EditFileTagsModal.spec.tsx @@ -1,6 +1,7 @@ import { EditFileTagsModal } from '@/sections/file/file-action-buttons/edit-file-menu/edit-file-tags/edit-file-tags-modal/EditFileTagsModal' import { FileLabelType } from '@/files/domain/models/FileMetadata' import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' +import { WithRepositories } from '@tests/component/WithRepositories' describe('EditFileTagsModal', () => { let datasetRepository: DatasetRepository @@ -10,20 +11,21 @@ describe('EditFileTagsModal', () => { const categoriesMock = ['Documentation', 'Code', 'Data', 'Category4'] datasetRepository.getAvailableCategories = cy.stub().resolves(categoriesMock) cy.customMount( - {}} - fileId={1} - handleUpdateCategories={cy.stub().as('handleUpdateCategories')} - isUpdatingFileCategories={false} - errorUpdatingFileCategories={null} - handleUpdateTabularTags={cy.stub().as('handleUpdateTabularTags')} - isUpdatingTabularTags={false} - errorUpdatingTabularTags={null} - isTabularFile={true} - datasetRepository={datasetRepository} - datasetPersistentId={'1'} - /> + + {}} + fileId={1} + handleUpdateCategories={cy.stub().as('handleUpdateCategories')} + isUpdatingFileCategories={false} + errorUpdatingFileCategories={null} + handleUpdateTabularTags={cy.stub().as('handleUpdateTabularTags')} + isUpdatingTabularTags={false} + errorUpdatingTabularTags={null} + isTabularFile={true} + datasetPersistentId={'1'} + /> + ) }) @@ -124,20 +126,21 @@ describe('EditFileTagsModal', () => { it('should hide tabular tags section when file is not tabular', () => { cy.customMount( - {}} - fileId={1} - handleUpdateCategories={cy.stub().as('handleUpdateCategories')} - isUpdatingFileCategories={false} - errorUpdatingFileCategories={null} - handleUpdateTabularTags={cy.stub().as('handleUpdateTabularTags')} - isUpdatingTabularTags={false} - errorUpdatingTabularTags={null} - isTabularFile={false} - datasetRepository={datasetRepository} - datasetPersistentId={'1'} - /> + + {}} + fileId={1} + handleUpdateCategories={cy.stub().as('handleUpdateCategories')} + isUpdatingFileCategories={false} + errorUpdatingFileCategories={null} + handleUpdateTabularTags={cy.stub().as('handleUpdateTabularTags')} + isUpdatingTabularTags={false} + errorUpdatingTabularTags={null} + isTabularFile={false} + datasetPersistentId={'1'} + /> + ) cy.get('#file-tags-select').should('exist') @@ -148,20 +151,21 @@ describe('EditFileTagsModal', () => { it('should only update file categories and not tabular tags when file is not tabular', () => { cy.customMount( - {}} - fileId={1} - handleUpdateCategories={cy.stub().as('handleUpdateCategories')} - isUpdatingFileCategories={false} - errorUpdatingFileCategories={null} - handleUpdateTabularTags={cy.stub().as('handleUpdateTabularTags')} - isUpdatingTabularTags={false} - errorUpdatingTabularTags={null} - isTabularFile={false} - datasetRepository={datasetRepository} - datasetPersistentId={'1'} - /> + + {}} + fileId={1} + handleUpdateCategories={cy.stub().as('handleUpdateCategories')} + isUpdatingFileCategories={false} + errorUpdatingFileCategories={null} + handleUpdateTabularTags={cy.stub().as('handleUpdateTabularTags')} + isUpdatingTabularTags={false} + errorUpdatingTabularTags={null} + isTabularFile={false} + datasetPersistentId={'1'} + /> + ) cy.get('#file-tags-select').click() @@ -186,21 +190,22 @@ describe('EditFileTagsModal', () => { it('should not call update handlers if no changes are made', () => { cy.customMount( - {}} - fileId={1} - handleUpdateCategories={cy.stub().as('handleUpdateCategories')} - isUpdatingFileCategories={false} - errorUpdatingFileCategories={null} - handleUpdateTabularTags={cy.stub().as('handleUpdateTabularTags')} - isUpdatingTabularTags={false} - errorUpdatingTabularTags={null} - isTabularFile={true} - existingLabels={existingLabels} - datasetRepository={datasetRepository} - datasetPersistentId={'1'} - /> + + {}} + fileId={1} + handleUpdateCategories={cy.stub().as('handleUpdateCategories')} + isUpdatingFileCategories={false} + errorUpdatingFileCategories={null} + handleUpdateTabularTags={cy.stub().as('handleUpdateTabularTags')} + isUpdatingTabularTags={false} + errorUpdatingTabularTags={null} + isTabularFile={true} + existingLabels={existingLabels} + datasetPersistentId={'1'} + /> + ) cy.findByRole('button', { name: 'Save Changes' }).click() @@ -208,21 +213,22 @@ describe('EditFileTagsModal', () => { it('should show error message if duplicated customized tag exists', () => { cy.customMount( - {}} - fileId={1} - handleUpdateCategories={cy.stub().as('handleUpdateCategories')} - isUpdatingFileCategories={false} - errorUpdatingFileCategories={null} - handleUpdateTabularTags={cy.stub().as('handleUpdateTabularTags')} - isUpdatingTabularTags={false} - errorUpdatingTabularTags={null} - isTabularFile={true} - existingLabels={existingLabels} - datasetRepository={datasetRepository} - datasetPersistentId={'1'} - /> + + {}} + fileId={1} + handleUpdateCategories={cy.stub().as('handleUpdateCategories')} + isUpdatingFileCategories={false} + errorUpdatingFileCategories={null} + handleUpdateTabularTags={cy.stub().as('handleUpdateTabularTags')} + isUpdatingTabularTags={false} + errorUpdatingTabularTags={null} + isTabularFile={true} + existingLabels={existingLabels} + datasetPersistentId={'1'} + /> + ) cy.findByTestId('custom-file-tag-input').type('duplicated tag') cy.findByRole('button', { name: 'Apply' }).click() @@ -240,21 +246,22 @@ describe('EditFileTagsModal', () => { const handleCloseSpy = cy.stub().as('handleClose') cy.customMount( - + + + ) cy.findByRole('button', { name: 'Cancel' }).click() @@ -267,45 +274,47 @@ describe('EditFileTagsModal', () => { const handleCloseSpy = cy.stub().as('handleClose') cy.customMount( - - ) - - cy.get('.modal-header .btn-close').click() - cy.get('@handleClose').should('have.been.called') - }) - - describe('Error or Loading States', () => { - it('should display file categories error message', () => { - const errorMessage = 'Failed to update file categories' - cy.customMount( + {}} + handleClose={handleCloseSpy} fileId={1} handleUpdateCategories={cy.stub().as('handleUpdateCategories')} isUpdatingFileCategories={false} - errorUpdatingFileCategories={errorMessage} + errorUpdatingFileCategories={null} handleUpdateTabularTags={cy.stub().as('handleUpdateTabularTags')} isUpdatingTabularTags={false} errorUpdatingTabularTags={null} isTabularFile={true} - datasetRepository={datasetRepository} + existingLabels={existingLabels} datasetPersistentId={'1'} /> + + ) + + cy.get('.modal-header .btn-close').click() + cy.get('@handleClose').should('have.been.called') + }) + + describe('Error or Loading States', () => { + it('should display file categories error message', () => { + const errorMessage = 'Failed to update file categories' + cy.customMount( + + {}} + fileId={1} + handleUpdateCategories={cy.stub().as('handleUpdateCategories')} + isUpdatingFileCategories={false} + errorUpdatingFileCategories={errorMessage} + handleUpdateTabularTags={cy.stub().as('handleUpdateTabularTags')} + isUpdatingTabularTags={false} + errorUpdatingTabularTags={null} + isTabularFile={true} + datasetPersistentId={'1'} + /> + ) cy.findByRole('alert').should('have.class', 'alert-danger') @@ -314,20 +323,21 @@ describe('EditFileTagsModal', () => { it('should display tabular tags error message', () => { const errorMessage = 'Failed to update tabular tags' cy.customMount( - {}} - fileId={1} - handleUpdateCategories={cy.stub().as('handleUpdateCategories')} - isUpdatingFileCategories={false} - errorUpdatingFileCategories={null} - handleUpdateTabularTags={cy.stub().as('handleUpdateTabularTags')} - isUpdatingTabularTags={false} - errorUpdatingTabularTags={errorMessage} - isTabularFile={true} - datasetRepository={datasetRepository} - datasetPersistentId={'1'} - /> + + {}} + fileId={1} + handleUpdateCategories={cy.stub().as('handleUpdateCategories')} + isUpdatingFileCategories={false} + errorUpdatingFileCategories={null} + handleUpdateTabularTags={cy.stub().as('handleUpdateTabularTags')} + isUpdatingTabularTags={false} + errorUpdatingTabularTags={errorMessage} + isTabularFile={true} + datasetPersistentId={'1'} + /> + ) cy.findByRole('alert').should('have.class', 'alert-danger') @@ -338,20 +348,21 @@ describe('EditFileTagsModal', () => { datasetRepository.getAvailableCategories = cy.stub().rejects(new Error(errorMessage)) cy.customMount( - {}} - fileId={1} - handleUpdateCategories={cy.stub().as('handleUpdateCategories')} - isUpdatingFileCategories={false} - errorUpdatingFileCategories={null} - handleUpdateTabularTags={cy.stub().as('handleUpdateTabularTags')} - isUpdatingTabularTags={false} - errorUpdatingTabularTags={null} - isTabularFile={true} - datasetRepository={datasetRepository} - datasetPersistentId={'1'} - /> + + {}} + fileId={1} + handleUpdateCategories={cy.stub().as('handleUpdateCategories')} + isUpdatingFileCategories={false} + errorUpdatingFileCategories={null} + handleUpdateTabularTags={cy.stub().as('handleUpdateTabularTags')} + isUpdatingTabularTags={false} + errorUpdatingTabularTags={null} + isTabularFile={true} + datasetPersistentId={'1'} + /> + ) cy.findByRole('alert').should('have.class', 'alert-danger') @@ -359,20 +370,21 @@ describe('EditFileTagsModal', () => { it('should not display error messages when errors are null', () => { cy.customMount( - {}} - fileId={1} - handleUpdateCategories={cy.stub().as('handleUpdateCategories')} - isUpdatingFileCategories={false} - errorUpdatingFileCategories={null} - handleUpdateTabularTags={cy.stub().as('handleUpdateTabularTags')} - isUpdatingTabularTags={false} - errorUpdatingTabularTags={null} - isTabularFile={true} - datasetRepository={datasetRepository} - datasetPersistentId={'1'} - /> + + {}} + fileId={1} + handleUpdateCategories={cy.stub().as('handleUpdateCategories')} + isUpdatingFileCategories={false} + errorUpdatingFileCategories={null} + handleUpdateTabularTags={cy.stub().as('handleUpdateTabularTags')} + isUpdatingTabularTags={false} + errorUpdatingTabularTags={null} + isTabularFile={true} + datasetPersistentId={'1'} + /> + ) cy.get('.text-danger').should('not.exist') @@ -380,20 +392,21 @@ describe('EditFileTagsModal', () => { it('should disable save button when updating file categories', () => { cy.customMount( - {}} - fileId={1} - handleUpdateCategories={cy.stub().as('handleUpdateCategories')} - isUpdatingFileCategories={true} - errorUpdatingFileCategories={null} - handleUpdateTabularTags={cy.stub().as('handleUpdateTabularTags')} - isUpdatingTabularTags={false} - errorUpdatingTabularTags={null} - isTabularFile={true} - datasetRepository={datasetRepository} - datasetPersistentId={'1'} - /> + + {}} + fileId={1} + handleUpdateCategories={cy.stub().as('handleUpdateCategories')} + isUpdatingFileCategories={true} + errorUpdatingFileCategories={null} + handleUpdateTabularTags={cy.stub().as('handleUpdateTabularTags')} + isUpdatingTabularTags={false} + errorUpdatingTabularTags={null} + isTabularFile={true} + datasetPersistentId={'1'} + /> + ) cy.findByRole('button', { name: 'Saving' }).should('be.disabled') diff --git a/tests/component/sections/file/file-action-buttons/edit-file-menu/EditFileMenu.spec.tsx b/tests/component/sections/file/file-action-buttons/edit-file-menu/EditFileMenu.spec.tsx index f3d4332d5..94a683306 100644 --- a/tests/component/sections/file/file-action-buttons/edit-file-menu/EditFileMenu.spec.tsx +++ b/tests/component/sections/file/file-action-buttons/edit-file-menu/EditFileMenu.spec.tsx @@ -5,27 +5,29 @@ import { DatasetMockRepository } from '@/stories/dataset/DatasetMockRepository' import { FileMockRepository } from '@/stories/file/FileMockRepository' import { WriteError } from '@iqss/dataverse-client-javascript' import { FileMother } from '@tests/component/files/domain/models/FileMother' +import { WithRepositories } from '@tests/component/WithRepositories' const testFile = FileMother.createRealistic() describe('EditFileMenu', () => { it('renders the edit file menu', () => { cy.customMount( - + + + ) cy.findByRole('button', { name: 'Edit File' }).should('exist').click() @@ -50,29 +52,7 @@ describe('EditFileMenu', () => { it('does not render the replace file button if file storageIdentifier does not start with "s3"', () => { cy.customMount( - - ) - - cy.findByRole('link', { name: 'Replace' }).should('not.exist') - }) - - describe('Delete button', () => { - it('opens and close the delete file confirmation modal', () => { - cy.customMount( + { releasedVersionExists: false, requestAccess: false }} - storageIdentifier="s3://10.5072/FK2/FNJFOR" isTabularFile={true} - datasetRepository={new DatasetMockRepository()} + storageIdentifier="non-s3://10.5072/FK2/FNJFOR" fileType={testFile.metadata.type.value} /> + + ) + + cy.findByRole('link', { name: 'Replace' }).should('not.exist') + }) + + describe('Delete button', () => { + it('opens and close the delete file confirmation modal', () => { + cy.customMount( + + + ) cy.findByRole('button', { name: 'Edit File' }).click() @@ -101,21 +105,22 @@ describe('EditFileMenu', () => { it('file dataset has a released version, shows custom message also', () => { cy.customMount( - + + + ) cy.findByRole('button', { name: 'Edit File' }).click() @@ -129,21 +134,22 @@ describe('EditFileMenu', () => { it('closes the modal and shows toast success message when delete file succeeds', () => { cy.customMount( - + + + ) cy.findByRole('button', { name: 'Edit File' }).click() @@ -166,21 +172,22 @@ describe('EditFileMenu', () => { fileRepository.delete = cy.stub().rejects(new WriteError('Testing delete error message.')) cy.customMount( - + + + ) cy.findByRole('button', { name: 'Edit File' }).click() @@ -197,21 +204,22 @@ describe('EditFileMenu', () => { fileRepository.delete = cy.stub().rejects('Some error') cy.customMount( - + + + ) cy.findByRole('button', { name: 'Edit File' }).click() @@ -227,21 +235,22 @@ describe('EditFileMenu', () => { describe('Restrict button', () => { it('opens and close the restrict file modal', () => { cy.customMount( - + + + ) cy.findByRole('button', { name: 'Edit File' }).click() @@ -257,22 +266,23 @@ describe('EditFileMenu', () => { it('should show terms Of Access For Restricted Files in restrict file modal', () => { cy.customMount( - + + + ) cy.findByRole('button', { name: 'Edit File' }).click() @@ -289,21 +299,22 @@ describe('EditFileMenu', () => { it('file dataset has a released version, shows custom message also', () => { cy.customMount( - + + + ) cy.findByRole('button', { name: 'Edit File' }).click() @@ -317,21 +328,22 @@ describe('EditFileMenu', () => { it('should disable Save button if no terms of acccess and disenable access request', () => { cy.customMount( - + + + ) cy.findByRole('button', { name: 'Edit File' }).click() @@ -347,21 +359,22 @@ describe('EditFileMenu', () => { it('closes the modal and shows toast success message when restrict file succeeds', () => { cy.customMount( - + + + ) cy.findByRole('button', { name: 'Edit File' }).click() @@ -383,21 +396,22 @@ describe('EditFileMenu', () => { fileRepository.restrict = cy.stub().rejects('Some error') cy.customMount( - + + + ) cy.findByRole('button', { name: 'Edit File' }).click() @@ -414,21 +428,22 @@ describe('EditFileMenu', () => { fileRepository.restrict = cy.stub().rejects(new WriteError('error message.')) cy.customMount( - + + + ) cy.findByRole('button', { name: 'Edit File' }).click() @@ -442,21 +457,22 @@ describe('EditFileMenu', () => { it('should be able to restrict file with access request', () => { cy.customMount( - + + + ) cy.findByRole('button', { name: 'Edit File' }).click() @@ -477,20 +493,21 @@ describe('EditFileMenu', () => { describe('Unrestrict button', () => { it('opens and close the unrestrict file modal', () => { cy.customMount( - + + + ) cy.findByRole('button', { name: 'Edit File' }).click() @@ -505,20 +522,21 @@ describe('EditFileMenu', () => { it('file dataset has a released version, shows custom message also', () => { cy.customMount( - + + + ) cy.findByRole('button', { name: 'Edit File' }).click() @@ -531,20 +549,21 @@ describe('EditFileMenu', () => { it('closes the modal and shows toast success message when unrestrict file succeeds', () => { cy.customMount( - + + + ) cy.findByRole('button', { name: 'Edit File' }).click() @@ -566,20 +585,21 @@ describe('EditFileMenu', () => { fileRepository.restrict = cy.stub().rejects('Some error') cy.customMount( - + + + ) cy.findByRole('button', { name: 'Edit File' }).click() @@ -596,20 +616,21 @@ describe('EditFileMenu', () => { fileRepository.restrict = cy.stub().rejects(new WriteError('error message.')) cy.customMount( - + + + ) cy.findByRole('button', { name: 'Edit File' }).click() @@ -625,27 +646,28 @@ describe('EditFileMenu', () => { describe('Tags button', () => { beforeEach(() => { cy.customMount( - + + + ) }) diff --git a/tests/component/sections/shared/citation/CitationDownloadButton.spec.tsx b/tests/component/sections/shared/citation/CitationDownloadButton.spec.tsx index e96902a1a..2d143683e 100644 --- a/tests/component/sections/shared/citation/CitationDownloadButton.spec.tsx +++ b/tests/component/sections/shared/citation/CitationDownloadButton.spec.tsx @@ -2,6 +2,7 @@ import { DatasetRepository } from '@/dataset/domain/repositories/DatasetReposito import { CitationDownloadButton } from '../../../../../src/sections/shared/citation/citation-download/CitationDownloadButton' import { FormattedCitation } from '@/dataset/domain/models/DatasetCitation' import { ViewStyledCitationModal } from '@/sections/shared/citation/citation-download/ViewStyledCitationModal' +import { WithRepositories } from '@tests/component/WithRepositories' const datasetRepository: DatasetRepository = {} as DatasetRepository const mockCitation: FormattedCitation = { @@ -20,7 +21,9 @@ describe('CitationDownloadButton', () => { it('renders the button', () => { cy.customMount( - + + + ) cy.findByRole('button', { name: 'Cite Dataset' }).should('exist') }) @@ -29,11 +32,9 @@ describe('CitationDownloadButton', () => { datasetRepository.getDatasetCitationInOtherFormats = cy.stub().resolves(mockCitation) cy.customMount( - + + + ) cy.findByRole('button', { name: 'Cite Dataset' }).click() @@ -56,11 +57,9 @@ describe('CitationDownloadButton', () => { datasetRepository.getDatasetCitationInOtherFormats = cy.stub().resolves(mockCitation) cy.customMount( - + + + ) cy.findByRole('button', { name: 'Cite Dataset' }).click() @@ -82,11 +81,9 @@ describe('CitationDownloadButton', () => { datasetRepository.getDatasetCitationInOtherFormats = cy.stub().resolves(mockCitation) cy.customMount( - + + + ) cy.findByRole('button', { name: 'Cite Dataset' }).click() @@ -111,11 +108,9 @@ describe('CitationDownloadButton', () => { datasetRepository.getDatasetCitationInOtherFormats = cy.stub().resolves(mockCitation) cy.customMount( - + + + ) cy.findByRole('button', { name: 'Cite Dataset' }).click() @@ -129,7 +124,9 @@ describe('CitationDownloadButton', () => { it('opens the dropdown list and displays the citation download options', () => { datasetRepository.getDatasetCitationInOtherFormats = cy.stub().resolves(mockCitation) cy.customMount( - + + + ) cy.findByRole('button', { name: 'Cite Dataset' }).click() cy.findByText('Download EndNote XML').should('exist') @@ -143,7 +140,9 @@ describe('CitationDownloadButton', () => { .stub() .rejects(new Error('Download error')) cy.customMount( - + + + ) cy.findByRole('button', { name: 'Cite Dataset' }).click() cy.findByText('Download EndNote XML').click() @@ -153,11 +152,9 @@ describe('CitationDownloadButton', () => { it('opens styled citation modal when View Styled Citation is clicked', () => { datasetRepository.getDatasetCitationInOtherFormats = cy.stub().resolves(mockCitation) cy.customMount( - + + + ) cy.customMount( @@ -175,11 +172,9 @@ describe('CitationDownloadButton', () => { datasetRepository.getDatasetCitationInOtherFormats = cy.stub().resolves(mockCitation) cy.customMount( - + + + ) cy.findByRole('button', { name: 'Cite Dataset' }).click() @@ -196,11 +191,9 @@ describe('CitationDownloadButton', () => { .rejects(new Error('Citation fetch error')) cy.customMount( - + + + ) cy.findByRole('button', { name: 'Cite Dataset' }).click() diff --git a/tests/component/sections/shared/dataset-metadata-form/DatasetMetadataForm.spec.tsx b/tests/component/sections/shared/dataset-metadata-form/DatasetMetadataForm.spec.tsx index 9f99b0f28..9423a2812 100644 --- a/tests/component/sections/shared/dataset-metadata-form/DatasetMetadataForm.spec.tsx +++ b/tests/component/sections/shared/dataset-metadata-form/DatasetMetadataForm.spec.tsx @@ -10,6 +10,7 @@ import { MetadataBlockInfoMother } from '../../../metadata-block-info/domain/mod import { UserMother } from '../../../users/domain/models/UserMother' import { DatasetTemplateMother } from '@tests/component/dataset/domain/models/DatasetTemplateMother' import { needsUpdateStore } from '@/notifications/domain/hooks/needsUpdateStore' +import { WithRepositories } from '@tests/component/WithRepositories' const datasetRepository: DatasetRepository = {} as DatasetRepository const metadataBlockInfoRepository: MetadataBlockInfoRepository = {} as MetadataBlockInfoRepository @@ -221,12 +222,13 @@ describe('DatasetMetadataForm', () => { it('renders the form in create mode', () => { cy.customMount( - + + + ) cy.findByTestId('metadata-form').should('exist') @@ -234,15 +236,16 @@ describe('DatasetMetadataForm', () => { it('renders the form in edit mode', () => { cy.customMount( - + + + ) cy.findByTestId('metadata-form').should('exist') @@ -250,12 +253,13 @@ describe('DatasetMetadataForm', () => { it('renders the correct metadata block form sections', () => { cy.customMount( - + + + ) cy.findByText(/Citation Metadata/i).should('exist') cy.findByText(/Geospatial Metadata/i).should('exist') @@ -268,12 +272,13 @@ describe('DatasetMetadataForm', () => { describe('renders the Citation and Geospatial Metadata Form Fields correctly on create mode', () => { beforeEach(() => { cy.customMount( - + + + ) }) it('renders the correct form fields from Citation Metadata Block', () => { @@ -494,15 +499,16 @@ describe('DatasetMetadataForm', () => { describe('renders the Citation and Geospatial Metadata Form Fields correctly on edit mode', () => { beforeEach(() => { cy.customMount( - + + + ) }) @@ -1224,12 +1230,13 @@ describe('DatasetMetadataForm', () => { describe('should display required errors when submitting the form with required fields empty', () => { it('on create mode', () => { cy.customMount( - + + + ) // Fill one non required field to undisable the Save button, is disabled if fields are not dirty cy.findByLabelText(/^Notes/i).type('Some note') @@ -1248,15 +1255,16 @@ describe('DatasetMetadataForm', () => { it('on edit mode', () => { cy.customMount( - + + + ) // Clear title field to undisable the Save button and unfill a required field that is already filled as it is in edit mode cy.findByLabelText(/^Title/i).clear() @@ -1279,12 +1287,13 @@ describe('DatasetMetadataForm', () => { it('on create mode', () => { cy.spy(needsUpdateStore, 'setNeedsUpdate').as('setNeedsUpdate') cy.customMount( - + + + ) fillRequiredFieldsOnCreate() cy.findByText(/Save Dataset/i).click() @@ -1302,15 +1311,16 @@ describe('DatasetMetadataForm', () => { it('on edit mode', () => { cy.customMount( - + + + ) cy.findByLabelText(/^Title/i) .clear() @@ -1338,12 +1348,13 @@ describe('DatasetMetadataForm', () => { .resolves(metadataBlocksInfoOnCreateModeWithAstroBlock) cy.customMount( - + + + ) cy.get('.accordion > :nth-child(1)').within(() => { cy.findByText('Keyword') @@ -1399,12 +1410,13 @@ describe('DatasetMetadataForm', () => { .resolves(metadataBlocksInfoOnCreateModeWithAstroBlock) cy.customMount( - + + + ) cy.get('.accordion > :nth-child(1)').within(() => { cy.findByText('Keyword') @@ -1466,12 +1478,13 @@ describe('DatasetMetadataForm', () => { const expectedDepositDate = DateHelper.toISO8601Format(new Date()) cy.mountAuthenticated( - + + + ) cy.findByText('Author') .closest('.row') @@ -1500,12 +1513,13 @@ describe('DatasetMetadataForm', () => { it('shows the skeleton while loading', () => { cy.customMount( - + + + ) cy.findByTestId('metadata-form-loading-skeleton').should('exist') @@ -1517,12 +1531,13 @@ describe('DatasetMetadataForm', () => { .rejects(new Error('some error')) cy.customMount( - + + + ) cy.findByText('Error').should('exist') @@ -1530,12 +1545,13 @@ describe('DatasetMetadataForm', () => { it('cancel button is clickable', () => { cy.customMount( - + + + ) cy.findByText(/Cancel/i).click() @@ -1543,12 +1559,13 @@ describe('DatasetMetadataForm', () => { it('open closed accordion that has fields with errors on it and scrolls to the focused field', () => { cy.customMount( - + + + ) // Fill one non required field to undisable the Save button, is disabled if fields are not dirty @@ -1577,12 +1594,13 @@ describe('DatasetMetadataForm', () => { .resolves(wrongCollectionMetadataBlocksInfo) cy.customMount( - + + + ) // Fill one non required field to undisable the Save button, is disabled if fields are not dirty @@ -1604,12 +1622,13 @@ describe('DatasetMetadataForm', () => { ) cy.customMount( - + + + ) // Fields are being send correctly, we are just forcing a create error to check if the error message is being displayed correctly fillRequiredFieldsOnCreate() @@ -1626,12 +1645,13 @@ describe('DatasetMetadataForm', () => { datasetRepository.create = cy.stub().rejects('Some not expected error') cy.customMount( - + + + ) fillRequiredFieldsOnCreate() @@ -1655,15 +1675,16 @@ describe('DatasetMetadataForm', () => { .resolves(wrongCollectionMetadataBlocksInfo) cy.customMount( - + + + ) // Fill one non required field to undisable the Save button, is disabled if fields are not dirty @@ -1687,15 +1708,16 @@ describe('DatasetMetadataForm', () => { ) cy.customMount( - + + + ) cy.findByLabelText(/^Title/i) @@ -1716,15 +1738,16 @@ describe('DatasetMetadataForm', () => { datasetRepository.updateMetadata = cy.stub().rejects('Some not expected error') cy.customMount( - + + + ) cy.findByLabelText(/^Title/i) @@ -1744,12 +1767,13 @@ describe('DatasetMetadataForm', () => { it('adds a new field and removes a field to a composed multiple field', () => { cy.customMount( - + + + ) cy.findByText('Author') @@ -1773,15 +1797,16 @@ describe('DatasetMetadataForm', () => { it('adds a new field and removes a field to a primitive multiple field', () => { cy.customMount( - + + + ) cy.findByLabelText(/^Alternative Title/i).type('Alternative Title 1') @@ -1797,12 +1822,13 @@ describe('DatasetMetadataForm', () => { it('should not submit the form when pressing enter key if submit button is not focused', () => { cy.customMount( - + + + ) // We simulate using focusing on an input and pressing enter key @@ -1815,12 +1841,13 @@ describe('DatasetMetadataForm', () => { }) it('should submit the form when pressing enter key if submit button is indeed focused', () => { cy.customMount( - + + + ) // Type something so submit button is not disabled @@ -1837,15 +1864,16 @@ describe('DatasetMetadataForm', () => { describe('should make field required if some of the siblings are filled and viceversa and show helper message', () => { it('for a composed field multiple', () => { cy.customMount( - + + + ) cy.findByText('Producer') @@ -1877,15 +1905,16 @@ describe('DatasetMetadataForm', () => { .resolves(metadataBlocksInfoOnCreateModeWithComposedNotMultipleField) cy.customMount( - + + + ) cy.get('.accordion > :nth-child(3)').within(() => { @@ -1937,13 +1966,14 @@ describe('DatasetMetadataForm', () => { }) cy.mountAuthenticated( - + + + ) cy.findByLabelText(/^Title/i).should('have.value', 'Test Template Title') @@ -1980,13 +2010,14 @@ describe('DatasetMetadataForm', () => { }) cy.mountAuthenticated( - + + + ) cy.findByLabelText(/^Subtitle/i) @@ -2018,13 +2049,14 @@ describe('DatasetMetadataForm', () => { }) cy.mountAuthenticated( - + + + ) // The astro metadata block is not part of the fields for display on create @@ -2070,13 +2102,14 @@ describe('DatasetMetadataForm', () => { }) cy.mountAuthenticated( - + + + ) cy.findByLabelText(/^Title/i).should('have.value', 'Test Template Title') @@ -2185,13 +2218,14 @@ describe('DatasetMetadataForm', () => { }) cy.mountAuthenticated( - + + + ) cy.findByText('An author field instruction.').should('exist') diff --git a/tests/component/sections/shared/file-uploader/FileUploader.spec.tsx b/tests/component/sections/shared/file-uploader/FileUploader.spec.tsx index 200b9f9ec..70abbb9ed 100644 --- a/tests/component/sections/shared/file-uploader/FileUploader.spec.tsx +++ b/tests/component/sections/shared/file-uploader/FileUploader.spec.tsx @@ -13,14 +13,15 @@ import { import { FileMother } from '@tests/component/files/domain/models/FileMother' import { FileMockFailedRepository } from '@/stories/file/FileMockFailedUploadRepository' import FileUploadInputStyles from '../../../../../src/sections/shared/file-uploader/file-upload-input/FileUploadInput.module.scss' +import { WithRepositories } from '@tests/component/WithRepositories' const fileMockRepository = new FileMockRepository() const datasetMockRepository = new DatasetMockRepository() -type DistributiveOmit = T extends unknown ? Omit : never - -const TestFileUploader = (props: DistributiveOmit) => ( - +const TestFileUploader = (props: FileUploaderProps) => ( + + + ) const ORIGINAL_FILE_NAME = 'File Title' diff --git a/tests/component/sections/upload-dataset-files/UploadDatasetFiles.spec.tsx b/tests/component/sections/upload-dataset-files/UploadDatasetFiles.spec.tsx index 7540ca5c3..d1cfc1a6d 100644 --- a/tests/component/sections/upload-dataset-files/UploadDatasetFiles.spec.tsx +++ b/tests/component/sections/upload-dataset-files/UploadDatasetFiles.spec.tsx @@ -7,6 +7,7 @@ import { DatasetProvider } from '../../../../src/sections/dataset/DatasetProvide import { UploadDatasetFiles } from '../../../../src/sections/upload-dataset-files/UploadDatasetFiles' import { LoadingProvider } from '../../../../src/shared/contexts/loading/LoadingProvider' import { FileMockRepository } from '../../../../src/stories/file/FileMockRepository' +import { WithRepositories } from '@tests/component/WithRepositories' const fileRepository: FileRepository = {} as FileRepository const datasetRepository: DatasetRepository = {} as DatasetRepository @@ -26,11 +27,13 @@ describe('UploadDatasetFiles', () => { }) cy.customMount( - - - {component} - - + + + + {component} + + + ) } From 86c7241ea2b73ac17212018de4c0d93af6907619 Mon Sep 17 00:00:00 2001 From: Cheng Shi Date: Mon, 27 Apr 2026 17:37:09 -0400 Subject: [PATCH 2/5] fix: test error --- .../EditDatasetTerms.spec.tsx | 12 ++++--- .../replace-file/ReplaceFile.spec.tsx | 32 ++++++++++++------- .../DatasetJSDataverseRepository.spec.ts | 16 +++++----- 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/tests/component/sections/edit-dataset-terms/EditDatasetTerms.spec.tsx b/tests/component/sections/edit-dataset-terms/EditDatasetTerms.spec.tsx index 852104e6b..3670a925f 100644 --- a/tests/component/sections/edit-dataset-terms/EditDatasetTerms.spec.tsx +++ b/tests/component/sections/edit-dataset-terms/EditDatasetTerms.spec.tsx @@ -516,11 +516,13 @@ describe('EditDatasetTerms', () => { datasetRepository.getByPersistentId = cy.stub().resolves(dataset) datasetRepository.getByPrivateUrlToken = cy.stub().resolves(dataset) return ( - - {component} - + + + {component} + + ) } diff --git a/tests/component/sections/replace-file/ReplaceFile.spec.tsx b/tests/component/sections/replace-file/ReplaceFile.spec.tsx index 56e9bf69f..1e2ba7c4d 100644 --- a/tests/component/sections/replace-file/ReplaceFile.spec.tsx +++ b/tests/component/sections/replace-file/ReplaceFile.spec.tsx @@ -1,3 +1,4 @@ +import { ReactNode } from 'react' import { ReplaceFile, ReplaceFileReferrer } from '@/sections/replace-file/ReplaceFile' import { FileMother } from '@tests/component/files/domain/models/FileMother' import { @@ -6,9 +7,16 @@ import { } from '@tests/component/files/domain/models/FileMetadataMother' import { LoadingProvider } from '../../../../src/shared/contexts/loading/LoadingProvider' import { FileMockRepository } from '../../../../src/stories/file/FileMockRepository' +import { WithRepositories } from '@tests/component/WithRepositories' const fileMockRepository = new FileMockRepository() +const withProviders = (component: ReactNode) => ( + + {component} + +) + const GET_FILE_BY_ID_LOADING_TIME = 200 const ORIGINAL_FILE_NAME = 'File Title' const ORIGINAL_FILE_TYPE = 'application/json' @@ -30,7 +38,7 @@ describe('ReplaceFile', () => { it('renders the breadcrumbs', () => { cy.customMount( - + withProviders( { fileRepository={fileMockRepository} referrer={ReplaceFileReferrer.FILE} /> - + ) ) cy.findByRole('link', { name: 'Root' }).should('exist') @@ -48,7 +56,7 @@ describe('ReplaceFile', () => { it('renders skeleton while loading', () => { cy.customMount( - + withProviders( { fileRepository={fileMockRepository} referrer={ReplaceFileReferrer.FILE} /> - + ) ) cy.clock() @@ -71,7 +79,7 @@ describe('ReplaceFile', () => { fileMockRepository.getById = cy.stub().rejects() cy.customMount( - + withProviders( { fileRepository={fileMockRepository} referrer={ReplaceFileReferrer.FILE} /> - + ) ) cy.findByTestId('not-found-page').should('exist') @@ -87,7 +95,7 @@ describe('ReplaceFile', () => { it('renders the file being replaced info', () => { cy.customMount( - + withProviders( { fileRepository={fileMockRepository} referrer={ReplaceFileReferrer.FILE} /> - + ) ) cy.findByText('Original File').should('exist') @@ -109,7 +117,7 @@ describe('ReplaceFile', () => { it('replace the file successfully', () => { cy.customMount( - + withProviders( { fileRepository={fileMockRepository} referrer={ReplaceFileReferrer.FILE} /> - + ) ) cy.findByTestId('file-uploader-drop-zone').as('dnd') @@ -140,7 +148,7 @@ describe('ReplaceFile', () => { it('replace the file successfully coming from Dataset page', () => { cy.customMount( - + withProviders( { fileRepository={fileMockRepository} referrer={ReplaceFileReferrer.DATASET} /> - + ) ) cy.findByTestId('file-uploader-drop-zone').as('dnd') diff --git a/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts b/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts index 63fd2e066..3b15edce7 100644 --- a/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts +++ b/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts @@ -188,15 +188,15 @@ describe('Dataset JSDataverse Repository', () => { dataset.version.lastUpdateTime ) expect(dataset.license).to.deep.equal(datasetExpected.license) - // expect(dataset.metadataBlocks).to.deep.equal(datasetExpected.metadataBlocks) - // expect(dataset.summaryFields).to.deep.equal(datasetExpected.summaryFields) - // expect(dataset.version).to.deep.equal(datasetExpected.version) - // expect(dataset.metadataBlocks[0].fields.publicationDate).not.to.exist - // expect(dataset.metadataBlocks[0].fields.citationDate).not.to.exist - // expect(dataset.permissions).to.deep.equal(datasetExpected.permissions) - // expect(dataset.locks).to.deep.equal(datasetExpected.locks) + expect(dataset.metadataBlocks).to.deep.equal(datasetExpected.metadataBlocks) + expect(dataset.summaryFields).to.deep.equal(datasetExpected.summaryFields) + expect(dataset.version).to.deep.equal(datasetExpected.version) + expect(dataset.metadataBlocks[0].fields.publicationDate).not.to.exist + expect(dataset.metadataBlocks[0].fields.citationDate).not.to.exist + expect(dataset.permissions).to.deep.equal(datasetExpected.permissions) + expect(dataset.locks).to.deep.equal(datasetExpected.locks) expect(dataset.downloadUrls).to.deep.equal(datasetExpected.downloadUrls) - // expect(dataset.fileDownloadSizes).to.deep.equal(datasetExpected.fileDownloadSizes) + expect(dataset.fileDownloadSizes).to.deep.equal(datasetExpected.fileDownloadSizes) }) }) From fc101f07e50fac8a78b2d7fff0563d03a16ca556 Mon Sep 17 00:00:00 2001 From: Cheng Shi Date: Tue, 28 Apr 2026 12:51:33 -0400 Subject: [PATCH 3/5] fix: copilot reviews --- src/stories/WithRepositories.tsx | 22 +++++++++++++++---- tests/component/WithRepositories.tsx | 18 +++++++++++++-- .../FileOptionsMenu.spec.tsx | 3 +-- .../replace-file/ReplaceFile.spec.tsx | 4 +++- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/stories/WithRepositories.tsx b/src/stories/WithRepositories.tsx index 2917e6109..a12ba61fa 100644 --- a/src/stories/WithRepositories.tsx +++ b/src/stories/WithRepositories.tsx @@ -4,14 +4,28 @@ import { CollectionRepository } from '@/collection/domain/repositories/Collectio import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository' import { RepositoriesProvider } from '@/shared/contexts/repositories/RepositoriesProvider' +function failFastRepository(name: string): T { + return new Proxy({} as object, { + get(_target, prop) { + if (typeof prop === 'symbol') return undefined + return () => { + throw new Error( + `[${name}] method "${String(prop)}" was called but no repository was provided. ` + + `Pass a ${name} explicitly to this story decorator.` + ) + } + } + }) as T +} + interface WithRepositoriesProps { collectionRepository?: CollectionRepository datasetRepository?: DatasetRepository } export function WithRepositories({ - collectionRepository = {} as CollectionRepository, - datasetRepository = {} as DatasetRepository + collectionRepository = failFastRepository('CollectionRepository'), + datasetRepository = failFastRepository('DatasetRepository') }: WithRepositoriesProps) { function WithRepositoriesDecorator(Story: StoryFn) { return ( @@ -34,8 +48,8 @@ interface RepositoriesStoryProviderProps extends WithRepositoriesProps { export function RepositoriesStoryProvider({ children, - collectionRepository = {} as CollectionRepository, - datasetRepository = {} as DatasetRepository + collectionRepository = failFastRepository('CollectionRepository'), + datasetRepository = failFastRepository('DatasetRepository') }: RepositoriesStoryProviderProps) { return ( (name: string): T { + return new Proxy({} as object, { + get(_target, prop) { + if (typeof prop === 'symbol') return undefined + return () => { + throw new Error( + `[${name}] method "${String(prop)}" was called but no repository was provided. ` + + `Pass a ${name} explicitly to in this test.` + ) + } + } + }) as T +} + interface WithRepositoriesProps { children: ReactNode collectionRepository?: CollectionRepository @@ -11,8 +25,8 @@ interface WithRepositoriesProps { export function WithRepositories({ children, - collectionRepository = {} as CollectionRepository, - datasetRepository = {} as DatasetRepository + collectionRepository = failFastRepository('CollectionRepository'), + datasetRepository = failFastRepository('DatasetRepository') }: WithRepositoriesProps) { return ( { datasetRepository.getByPrivateUrlToken = cy.stub().resolves(dataset) return ( - + diff --git a/tests/component/sections/replace-file/ReplaceFile.spec.tsx b/tests/component/sections/replace-file/ReplaceFile.spec.tsx index 1e2ba7c4d..970fc6443 100644 --- a/tests/component/sections/replace-file/ReplaceFile.spec.tsx +++ b/tests/component/sections/replace-file/ReplaceFile.spec.tsx @@ -7,12 +7,14 @@ import { } from '@tests/component/files/domain/models/FileMetadataMother' import { LoadingProvider } from '../../../../src/shared/contexts/loading/LoadingProvider' import { FileMockRepository } from '../../../../src/stories/file/FileMockRepository' +import { DatasetMockRepository } from '../../../../src/stories/dataset/DatasetMockRepository' import { WithRepositories } from '@tests/component/WithRepositories' const fileMockRepository = new FileMockRepository() +const datasetMockRepository = new DatasetMockRepository() const withProviders = (component: ReactNode) => ( - + {component} ) From e9f97b5220915d1a298a4fbe7ff38e7d7168f634 Mon Sep 17 00:00:00 2001 From: Cheng Shi Date: Wed, 6 May 2026 11:04:20 -0400 Subject: [PATCH 4/5] fix: switch to app.tsx --- src/App.tsx | 11 ++++- src/sections/account/AccountFactory.tsx | 21 +++----- .../advanced-search/AdvancedSearchFactory.tsx | 19 ++----- src/sections/collection/CollectionFactory.tsx | 25 +++------- .../CreateCollectionFactory.tsx | 19 ++----- .../create-dataset/CreateDatasetFactory.tsx | 19 ++----- src/sections/dataset/DatasetFactory.tsx | 49 +++++++------------ .../EditFeaturedItemsFactory.tsx | 14 +----- .../edit-collection/EditCollectionFactory.tsx | 17 ++----- .../EditDatasetMetadataFactory.tsx | 17 ++----- .../EditDatasetTermsFactory.tsx | 25 ++++------ .../featured-item/FeaturedItemFactory.tsx | 18 ++----- src/sections/file/FileFactory.tsx | 25 +++------- src/sections/homepage/HomepageFactory.tsx | 17 ++----- src/sections/layout/header/HeaderFactory.tsx | 13 +---- .../replace-file/ReplaceFileFactory.tsx | 23 +++------ .../UploadDatasetFilesFactory.tsx | 17 ++----- .../create-dataset/CreateDataset.spec.tsx | 9 ++-- 18 files changed, 110 insertions(+), 248 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 24d369c34..07ef2e934 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -5,12 +5,17 @@ import { Route } from './sections/Route.enum' import { requireAppConfig } from './config' import { ExternalToolsProvider } from './shared/contexts/external-tools/ExternalToolsProvider' import { ExternalToolsJSDataverseRepository } from './externalTools/infrastructure/repositories/ExternalToolsJSDataverseRepository' +import { RepositoriesProvider } from './shared/contexts/repositories/RepositoriesProvider' +import { CollectionJSDataverseRepository } from './collection/infrastructure/repositories/CollectionJSDataverseRepository' +import { DatasetJSDataverseRepository } from './dataset/infrastructure/repositories/DatasetJSDataverseRepository' import 'react-loading-skeleton/dist/skeleton.css' import './assets/global.scss' import './assets/react-toastify-custom.scss' import './assets/swal-custom.scss' const externalToolsRepository = new ExternalToolsJSDataverseRepository() +const collectionRepository = new CollectionJSDataverseRepository() +const datasetRepository = new DatasetJSDataverseRepository() function App() { const appConfig = requireAppConfig() @@ -34,7 +39,11 @@ function App() { <> - + + + diff --git a/src/sections/account/AccountFactory.tsx b/src/sections/account/AccountFactory.tsx index 97f4ca544..a0fa99c97 100644 --- a/src/sections/account/AccountFactory.tsx +++ b/src/sections/account/AccountFactory.tsx @@ -3,15 +3,10 @@ import { useSearchParams } from 'react-router-dom' import { AccountHelper } from './AccountHelper' import { Account } from './Account' import { UserJSDataverseRepository } from '@/users/infrastructure/repositories/UserJSDataverseRepository' -import { CollectionJSDataverseRepository } from '@/collection/infrastructure/repositories/CollectionJSDataverseRepository' -import { DatasetJSDataverseRepository } from '@/dataset/infrastructure/repositories/DatasetJSDataverseRepository' import { RoleJSDataverseRepository } from '@/roles/infrastructure/repositories/RoleJSDataverseRepository' import { NotificationJSDataverseRepository } from '@/notifications/infrastructure/repositories/NotificationJSDataverseRepository' -import { RepositoriesProvider } from '@/shared/contexts/repositories/RepositoriesProvider' const userRepository = new UserJSDataverseRepository() -const collectionRepository = new CollectionJSDataverseRepository() -const datasetRepository = new DatasetJSDataverseRepository() const roleRepository = new RoleJSDataverseRepository() const notificationRepository = new NotificationJSDataverseRepository() @@ -26,15 +21,11 @@ function AccountWithSearchParams() { const defaultActiveTabKey = AccountHelper.defineSelectedTabKey(searchParams) return ( - - - + ) } diff --git a/src/sections/advanced-search/AdvancedSearchFactory.tsx b/src/sections/advanced-search/AdvancedSearchFactory.tsx index a723686b0..ecab2d4d6 100644 --- a/src/sections/advanced-search/AdvancedSearchFactory.tsx +++ b/src/sections/advanced-search/AdvancedSearchFactory.tsx @@ -1,15 +1,10 @@ import { ReactElement } from 'react' import { useParams, useSearchParams } from 'react-router-dom' -import { CollectionJSDataverseRepository } from '@/collection/infrastructure/repositories/CollectionJSDataverseRepository' -import { DatasetJSDataverseRepository } from '@/dataset/infrastructure/repositories/DatasetJSDataverseRepository' import { MetadataBlockInfoJSDataverseRepository } from '@/metadata-block-info/infrastructure/repositories/MetadataBlockInfoJSDataverseRepository' import { CollectionItemsQueryParams } from '@/collection/domain/models/CollectionItemsQueryParams' import { AdvancedSearch } from './AdvancedSearch' -import { RepositoriesProvider } from '@/shared/contexts/repositories/RepositoriesProvider' -const collectionRepository = new CollectionJSDataverseRepository() const metadataBlockInfoRepository = new MetadataBlockInfoJSDataverseRepository() -const datasetRepository = new DatasetJSDataverseRepository() export class AdvancedSearchFactory { static create(): ReactElement { @@ -26,14 +21,10 @@ function AdvancedSearchWithSearchParams() { searchParams.get(CollectionItemsQueryParams.FILTER_QUERIES) ?? undefined return ( - - - + ) } diff --git a/src/sections/collection/CollectionFactory.tsx b/src/sections/collection/CollectionFactory.tsx index b853a8222..2a0ce2339 100644 --- a/src/sections/collection/CollectionFactory.tsx +++ b/src/sections/collection/CollectionFactory.tsx @@ -1,17 +1,12 @@ import { ReactElement } from 'react' import { useLocation, useParams } from 'react-router-dom' -import { CollectionJSDataverseRepository } from '../../collection/infrastructure/repositories/CollectionJSDataverseRepository' import { ContactJSDataverseRepository } from '@/contact/infrastructure/ContactJSDataverseRepository' -import { DatasetJSDataverseRepository } from '@/dataset/infrastructure/repositories/DatasetJSDataverseRepository' import { Collection } from './Collection' import { INFINITE_SCROLL_ENABLED } from './config' import { useGetCollectionQueryParams } from './useGetCollectionQueryParams' import { ACCOUNT_CREATED_SESSION_STORAGE_KEY } from './AccountCreatedAlert' -import { RepositoriesProvider } from '@/shared/contexts/repositories/RepositoriesProvider' -const collectionRepository = new CollectionJSDataverseRepository() const contactRepository = new ContactJSDataverseRepository() -const datasetRepository = new DatasetJSDataverseRepository() export class CollectionFactory { static create(): ReactElement { @@ -34,17 +29,13 @@ function CollectionWithSearchParams() { Boolean(sessionStorage.getItem(ACCOUNT_CREATED_SESSION_STORAGE_KEY)) ?? false return ( - - - + ) } diff --git a/src/sections/create-collection/CreateCollectionFactory.tsx b/src/sections/create-collection/CreateCollectionFactory.tsx index 3ffc2b6f4..062e7c3eb 100644 --- a/src/sections/create-collection/CreateCollectionFactory.tsx +++ b/src/sections/create-collection/CreateCollectionFactory.tsx @@ -1,14 +1,9 @@ import { ReactElement } from 'react' import { useParams } from 'react-router-dom' -import { CollectionJSDataverseRepository } from '../../collection/infrastructure/repositories/CollectionJSDataverseRepository' -import { DatasetJSDataverseRepository } from '@/dataset/infrastructure/repositories/DatasetJSDataverseRepository' import { CreateCollection } from './CreateCollection' import { MetadataBlockInfoJSDataverseRepository } from '../../metadata-block-info/infrastructure/repositories/MetadataBlockInfoJSDataverseRepository' -import { RepositoriesProvider } from '@/shared/contexts/repositories/RepositoriesProvider' -const collectionRepository = new CollectionJSDataverseRepository() const metadataBlockInfoRepository = new MetadataBlockInfoJSDataverseRepository() -const datasetRepository = new DatasetJSDataverseRepository() export class CreateCollectionFactory { static create(): ReactElement { @@ -21,14 +16,10 @@ function CreateCollectionWithParams() { parentCollectionId: string } return ( - - - + ) } diff --git a/src/sections/create-dataset/CreateDatasetFactory.tsx b/src/sections/create-dataset/CreateDatasetFactory.tsx index 2c8b47a6c..1de41b6ae 100644 --- a/src/sections/create-dataset/CreateDatasetFactory.tsx +++ b/src/sections/create-dataset/CreateDatasetFactory.tsx @@ -1,17 +1,12 @@ import { ReactElement } from 'react' import { useParams } from 'react-router-dom' import { CreateDataset } from './CreateDataset' -import { DatasetJSDataverseRepository } from '../../dataset/infrastructure/repositories/DatasetJSDataverseRepository' import { TemplateJSDataverseRepository } from '../../templates/infrastructure/repositories/TemplateJSDataverseRepository' import { MetadataBlockInfoJSDataverseRepository } from '../../metadata-block-info/infrastructure/repositories/MetadataBlockInfoJSDataverseRepository' import { NotImplementedModalProvider } from '../not-implemented/NotImplementedModalProvider' -import { CollectionJSDataverseRepository } from '../../collection/infrastructure/repositories/CollectionJSDataverseRepository' -import { RepositoriesProvider } from '@/shared/contexts/repositories/RepositoriesProvider' -const datasetRepository = new DatasetJSDataverseRepository() const templateRepository = new TemplateJSDataverseRepository() const metadataBlockInfoRepository = new MetadataBlockInfoJSDataverseRepository() -const collectionRepository = new CollectionJSDataverseRepository() export class CreateDatasetFactory { static create(): ReactElement { @@ -27,14 +22,10 @@ function CreateDatasetWithSearchParams() { const { collectionId } = useParams<{ collectionId: string }>() as { collectionId: string } return ( - - - + ) } diff --git a/src/sections/dataset/DatasetFactory.tsx b/src/sections/dataset/DatasetFactory.tsx index e47764627..cc79e630f 100644 --- a/src/sections/dataset/DatasetFactory.tsx +++ b/src/sections/dataset/DatasetFactory.tsx @@ -16,15 +16,12 @@ import { NotImplementedModalProvider } from '../not-implemented/NotImplementedMo import { AlertProvider } from '../alerts/AlertProvider' import { searchParamVersionToDomainVersion } from '../../router' import { FILES_TAB_INFINITE_SCROLL_ENABLED } from './config' -import { CollectionJSDataverseRepository } from '@/collection/infrastructure/repositories/CollectionJSDataverseRepository' import { ContactJSDataverseRepository } from '@/contact/infrastructure/ContactJSDataverseRepository' import { AccessJSDataverseRepository } from '@/access/infrastructure/repositories/AccessJSDataverseRepository' import { AccessRepositoryProvider } from '../access/AccessRepositoryProvider' import { GuestbookJSDataverseRepository } from '@/guestbooks/infrastructure/repositories/GuestbookJSDataverseRepository' import { GuestbookRepositoryProvider } from '../guestbooks/GuestbookRepositoryProvider' -import { RepositoriesProvider } from '@/shared/contexts/repositories/RepositoriesProvider' -const collectionRepository = new CollectionJSDataverseRepository() const datasetRepository = new DatasetJSDataverseRepository() const fileRepository = new FileJSDataverseRepository() const metadataBlockInfoRepository = new MetadataBlockInfoJSDataverseRepository() @@ -80,44 +77,36 @@ function DatasetWithSearchParams() { if (privateUrlToken) { return ( - - - - - - ) - } - - return ( - - + ) + } + + return ( + + + ) } diff --git a/src/sections/edit-collection-featured-items/EditFeaturedItemsFactory.tsx b/src/sections/edit-collection-featured-items/EditFeaturedItemsFactory.tsx index 9c15bb043..8116e0819 100644 --- a/src/sections/edit-collection-featured-items/EditFeaturedItemsFactory.tsx +++ b/src/sections/edit-collection-featured-items/EditFeaturedItemsFactory.tsx @@ -1,12 +1,6 @@ import { ReactElement } from 'react' import { useParams } from 'react-router-dom' -import { CollectionJSDataverseRepository } from '@/collection/infrastructure/repositories/CollectionJSDataverseRepository' -import { DatasetJSDataverseRepository } from '@/dataset/infrastructure/repositories/DatasetJSDataverseRepository' import { EditFeaturedItems } from './EditFeaturedItems' -import { RepositoriesProvider } from '@/shared/contexts/repositories/RepositoriesProvider' - -const collectionRepository = new CollectionJSDataverseRepository() -const datasetRepository = new DatasetJSDataverseRepository() export class EditFeaturedItemsFactory { static create(): ReactElement { @@ -17,11 +11,5 @@ export class EditFeaturedItemsFactory { function EditFeaturedItemsWithSearchParams() { const { collectionId } = useParams<{ collectionId: string }>() - return ( - - - - ) + return } diff --git a/src/sections/edit-collection/EditCollectionFactory.tsx b/src/sections/edit-collection/EditCollectionFactory.tsx index dbd13e6b6..2d10cc85e 100644 --- a/src/sections/edit-collection/EditCollectionFactory.tsx +++ b/src/sections/edit-collection/EditCollectionFactory.tsx @@ -1,14 +1,9 @@ import { ReactElement } from 'react' import { useParams } from 'react-router-dom' -import { CollectionJSDataverseRepository } from '@/collection/infrastructure/repositories/CollectionJSDataverseRepository' -import { DatasetJSDataverseRepository } from '@/dataset/infrastructure/repositories/DatasetJSDataverseRepository' import { MetadataBlockInfoJSDataverseRepository } from '@/metadata-block-info/infrastructure/repositories/MetadataBlockInfoJSDataverseRepository' import { EditCollection } from './EditCollection' -import { RepositoriesProvider } from '@/shared/contexts/repositories/RepositoriesProvider' -const collectionRepository = new CollectionJSDataverseRepository() const metadataBlockInfoRepository = new MetadataBlockInfoJSDataverseRepository() -const datasetRepository = new DatasetJSDataverseRepository() export class EditCollectionFactory { static create(): ReactElement { @@ -22,13 +17,9 @@ function EditCollectionWithParams() { } return ( - - - + ) } diff --git a/src/sections/edit-dataset-metadata/EditDatasetMetadataFactory.tsx b/src/sections/edit-dataset-metadata/EditDatasetMetadataFactory.tsx index 935a50aac..9c7bdc77e 100644 --- a/src/sections/edit-dataset-metadata/EditDatasetMetadataFactory.tsx +++ b/src/sections/edit-dataset-metadata/EditDatasetMetadataFactory.tsx @@ -4,13 +4,10 @@ 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 { CollectionJSDataverseRepository } from '@/collection/infrastructure/repositories/CollectionJSDataverseRepository' -import { RepositoriesProvider } from '@/shared/contexts/repositories/RepositoriesProvider' import { searchParamVersionToDomainVersion } from '../../router' const datasetRepository = new DatasetJSDataverseRepository() const metadataBlockInfoRepository = new MetadataBlockInfoJSDataverseRepository() -const collectionRepository = new CollectionJSDataverseRepository() export class EditDatasetMetadataFactory { static create(): ReactElement { @@ -25,14 +22,10 @@ function EditDatasetMetadataWithParams() { const version = searchParamVersionToDomainVersion(searchParamVersion) return ( - - - - - + + + ) } diff --git a/src/sections/edit-dataset-terms/EditDatasetTermsFactory.tsx b/src/sections/edit-dataset-terms/EditDatasetTermsFactory.tsx index 02e4afd9b..4ce635b97 100644 --- a/src/sections/edit-dataset-terms/EditDatasetTermsFactory.tsx +++ b/src/sections/edit-dataset-terms/EditDatasetTermsFactory.tsx @@ -7,13 +7,10 @@ import { DatasetProvider } from '../dataset/DatasetProvider' import { ReactElement } from 'react' import { DatasetNonNumericVersion } from '@/dataset/domain/models/Dataset' import { GuestbookJSDataverseRepository } from '@/guestbooks/infrastructure/repositories/GuestbookJSDataverseRepository' -import { CollectionJSDataverseRepository } from '@/collection/infrastructure/repositories/CollectionJSDataverseRepository' -import { RepositoriesProvider } from '@/shared/contexts/repositories/RepositoriesProvider' const licenseRepository = new LicenseJSDataverseRepository() const datasetRepository = new DatasetJSDataverseRepository() const guestbookRepository = new GuestbookJSDataverseRepository() -const collectionRepository = new CollectionJSDataverseRepository() export class EditDatasetTermsFactory { static create(): ReactElement { @@ -29,18 +26,14 @@ function EditDatasetTermsWithSearchParams() { const version = DatasetNonNumericVersion.LATEST return ( - - - - - + + + ) } diff --git a/src/sections/featured-item/FeaturedItemFactory.tsx b/src/sections/featured-item/FeaturedItemFactory.tsx index 819b43328..f68e38c2c 100644 --- a/src/sections/featured-item/FeaturedItemFactory.tsx +++ b/src/sections/featured-item/FeaturedItemFactory.tsx @@ -1,12 +1,6 @@ import { ReactElement } from 'react' import { useParams } from 'react-router-dom' -import { CollectionJSDataverseRepository } from '../../collection/infrastructure/repositories/CollectionJSDataverseRepository' -import { DatasetJSDataverseRepository } from '@/dataset/infrastructure/repositories/DatasetJSDataverseRepository' import { FeaturedItem } from './FeaturedItem' -import { RepositoriesProvider } from '@/shared/contexts/repositories/RepositoriesProvider' - -const collectionRepository = new CollectionJSDataverseRepository() -const datasetRepository = new DatasetJSDataverseRepository() export class FeaturedItemFactory { static create(): ReactElement { @@ -21,13 +15,9 @@ function FeaturedItemWithParams() { } return ( - - - + ) } diff --git a/src/sections/file/FileFactory.tsx b/src/sections/file/FileFactory.tsx index b8d8326cf..ff960825c 100644 --- a/src/sections/file/FileFactory.tsx +++ b/src/sections/file/FileFactory.tsx @@ -1,7 +1,6 @@ import { ReactElement } from 'react' import { useSearchParams } from 'react-router-dom' import { FileJSDataverseRepository } from '../../files/infrastructure/FileJSDataverseRepository' -import { DatasetJSDataverseRepository } from '@/dataset/infrastructure/repositories/DatasetJSDataverseRepository' import { File } from './File' import { NotFoundPage } from '../not-found-page/NotFoundPage' import { searchParamVersionToDomainVersion } from '../../router' @@ -12,16 +11,12 @@ import { AccessJSDataverseRepository } from '@/access/infrastructure/repositorie import { AccessRepositoryProvider } from '../access/AccessRepositoryProvider' import { GuestbookJSDataverseRepository } from '@/guestbooks/infrastructure/repositories/GuestbookJSDataverseRepository' import { GuestbookRepositoryProvider } from '../guestbooks/GuestbookRepositoryProvider' -import { CollectionJSDataverseRepository } from '@/collection/infrastructure/repositories/CollectionJSDataverseRepository' -import { RepositoriesProvider } from '@/shared/contexts/repositories/RepositoriesProvider' const repository = new FileJSDataverseRepository() -const datasetRepository = new DatasetJSDataverseRepository() const dataverseInfoRepository = new DataverseInfoJSDataverseRepository() const contactRepository = new ContactJSDataverseRepository() const accessRepository = new AccessJSDataverseRepository() const guestbookRepository = new GuestbookJSDataverseRepository() -const collectionRepository = new CollectionJSDataverseRepository() export class FileFactory { static create(): ReactElement { @@ -49,17 +44,13 @@ function FileWithSearchParams() { } return ( - - - + ) } diff --git a/src/sections/homepage/HomepageFactory.tsx b/src/sections/homepage/HomepageFactory.tsx index 19b119a76..a52b12ab5 100644 --- a/src/sections/homepage/HomepageFactory.tsx +++ b/src/sections/homepage/HomepageFactory.tsx @@ -1,27 +1,18 @@ import { ReactElement } from 'react' -import { CollectionJSDataverseRepository } from '@/collection/infrastructure/repositories/CollectionJSDataverseRepository' -import { DatasetJSDataverseRepository } from '@/dataset/infrastructure/repositories/DatasetJSDataverseRepository' import { ApiDataverseHubRepository } from '@/dataverse-hub/infrastructure/repositories/ApiDataverseHubRepository' import { SearchJSRepository } from '@/search/infrastructure/repositories/SearchJSRepository' -import { RepositoriesProvider } from '@/shared/contexts/repositories/RepositoriesProvider' import Homepage from './Homepage' -const collectionRepository = new CollectionJSDataverseRepository() -const datasetRepository = new DatasetJSDataverseRepository() const dataverseHubRepository = new ApiDataverseHubRepository() const searchRepository = new SearchJSRepository() export class HomepageFactory { static create(): ReactElement { return ( - - - + ) } } diff --git a/src/sections/layout/header/HeaderFactory.tsx b/src/sections/layout/header/HeaderFactory.tsx index 0760bcd5f..abacd6c20 100644 --- a/src/sections/layout/header/HeaderFactory.tsx +++ b/src/sections/layout/header/HeaderFactory.tsx @@ -1,22 +1,11 @@ import { ReactElement } from 'react' import { Header } from './Header' -import { CollectionJSDataverseRepository } from '@/collection/infrastructure/repositories/CollectionJSDataverseRepository' -import { DatasetJSDataverseRepository } from '@/dataset/infrastructure/repositories/DatasetJSDataverseRepository' import { NotificationJSDataverseRepository } from '@/notifications/infrastructure/repositories/NotificationJSDataverseRepository' -import { RepositoriesProvider } from '@/shared/contexts/repositories/RepositoriesProvider' const notificationRepository = new NotificationJSDataverseRepository() -const collectionRepository = new CollectionJSDataverseRepository() -const datasetRepository = new DatasetJSDataverseRepository() export class HeaderFactory { static create(): ReactElement { - return ( - -
- - ) + return
} } diff --git a/src/sections/replace-file/ReplaceFileFactory.tsx b/src/sections/replace-file/ReplaceFileFactory.tsx index a7a28817d..15ac547af 100644 --- a/src/sections/replace-file/ReplaceFileFactory.tsx +++ b/src/sections/replace-file/ReplaceFileFactory.tsx @@ -1,16 +1,11 @@ import { ReactElement } from 'react' import { useSearchParams } from 'react-router-dom' import { FileJSDataverseRepository } from '@/files/infrastructure/FileJSDataverseRepository' -import { DatasetJSDataverseRepository } from '@/dataset/infrastructure/repositories/DatasetJSDataverseRepository' -import { CollectionJSDataverseRepository } from '@/collection/infrastructure/repositories/CollectionJSDataverseRepository' -import { RepositoriesProvider } from '@/shared/contexts/repositories/RepositoriesProvider' import { ReplaceFile, ReplaceFileReferrer } from './ReplaceFile' import { QueryParamKey } from '../Route.enum' import { searchParamVersionToDomainVersion } from '@/router' const fileRepository = new FileJSDataverseRepository() -const datasetRepository = new DatasetJSDataverseRepository() -const collectionRepository = new CollectionJSDataverseRepository() export class ReplaceFileFactory { static create(): ReactElement { @@ -40,16 +35,12 @@ function ReplaceFileWithParams() { (searchParams.get(QueryParamKey.REFERRER) as ReplaceFileReferrer | null) ?? undefined return ( - - - + ) } diff --git a/src/sections/upload-dataset-files/UploadDatasetFilesFactory.tsx b/src/sections/upload-dataset-files/UploadDatasetFilesFactory.tsx index bbc5eb638..b5bb2c6dd 100644 --- a/src/sections/upload-dataset-files/UploadDatasetFilesFactory.tsx +++ b/src/sections/upload-dataset-files/UploadDatasetFilesFactory.tsx @@ -2,15 +2,12 @@ import { ReactElement } from 'react' import { useSearchParams } from 'react-router-dom' import { DatasetJSDataverseRepository } from '../../dataset/infrastructure/repositories/DatasetJSDataverseRepository' import { FileJSDataverseRepository } from '../../files/infrastructure/FileJSDataverseRepository' -import { CollectionJSDataverseRepository } from '@/collection/infrastructure/repositories/CollectionJSDataverseRepository' -import { RepositoriesProvider } from '@/shared/contexts/repositories/RepositoriesProvider' import { DatasetProvider } from '../dataset/DatasetProvider' import { UploadDatasetFiles } from './UploadDatasetFiles' import { searchParamVersionToDomainVersion } from '../../router' const datasetRepository = new DatasetJSDataverseRepository() const fileRepository = new FileJSDataverseRepository() -const collectionRepository = new CollectionJSDataverseRepository() export class UploadDatasetFilesFactory { static create(): ReactElement { @@ -25,14 +22,10 @@ function UploadDatasetFilesWithSearchParams() { const version = searchParamVersionToDomainVersion(searchParamVersion) return ( - - - - - + + + ) } diff --git a/tests/e2e-integration/e2e/sections/create-dataset/CreateDataset.spec.tsx b/tests/e2e-integration/e2e/sections/create-dataset/CreateDataset.spec.tsx index 3bc7e7523..c8a5a0121 100644 --- a/tests/e2e-integration/e2e/sections/create-dataset/CreateDataset.spec.tsx +++ b/tests/e2e-integration/e2e/sections/create-dataset/CreateDataset.spec.tsx @@ -50,10 +50,7 @@ describe('Create Dataset', () => { let datasetTemplateId: number beforeEach(async () => { - await DatasetHelper.createTemplate() - const templates = await DatasetHelper.getTemplatesByCollectionId() - - const { id } = templates[0] + const { id } = await DatasetHelper.createTemplate() datasetTemplateId = id }) @@ -71,7 +68,9 @@ describe('Create Dataset', () => { cy.get('@templateSelect').within(() => { cy.findByLabelText('Toggle options menu').click({ force: true }) - cy.findByText('Dataset Template One').click({ force: true }) + cy.get(`[role="option"][data-value="${datasetTemplateId}"]`) + .should('have.text', 'Dataset Template One') + .click({ force: true }) }) cy.findByLabelText(/^Title/i).should('have.value', 'Dataset Template One Title') From a921257fcfdaec4e58dbc2dc999ee73a751109ea Mon Sep 17 00:00:00 2001 From: Cheng Shi Date: Wed, 6 May 2026 13:56:16 -0400 Subject: [PATCH 5/5] fix: test error, dataset versions --- .../dataset-versions/DatasetVersions.spec.tsx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/component/sections/dataset/dataset-versions/DatasetVersions.spec.tsx b/tests/component/sections/dataset/dataset-versions/DatasetVersions.spec.tsx index 1ec659ec2..b26a2c42c 100644 --- a/tests/component/sections/dataset/dataset-versions/DatasetVersions.spec.tsx +++ b/tests/component/sections/dataset/dataset-versions/DatasetVersions.spec.tsx @@ -435,13 +435,14 @@ describe('DatasetVersions', () => { datasetsRepository.getDatasetVersionsSummaries = getDatasetVersionsSummariesStub cy.customMount( - + + + ) cy.wrap(getDatasetVersionsSummariesStub).should(() => {