diff --git a/README.md b/README.md index 162c6ac3b..fcfdd4684 100644 --- a/README.md +++ b/README.md @@ -219,6 +219,10 @@ The environment is accessible through the following URLs: > > Given that at the moment the SPA only supports file uploading through direct upload (S3), the storage selector on the create collection > page is disabled. The collection is always created using the default storage, which must be S3 +> +> #### Account Page BreadCrumbs +> +> The Account Page has been updated to remove breadcrumbs, as the page is not part of the main navigation. diff --git a/package-lock.json b/package-lock.json index 0bbb5c74c..d737851d5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.1.0", "dependencies": { "@faker-js/faker": "7.6.0", - "@iqss/dataverse-client-javascript": "2.0.0-alpha.2", + "@iqss/dataverse-client-javascript": "npm:@IQSS/dataverse-client-javascript@^2.0.0-alpha.4", "@iqss/dataverse-design-system": "*", "@istanbuljs/nyc-config-typescript": "1.0.2", "@tanstack/react-table": "8.9.2", @@ -3674,9 +3674,9 @@ }, "node_modules/@iqss/dataverse-client-javascript": { "name": "@IQSS/dataverse-client-javascript", - "version": "2.0.0-alpha.2", - "resolved": "https://npm.pkg.github.com/download/@IQSS/dataverse-client-javascript/2.0.0-alpha.2/6f926581c976bbf8649053323e1c82a729d56706", - "integrity": "sha512-bJgGirBFr4gL+pVFz0zNAlMovxWHJMi9RCN9v6lnpkLU+fKHUTeMkEgQdGxoA0lI3V8cvA+e2xcpoi7/24vRKg==", + "version": "2.0.0-alpha.4", + "resolved": "https://npm.pkg.github.com/download/@IQSS/dataverse-client-javascript/2.0.0-alpha.4/10ab7e0ed2a31a09b1b32d27521b96f84ef50f4f", + "integrity": "sha512-SJdkBIks+yjJxEVw8G7sf4YY2Bujl+8vOD+fZqt2qhIGmyPSlj9ld0APnYyoVX6lI8lGsREHZzYYjzeAmYfxhw==", "dependencies": { "@types/node": "^18.15.11", "@types/turndown": "^5.0.1", diff --git a/package.json b/package.json index fe43d59f1..db411a652 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ }, "dependencies": { "@faker-js/faker": "7.6.0", - "@iqss/dataverse-client-javascript": "2.0.0-alpha.2", + "@iqss/dataverse-client-javascript": "2.0.0-alpha.4", "@iqss/dataverse-design-system": "*", "@istanbuljs/nyc-config-typescript": "1.0.2", "@tanstack/react-table": "8.9.2", diff --git a/src/collection/domain/models/Collection.ts b/src/collection/domain/models/Collection.ts index dca9ed2c5..885c0a13a 100644 --- a/src/collection/domain/models/Collection.ts +++ b/src/collection/domain/models/Collection.ts @@ -15,5 +15,3 @@ export interface CollectionInputLevel { include: boolean required: boolean } - -export const ROOT_COLLECTION_ALIAS = 'root' diff --git a/src/collection/domain/repositories/CollectionRepository.ts b/src/collection/domain/repositories/CollectionRepository.ts index 75c77005c..d4a8567a4 100644 --- a/src/collection/domain/repositories/CollectionRepository.ts +++ b/src/collection/domain/repositories/CollectionRepository.ts @@ -7,10 +7,10 @@ import { CollectionUserPermissions } from '../models/CollectionUserPermissions' import { CollectionDTO } from '../useCases/DTOs/CollectionDTO' export interface CollectionRepository { - getById: (id: string) => Promise + getById: (id?: string) => Promise create(collection: CollectionDTO, hostCollection?: string): Promise - getFacets(collectionIdOrAlias: number | string): Promise - getUserPermissions(collectionIdOrAlias: number | string): Promise + getFacets(collectionIdOrAlias?: number | string): Promise + getUserPermissions(collectionIdOrAlias?: number | string): Promise publish(collectionIdOrAlias: number | string): Promise getItems( collectionId: string, diff --git a/src/collection/domain/useCases/createCollection.ts b/src/collection/domain/useCases/createCollection.ts index 68af8ba32..67da6fef5 100644 --- a/src/collection/domain/useCases/createCollection.ts +++ b/src/collection/domain/useCases/createCollection.ts @@ -5,7 +5,7 @@ import { CollectionDTO } from './DTOs/CollectionDTO' export function createCollection( collectionRepository: CollectionRepository, collection: CollectionDTO, - hostCollection?: string + hostCollection: string ): Promise { return collectionRepository.create(collection, hostCollection).catch((error: WriteError) => { throw error diff --git a/src/collection/domain/useCases/getCollectionById.ts b/src/collection/domain/useCases/getCollectionById.ts index 5de6cb61d..c2da48d87 100644 --- a/src/collection/domain/useCases/getCollectionById.ts +++ b/src/collection/domain/useCases/getCollectionById.ts @@ -3,8 +3,8 @@ import { CollectionRepository } from '../repositories/CollectionRepository' export async function getCollectionById( collectionRepository: CollectionRepository, - id: string -): Promise { + id?: string +): Promise { return collectionRepository.getById(id).catch((error: Error) => { throw new Error(error.message) }) diff --git a/src/collection/domain/useCases/getCollectionUserPermissions.ts b/src/collection/domain/useCases/getCollectionUserPermissions.ts index fb5d10a6d..1c51b23f3 100644 --- a/src/collection/domain/useCases/getCollectionUserPermissions.ts +++ b/src/collection/domain/useCases/getCollectionUserPermissions.ts @@ -3,7 +3,7 @@ import { CollectionUserPermissions } from '../models/CollectionUserPermissions' export function getCollectionUserPermissions( collectionRepository: CollectionRepository, - collectionIdOrAlias: number | string + collectionIdOrAlias?: number | string ): Promise { return collectionRepository.getUserPermissions(collectionIdOrAlias).catch((error: Error) => { throw new Error(error.message) diff --git a/src/collection/infrastructure/repositories/CollectionJSDataverseRepository.ts b/src/collection/infrastructure/repositories/CollectionJSDataverseRepository.ts index 3f745a569..996b6750a 100644 --- a/src/collection/infrastructure/repositories/CollectionJSDataverseRepository.ts +++ b/src/collection/infrastructure/repositories/CollectionJSDataverseRepository.ts @@ -18,7 +18,7 @@ import { CollectionSearchCriteria } from '../../domain/models/CollectionSearchCr import { JSCollectionItemsMapper } from '../mappers/JSCollectionItemsMapper' export class CollectionJSDataverseRepository implements CollectionRepository { - getById(id: string): Promise { + getById(id?: string): Promise { return getCollection .execute(id) .then((jsCollection) => JSCollectionMapper.toCollection(jsCollection)) @@ -30,11 +30,11 @@ export class CollectionJSDataverseRepository implements CollectionRepository { .then((newCollectionIdentifier) => newCollectionIdentifier) } - getFacets(collectionIdOrAlias: number | string): Promise { + getFacets(collectionIdOrAlias?: number | string): Promise { return getCollectionFacets.execute(collectionIdOrAlias).then((facets) => facets) } - getUserPermissions(collectionIdOrAlias: number | string): Promise { + getUserPermissions(collectionIdOrAlias?: number | string): Promise { return getCollectionUserPermissions .execute(collectionIdOrAlias) .then((jsCollectionUserPermissions) => jsCollectionUserPermissions) diff --git a/src/dataset/domain/repositories/DatasetRepository.ts b/src/dataset/domain/repositories/DatasetRepository.ts index d829934dc..0e708786b 100644 --- a/src/dataset/domain/repositories/DatasetRepository.ts +++ b/src/dataset/domain/repositories/DatasetRepository.ts @@ -8,7 +8,7 @@ export interface DatasetRepository { getByPersistentId: (persistentId: string, version?: string) => Promise getLocks(persistentId: string): Promise getByPrivateUrlToken: (privateUrlToken: string) => Promise - create: (dataset: DatasetDTO, collectionId?: string) => Promise<{ persistentId: string }> + create: (dataset: DatasetDTO, collectionId: string) => Promise<{ persistentId: string }> updateMetadata: (datasetId: string | number, datasetDTO: DatasetDTO) => Promise getAllWithCount: ( collectionId: string, diff --git a/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts b/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts index cb352631a..84c4d93e2 100644 --- a/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts +++ b/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts @@ -32,7 +32,6 @@ import { DatasetDTO } from '../../domain/useCases/DTOs/DatasetDTO' import { DatasetDTOMapper } from '../mappers/DatasetDTOMapper' import { DatasetsWithCount } from '../../domain/models/DatasetsWithCount' import { VersionUpdateType } from '../../domain/models/VersionUpdateType' -import { ROOT_COLLECTION_ALIAS } from '../../../collection/domain/models/Collection' const includeDeaccessioned = true type DatasetDetails = [JSDataset, string[], string, JSDatasetPermissions, JSDatasetLock[]] @@ -223,10 +222,7 @@ export class DatasetJSDataverseRepository implements DatasetRepository { }) } - create( - dataset: DatasetDTO, - collectionId = ROOT_COLLECTION_ALIAS - ): Promise<{ persistentId: string }> { + create(dataset: DatasetDTO, collectionId: string): Promise<{ persistentId: string }> { return createDataset .execute(DatasetDTOMapper.toJSDatasetDTO(dataset), collectionId) .then((jsDatasetIdentifiers: JSDatasetIdentifiers) => ({ diff --git a/src/sections/Route.enum.ts b/src/sections/Route.enum.ts index e2d5a5248..93a88ee49 100644 --- a/src/sections/Route.enum.ts +++ b/src/sections/Route.enum.ts @@ -1,5 +1,3 @@ -import { ROOT_COLLECTION_ALIAS } from '../collection/domain/models/Collection' - export enum Route { HOME = '/', SIGN_UP = '/dataverseuser.xhtml?editMode=CREATE&redirectPage=%2Fdataverse.xhtml', @@ -17,11 +15,10 @@ export enum Route { } export const RouteWithParams = { - COLLECTIONS: (collectionId?: string) => `/collections/${collectionId ?? 'root'}`, - CREATE_COLLECTION: (ownerCollectionId?: string) => - `/collections/${ownerCollectionId ?? ROOT_COLLECTION_ALIAS}/create`, - CREATE_DATASET: (collectionId?: string) => - `/datasets/${collectionId ?? ROOT_COLLECTION_ALIAS}/create` + COLLECTIONS: (collectionId?: string) => + collectionId ? `/collections/${collectionId}` : Route.COLLECTIONS_BASE, + CREATE_COLLECTION: (ownerCollectionId: string) => `/collections/${ownerCollectionId}/create`, + CREATE_DATASET: (collectionId: string) => `/datasets/${collectionId}/create` } export enum QueryParamKey { diff --git a/src/sections/account/Account.module.scss b/src/sections/account/Account.module.scss index e76e0535b..ff579901d 100644 --- a/src/sections/account/Account.module.scss +++ b/src/sections/account/Account.module.scss @@ -1,5 +1,9 @@ @import 'node_modules/@iqss/dataverse-design-system/src/lib/assets/styles/design-tokens/colors.module'; +.header { + padding-block: 1rem; +} + .tab-container { padding: 1rem; } diff --git a/src/sections/account/Account.tsx b/src/sections/account/Account.tsx index 06d5a9fbb..3d06c6ec3 100644 --- a/src/sections/account/Account.tsx +++ b/src/sections/account/Account.tsx @@ -1,16 +1,8 @@ -import { useEffect } from 'react' import { useTranslation } from 'react-i18next' import { Tabs } from '@iqss/dataverse-design-system' -import { useLoading } from '../loading/LoadingContext' import { AccountHelper, AccountPanelTabKey } from './AccountHelper' import { ApiTokenSection } from './api-token-section/ApiTokenSection' -import { BreadcrumbsGenerator } from '../shared/hierarchy/BreadcrumbsGenerator' import styles from './Account.module.scss' -import { - DvObjectType, - UpwardHierarchyNode -} from '../../shared/hierarchy/domain/models/UpwardHierarchyNode' -import { ROOT_COLLECTION_ALIAS } from '../../collection/domain/models/Collection' const tabsKeys = AccountHelper.ACCOUNT_PANEL_TABS_KEYS @@ -20,23 +12,10 @@ interface AccountProps { export const Account = ({ defaultActiveTabKey }: AccountProps) => { const { t } = useTranslation('account') - const { setIsLoading } = useLoading() - - const rootHierarchy = new UpwardHierarchyNode( - 'Root', - DvObjectType.COLLECTION, - ROOT_COLLECTION_ALIAS - ) - - useEffect(() => { - setIsLoading(false) - }, [setIsLoading]) return (
- - -
+

{t('pageTitle')}

diff --git a/src/sections/collection/Collection.tsx b/src/sections/collection/Collection.tsx index 0db7f0916..f90964f0b 100644 --- a/src/sections/collection/Collection.tsx +++ b/src/sections/collection/Collection.tsx @@ -18,7 +18,7 @@ import styles from './Collection.module.scss' interface CollectionProps { collectionRepository: CollectionRepository - collectionId: string + collectionIdFromParams: string | undefined created: boolean published: boolean collectionQueryParams: UseCollectionQueryParamsReturnType @@ -26,7 +26,7 @@ interface CollectionProps { } export function Collection({ - collectionId, + collectionIdFromParams, collectionRepository, created, published, @@ -35,9 +35,13 @@ export function Collection({ useTranslation('collection') useScrollTop() const { user } = useSession() - const { collection, isLoading } = useCollection(collectionRepository, collectionId, published) + const { collection, isLoading } = useCollection( + collectionRepository, + collectionIdFromParams, + published + ) const { collectionUserPermissions } = useGetCollectionUserPermissions({ - collectionIdOrAlias: collectionId, + collectionIdOrAlias: collectionIdFromParams, collectionRepository }) @@ -75,23 +79,24 @@ export function Collection({ /> )} + + + ) : null + } + /> )} - - ) : null - } - /> ) diff --git a/src/sections/collection/CollectionFactory.tsx b/src/sections/collection/CollectionFactory.tsx index 6865ad81d..d06056eb9 100644 --- a/src/sections/collection/CollectionFactory.tsx +++ b/src/sections/collection/CollectionFactory.tsx @@ -14,7 +14,7 @@ export class CollectionFactory { function CollectionWithSearchParams() { const collectionQueryParams = useGetCollectionQueryParams() - const { collectionId = 'root' } = useParams<{ collectionId: string }>() + const { collectionId } = useParams<{ collectionId: string }>() const location = useLocation() const state = location.state as { published: boolean; created: boolean } | undefined const created = state?.created ?? false @@ -23,7 +23,7 @@ function CollectionWithSearchParams() { return ( (
  • {collectionItem?.type === CollectionItemType.COLLECTION && ( - + )} {collectionItem?.type === CollectionItemType.DATASET && ( diff --git a/src/sections/collection/collection-items-panel/items-list/collection-card/CollectionCard.tsx b/src/sections/collection/collection-items-panel/items-list/collection-card/CollectionCard.tsx index 768d77d10..abeb31e39 100644 --- a/src/sections/collection/collection-items-panel/items-list/collection-card/CollectionCard.tsx +++ b/src/sections/collection/collection-items-panel/items-list/collection-card/CollectionCard.tsx @@ -6,15 +6,19 @@ import styles from './CollectionCard.module.scss' interface CollectionCardProps { collectionPreview: CollectionItemTypePreview + parentCollectionAlias: string } -export function CollectionCard({ collectionPreview }: CollectionCardProps) { +export function CollectionCard({ collectionPreview, parentCollectionAlias }: CollectionCardProps) { return (
    - +
    ) diff --git a/src/sections/collection/collection-items-panel/items-list/collection-card/CollectionCardInfo.tsx b/src/sections/collection/collection-items-panel/items-list/collection-card/CollectionCardInfo.tsx index 5c182b285..7fcaf07d6 100644 --- a/src/sections/collection/collection-items-panel/items-list/collection-card/CollectionCardInfo.tsx +++ b/src/sections/collection/collection-items-panel/items-list/collection-card/CollectionCardInfo.tsx @@ -1,6 +1,4 @@ -import { useParams } from 'react-router-dom' import { Stack } from '@iqss/dataverse-design-system' -import { ROOT_COLLECTION_ALIAS } from '@/collection/domain/models/Collection' import { CollectionItemTypePreview } from '@/collection/domain/models/CollectionItemTypePreview' import { DvObjectType } from '@/shared/hierarchy/domain/models/UpwardHierarchyNode' import { DateHelper } from '@/shared/helpers/DateHelper' @@ -10,11 +8,15 @@ import styles from './CollectionCard.module.scss' interface CollectionCardInfoProps { collectionPreview: CollectionItemTypePreview + parentCollectionAlias: string } -export function CollectionCardInfo({ collectionPreview }: CollectionCardInfoProps) { - const { collectionId = ROOT_COLLECTION_ALIAS } = useParams<{ collectionId: string }>() - const isStandingOnParentCollectionPage = collectionPreview.parentCollectionAlias === collectionId +export function CollectionCardInfo({ + collectionPreview, + parentCollectionAlias +}: CollectionCardInfoProps) { + const isStandingOnParentCollectionPage = + collectionPreview.parentCollectionAlias === parentCollectionAlias return (
    diff --git a/src/sections/collection/useCollection.tsx b/src/sections/collection/useCollection.tsx index 74c99159f..de58cdcba 100644 --- a/src/sections/collection/useCollection.tsx +++ b/src/sections/collection/useCollection.tsx @@ -5,7 +5,7 @@ import { getCollectionById } from '../../collection/domain/useCases/getCollectio export function useCollection( collectionRepository: CollectionRepository, - collectionId: string, + collectionId?: string | undefined, published?: boolean ) { const [isLoading, setIsLoading] = useState(true) @@ -15,7 +15,7 @@ export function useCollection( setIsLoading(true) setCollection(undefined) getCollectionById(collectionRepository, collectionId) - .then((collection: Collection | undefined) => { + .then((collection: Collection) => { setCollection(collection) }) .catch((error) => { diff --git a/src/sections/create-collection/CreateCollectionFactory.tsx b/src/sections/create-collection/CreateCollectionFactory.tsx index 1e65d3b9b..af55ee266 100644 --- a/src/sections/create-collection/CreateCollectionFactory.tsx +++ b/src/sections/create-collection/CreateCollectionFactory.tsx @@ -2,7 +2,6 @@ import { ReactElement } from 'react' import { useParams } from 'react-router-dom' import { CollectionJSDataverseRepository } from '../../collection/infrastructure/repositories/CollectionJSDataverseRepository' import { CreateCollection } from './CreateCollection' -import { ROOT_COLLECTION_ALIAS } from '../../collection/domain/models/Collection' import { MetadataBlockInfoJSDataverseRepository } from '../../metadata-block-info/infrastructure/repositories/MetadataBlockInfoJSDataverseRepository' const collectionRepository = new CollectionJSDataverseRepository() @@ -15,8 +14,9 @@ export class CreateCollectionFactory { } function CreateCollectionWithParams() { - const { ownerCollectionId = ROOT_COLLECTION_ALIAS } = useParams<{ ownerCollectionId: string }>() - + const { ownerCollectionId } = useParams<{ ownerCollectionId: string }>() as { + ownerCollectionId: string + } return ( {t('pageTitle')}
  • - + () + const { collectionId } = useParams<{ collectionId: string }>() as { collectionId: string } return ( -
    + {HeaderFactory.create()}
    diff --git a/src/sections/layout/header/Header.tsx b/src/sections/layout/header/Header.tsx index 092b7b8ef..8937eff6e 100644 --- a/src/sections/layout/header/Header.tsx +++ b/src/sections/layout/header/Header.tsx @@ -5,12 +5,13 @@ import { Route } from '../../Route.enum' import { useSession } from '../../session/SessionContext' import { BASE_URL } from '../../../config' import { LoggedInHeaderActions } from './LoggedInHeaderActions' -import { CollectionJSDataverseRepository } from '../../../collection/infrastructure/repositories/CollectionJSDataverseRepository' import styles from './Header.module.scss' +import { CollectionRepository } from '@/collection/domain/repositories/CollectionRepository' -const collectionRepository = new CollectionJSDataverseRepository() - -export function Header() { +interface HeaderProps { + collectionRepository: CollectionRepository +} +export function Header({ collectionRepository }: HeaderProps) { const { t } = useTranslation('header') const { user } = useSession() diff --git a/src/sections/layout/header/HeaderFactory.tsx b/src/sections/layout/header/HeaderFactory.tsx new file mode 100644 index 000000000..a00eaa5ce --- /dev/null +++ b/src/sections/layout/header/HeaderFactory.tsx @@ -0,0 +1,11 @@ +import { ReactElement } from 'react' +import { Header } from './Header' +import { CollectionJSDataverseRepository } from '@/collection/infrastructure/repositories/CollectionJSDataverseRepository' + +const collectionRepository = new CollectionJSDataverseRepository() + +export class HeaderFactory { + static create(): ReactElement { + return
    + } +} diff --git a/src/sections/layout/header/LoggedInHeaderActions.tsx b/src/sections/layout/header/LoggedInHeaderActions.tsx index 1d44f715e..6bcc3e695 100644 --- a/src/sections/layout/header/LoggedInHeaderActions.tsx +++ b/src/sections/layout/header/LoggedInHeaderActions.tsx @@ -6,8 +6,8 @@ import { useSession } from '../../session/SessionContext' import { RouteWithParams, Route } from '../../Route.enum' import { User } from '../../../users/domain/models/User' import { CollectionRepository } from '../../../collection/domain/repositories/CollectionRepository' -import { ROOT_COLLECTION_ALIAS } from '../../../collection/domain/models/Collection' import { AccountHelper } from '../../account/AccountHelper' +import { useCollection } from '@/sections/collection/useCollection' const currentPage = 0 @@ -23,9 +23,10 @@ export const LoggedInHeaderActions = ({ const { t } = useTranslation('header') const { logout } = useSession() const navigate = useNavigate() + const { collection } = useCollection(collectionRepository) const { collectionUserPermissions } = useGetCollectionUserPermissions({ - collectionIdOrAlias: ROOT_COLLECTION_ALIAS, + collectionIdOrAlias: undefined, collectionRepository: collectionRepository }) @@ -35,8 +36,12 @@ export const LoggedInHeaderActions = ({ }) } - const createCollectionRoute = RouteWithParams.CREATE_COLLECTION() - const createDatasetRoute = RouteWithParams.CREATE_DATASET() + if (!collection) { + return null + } + + const createCollectionRoute = RouteWithParams.CREATE_COLLECTION(collection.id) + const createDatasetRoute = RouteWithParams.CREATE_DATASET(collection.id) const canUserAddCollectionToRoot = Boolean(collectionUserPermissions?.canAddCollection) const canUserAddDatasetToRoot = Boolean(collectionUserPermissions?.canAddDataset) diff --git a/src/sections/shared/add-data-actions/AddDataActionsButton.tsx b/src/sections/shared/add-data-actions/AddDataActionsButton.tsx index 517a0238d..e55d8bd8b 100644 --- a/src/sections/shared/add-data-actions/AddDataActionsButton.tsx +++ b/src/sections/shared/add-data-actions/AddDataActionsButton.tsx @@ -7,7 +7,7 @@ import { RouteWithParams } from '../../Route.enum' import styles from './AddDataActionsButton.module.scss' interface AddDataActionsButtonProps { - collectionId?: string + collectionId: string canAddCollection: boolean canAddDataset: boolean } diff --git a/src/shared/hooks/useGetCollectionUserPermissions.ts b/src/shared/hooks/useGetCollectionUserPermissions.ts index 1e06c26a1..1a94ff902 100644 --- a/src/shared/hooks/useGetCollectionUserPermissions.ts +++ b/src/shared/hooks/useGetCollectionUserPermissions.ts @@ -4,7 +4,7 @@ import { CollectionUserPermissions } from '@iqss/dataverse-client-javascript' import { getCollectionUserPermissions } from '../../collection/domain/useCases/getCollectionUserPermissions' interface Props { - collectionIdOrAlias: string | number + collectionIdOrAlias: string | number | undefined collectionRepository: CollectionRepository } diff --git a/src/stories/collection/Collection.stories.tsx b/src/stories/collection/Collection.stories.tsx index c56e42f20..f48b6235d 100644 --- a/src/stories/collection/Collection.stories.tsx +++ b/src/stories/collection/Collection.stories.tsx @@ -24,7 +24,7 @@ export const Default: Story = { render: () => ( ( ( ( ( ( { + getById(_id?: string): Promise { return new Promise((_resolve, reject) => { setTimeout(() => { reject('Something went wrong') diff --git a/src/stories/collection/CollectionLoadingMockRepository.ts b/src/stories/collection/CollectionLoadingMockRepository.ts index cf48f565e..71e63e09e 100644 --- a/src/stories/collection/CollectionLoadingMockRepository.ts +++ b/src/stories/collection/CollectionLoadingMockRepository.ts @@ -7,7 +7,7 @@ import { CollectionItemSubset } from '@/collection/domain/models/CollectionItemS import { CollectionSearchCriteria } from '@/collection/domain/models/CollectionSearchCriteria' export class CollectionLoadingMockRepository extends CollectionMockRepository { - getById(_id: string): Promise { + getById(_id?: string): Promise { return new Promise(() => {}) } create(_collection: CollectionDTO, _hostCollection?: string): Promise { diff --git a/src/stories/collection/CollectionMockRepository.ts b/src/stories/collection/CollectionMockRepository.ts index 9766af900..efb2e116a 100644 --- a/src/stories/collection/CollectionMockRepository.ts +++ b/src/stories/collection/CollectionMockRepository.ts @@ -13,7 +13,7 @@ import { CollectionItemsMother } from '../../../tests/component/collection/domai import { CollectionItemType } from '@/collection/domain/models/CollectionItemType' export class CollectionMockRepository implements CollectionRepository { - getById(_id: string): Promise { + getById(_id?: string): Promise { return new Promise((resolve) => { setTimeout(() => { resolve(CollectionMother.createRealistic()) diff --git a/src/stories/collection/NoCollectionMockRepository.ts b/src/stories/collection/NoCollectionMockRepository.ts index 17cb063a0..63d8c5e00 100644 --- a/src/stories/collection/NoCollectionMockRepository.ts +++ b/src/stories/collection/NoCollectionMockRepository.ts @@ -7,7 +7,7 @@ import { CollectionFacet } from '../../collection/domain/models/CollectionFacet' import { CollectionMockRepository } from './CollectionMockRepository' export class NoCollectionMockRepository extends CollectionMockRepository { - getById(_id: string): Promise { + getById(_id?: string): Promise { return new Promise((_resolve, reject) => { setTimeout(() => { reject('Collection not found') diff --git a/src/stories/collection/UnpublishedCollectionMockRepository.ts b/src/stories/collection/UnpublishedCollectionMockRepository.ts index c9194f4f7..9bc90dd61 100644 --- a/src/stories/collection/UnpublishedCollectionMockRepository.ts +++ b/src/stories/collection/UnpublishedCollectionMockRepository.ts @@ -4,7 +4,7 @@ import { FakerHelper } from '../../../tests/component/shared/FakerHelper' import { CollectionMockRepository } from '@/stories/collection/CollectionMockRepository' export class UnpublishedCollectionMockRepository extends CollectionMockRepository { - getById(_id: string): Promise { + getById(_id?: string): Promise { return new Promise((resolve) => { setTimeout(() => { resolve(CollectionMother.createUnpublished()) diff --git a/src/stories/collection/collection-items-panel/CollectionCard.stories.tsx b/src/stories/collection/collection-items-panel/CollectionCard.stories.tsx index 05443406e..e50285374 100644 --- a/src/stories/collection/collection-items-panel/CollectionCard.stories.tsx +++ b/src/stories/collection/collection-items-panel/CollectionCard.stories.tsx @@ -15,7 +15,10 @@ type Story = StoryObj export const Default: Story = { render: () => ( - + ) } @@ -24,19 +27,26 @@ export const WithLongDescription: Story = { const collectionPreview = CollectionItemTypePreviewMother.create({ description: FakerHelper.paragraph(20) }) - - return + return ( + + ) } } export const Unpublished: Story = { render: () => ( - + ) } export const WithThumbnail: Story = { render: () => ( - + ) } diff --git a/src/stories/create-collection/CreateCollection.stories.tsx b/src/stories/create-collection/CreateCollection.stories.tsx index 0f2e81cc4..f868a305d 100644 --- a/src/stories/create-collection/CreateCollection.stories.tsx +++ b/src/stories/create-collection/CreateCollection.stories.tsx @@ -8,11 +8,12 @@ import { CollectionLoadingMockRepository } from '../collection/CollectionLoading import { NoCollectionMockRepository } from '../collection/NoCollectionMockRepository' import { CollectionMother } from '../../../tests/component/collection/domain/models/CollectionMother' import { FakerHelper } from '../../../tests/component/shared/FakerHelper' -import { ROOT_COLLECTION_ALIAS } from '../../collection/domain/models/Collection' import { MetadataBlockInfoMockRepository } from '../shared-mock-repositories/metadata-block-info/MetadataBlockInfoMockRepository' import { MetadataBlockInfoMockLoadingRepository } from '../shared-mock-repositories/metadata-block-info/MetadataBlockInfoMockLoadingRepository' import { MetadataBlockInfoMockErrorRepository } from '../shared-mock-repositories/metadata-block-info/MetadataBlockInfoMockErrorRepository' +import { ROOT_COLLECTION_ALIAS } from '@tests/e2e-integration/shared/collection/ROOT_COLLECTION_ALIAS' + const meta: Meta = { title: 'Pages/Create Collection', component: CreateCollection, diff --git a/src/stories/create-dataset/CreateDataset.stories.tsx b/src/stories/create-dataset/CreateDataset.stories.tsx index c14c09cec..7cf4ce107 100644 --- a/src/stories/create-dataset/CreateDataset.stories.tsx +++ b/src/stories/create-dataset/CreateDataset.stories.tsx @@ -30,6 +30,7 @@ export const Default: Story = { datasetRepository={new DatasetMockRepository()} metadataBlockInfoRepository={new MetadataBlockInfoMockRepository()} collectionRepository={new CollectionMockRepository()} + collectionId={'collectionId'} /> ) @@ -41,6 +42,7 @@ export const Loading: Story = { datasetRepository={new DatasetMockRepository()} metadataBlockInfoRepository={new MetadataBlockInfoMockLoadingRepository()} collectionRepository={new CollectionMockRepository()} + collectionId={'collectionId'} /> ) } @@ -64,6 +66,7 @@ export const NotAllowedToAddDataset: Story = { datasetRepository={new DatasetMockRepository()} metadataBlockInfoRepository={new MetadataBlockInfoMockRepository()} collectionRepository={collectionRepositoryWithoutPermissionsToCreateDataset} + collectionId={'collectionId'} /> ) } diff --git a/src/stories/layout/header/Header.stories.tsx b/src/stories/layout/header/Header.stories.tsx index 83fb841ee..aef730840 100644 --- a/src/stories/layout/header/Header.stories.tsx +++ b/src/stories/layout/header/Header.stories.tsx @@ -2,6 +2,7 @@ import type { Meta, StoryObj } from '@storybook/react' import { WithI18next } from '../../WithI18next' import { Header } from '../../../sections/layout/header/Header' import { WithLoggedInUser } from '../../WithLoggedInUser' +import { CollectionMockRepository } from '@/stories/collection/CollectionMockRepository' const meta: Meta = { title: 'Layout/Header', @@ -14,13 +15,13 @@ type Story = StoryObj export const LoggedOut: Story = { render: () => { - return
    + return
    } } export const LoggedIn: Story = { decorators: [WithLoggedInUser], render: () => { - return
    + return
    } } diff --git a/src/stories/shared/add-data-actions/AddDataActionsButton.stories.tsx b/src/stories/shared/add-data-actions/AddDataActionsButton.stories.tsx index 1da6ce4f7..77df60b5a 100644 --- a/src/stories/shared/add-data-actions/AddDataActionsButton.stories.tsx +++ b/src/stories/shared/add-data-actions/AddDataActionsButton.stories.tsx @@ -1,7 +1,8 @@ import { Meta, StoryObj } from '@storybook/react' import { WithI18next } from '../../WithI18next' import AddDataActionsButton from '../../../sections/shared/add-data-actions/AddDataActionsButton' -import { ROOT_COLLECTION_ALIAS } from '../../../collection/domain/models/Collection' + +import { ROOT_COLLECTION_ALIAS } from '@tests/e2e-integration/shared/collection/ROOT_COLLECTION_ALIAS' const meta: Meta = { title: 'Sections/Shared/AddDataActions/AddDataActionsButton', diff --git a/tests/component/sections/account/Account.spec.tsx b/tests/component/sections/account/Account.spec.tsx index 77fc048eb..3a3176ba4 100644 --- a/tests/component/sections/account/Account.spec.tsx +++ b/tests/component/sections/account/Account.spec.tsx @@ -1,14 +1,16 @@ import { Account } from '../../../../src/sections/account/Account' +import { AccountHelper } from '../../../../src/sections/account/AccountHelper' describe('Account', () => { - it('should render the correct breadcrumbs', () => { - cy.mountAuthenticated() + it('should render the component', () => { + cy.mountAuthenticated( + + ) - cy.findByRole('link', { name: 'Root' }).should('exist') - - cy.get('li[aria-current="page"]') - .should('exist') - .should('have.text', 'Account') - .should('have.class', 'active') + cy.get('h1').should('contain.text', 'Account') + cy.findByRole('tab', { name: 'My Data' }).should('exist').and('be.disabled') + cy.findByRole('tab', { name: 'Account Information' }).should('exist').and('be.disabled') + cy.findByRole('tab', { name: 'Notifications' }).should('exist').and('be.disabled') + cy.findByRole('tab', { name: 'API Token' }).should('be.enabled') }) }) diff --git a/tests/component/sections/collection/Collection.spec.tsx b/tests/component/sections/collection/Collection.spec.tsx index 8ce5aedc7..fdb80ac37 100644 --- a/tests/component/sections/collection/Collection.spec.tsx +++ b/tests/component/sections/collection/Collection.spec.tsx @@ -32,7 +32,7 @@ describe('Collection page', () => { cy.customMount( { cy.customMount( { cy.customMount( { cy.customMount( { cy.customMount( { cy.mountAuthenticated( { cy.customMount( { cy.customMount( { cy.mountAuthenticated( { const { result } = renderHook(() => useGetCollectionFacets({ collectionRepository, - collectionId: ROOT_COLLECTION_ALIAS + collectionId: 'collectionId' }) ) @@ -37,7 +36,7 @@ describe('useGetCollectionFacets', () => { const { result } = renderHook(() => useGetCollectionFacets({ collectionRepository, - collectionId: ROOT_COLLECTION_ALIAS + collectionId: 'collectionId' }) ) @@ -58,7 +57,7 @@ describe('useGetCollectionFacets', () => { const { result } = renderHook(() => useGetCollectionFacets({ collectionRepository, - collectionId: ROOT_COLLECTION_ALIAS + collectionId: 'collectionId' }) ) diff --git a/tests/component/sections/create-dataset/CreateDataset.spec.tsx b/tests/component/sections/create-dataset/CreateDataset.spec.tsx index 159942511..99deb0f20 100644 --- a/tests/component/sections/create-dataset/CreateDataset.spec.tsx +++ b/tests/component/sections/create-dataset/CreateDataset.spec.tsx @@ -16,7 +16,7 @@ const collectionMetadataBlocksInfo = MetadataBlockInfoMother.getByCollectionIdDisplayedOnCreateTrue() const COLLECTION_NAME = 'Collection Name' -const collection = CollectionMother.create({ name: COLLECTION_NAME }) +const collection = CollectionMother.create({ name: COLLECTION_NAME, id: 'test-alias' }) describe('Create Dataset', () => { beforeEach(() => { @@ -36,6 +36,7 @@ describe('Create Dataset', () => { datasetRepository={datasetRepository} metadataBlockInfoRepository={metadataBlockInfoRepository} collectionRepository={collectionRepository} + collectionId={'non-existing-collection'} /> ) cy.findByText('Page Not Found').should('exist') @@ -52,6 +53,7 @@ describe('Create Dataset', () => { datasetRepository={datasetRepository} metadataBlockInfoRepository={metadataBlockInfoRepository} collectionRepository={collectionRepository} + collectionId={'test-collectionId'} /> ) cy.clock() @@ -67,6 +69,7 @@ describe('Create Dataset', () => { datasetRepository={datasetRepository} metadataBlockInfoRepository={metadataBlockInfoRepository} collectionRepository={collectionRepository} + collectionId={'test-collectionId'} /> ) @@ -78,18 +81,6 @@ describe('Create Dataset', () => { .should('have.class', 'active') }) - it('renders the Host Collection Form for root collection', () => { - cy.customMount( - - ) - cy.findByText(/^Host Collection/i).should('exist') - cy.findByDisplayValue('root').should('exist') - }) - it('renders the Host Collection Form', () => { cy.customMount( @@ -102,7 +93,7 @@ describe('Create Dataset', () => { ) cy.findByText(/^Host Collection/i).should('exist') - cy.findByDisplayValue('test-collectionId').should('exist') + cy.findByDisplayValue('test-alias').should('exist') cy.findByText(/^Edit Host Collection/i) .should('exist') .click() @@ -123,6 +114,7 @@ describe('Create Dataset', () => { datasetRepository={datasetRepository} metadataBlockInfoRepository={metadataBlockInfoRepository} collectionRepository={collectionRepository} + collectionId={'test-collectionId'} /> ) cy.findAllByTestId('not-allowed-to-create-dataset-alert').should('exist') @@ -134,6 +126,7 @@ describe('Create Dataset', () => { datasetRepository={datasetRepository} metadataBlockInfoRepository={metadataBlockInfoRepository} collectionRepository={collectionRepository} + collectionId={'test-collectionId'} /> ) cy.findAllByTestId('not-allowed-to-create-dataset-alert').should('not.exist') diff --git a/tests/component/sections/layout/header/Header.spec.tsx b/tests/component/sections/layout/header/Header.spec.tsx index f74b956ef..fe10d19e7 100644 --- a/tests/component/sections/layout/header/Header.spec.tsx +++ b/tests/component/sections/layout/header/Header.spec.tsx @@ -2,19 +2,24 @@ import { UserMother } from '../../../users/domain/models/UserMother' import { UserRepository } from '../../../../../src/users/domain/repositories/UserRepository' import { Header } from '../../../../../src/sections/layout/header/Header' import { SessionProvider } from '../../../../../src/sections/session/SessionProvider' +import { CollectionMother } from '@tests/component/collection/domain/models/CollectionMother' +import { CollectionRepository } from '@/collection/domain/repositories/CollectionRepository' const testUser = UserMother.create() +const rootCollection = CollectionMother.create({ id: 'root' }) const userRepository: UserRepository = {} as UserRepository +const collectionRepository: CollectionRepository = {} as CollectionRepository describe('Header component', () => { beforeEach(() => { userRepository.getAuthenticated = cy.stub().resolves(testUser) userRepository.removeAuthenticated = cy.stub().resolves() + collectionRepository.getById = cy.stub().resolves(rootCollection) }) it('displays the brand', () => { cy.customMount( -
    +
    ) @@ -25,7 +30,7 @@ describe('Header component', () => { it('displays the user name when the user is logged in', () => { cy.customMount( -
    +
    ) @@ -40,7 +45,7 @@ describe('Header component', () => { it('displays the Add Data Button when the user is logged in', () => { cy.customMount( -
    +
    ) @@ -59,7 +64,7 @@ describe('Header component', () => { cy.customMount( -
    +
    ) @@ -76,7 +81,7 @@ describe('Header component', () => { cy.customMount( -
    +
    ) @@ -89,7 +94,7 @@ describe('Header component', () => { it('log outs the user after clicking Log Out', () => { cy.customMount( -
    +
    ) diff --git a/tests/component/sections/layout/header/LoggedInHeaderActions.spec.tsx b/tests/component/sections/layout/header/LoggedInHeaderActions.spec.tsx index 26751e0ee..9a172df70 100644 --- a/tests/component/sections/layout/header/LoggedInHeaderActions.spec.tsx +++ b/tests/component/sections/layout/header/LoggedInHeaderActions.spec.tsx @@ -14,7 +14,7 @@ describe('LoggedInHeaderActions', () => { canAddCollection: false }) ) - + collectionRepository.getById = cy.stub().resolves(CollectionMother.create()) cy.customMount( ) diff --git a/tests/component/sections/shared/add-data-actions/AddDataActionsButton.spec.tsx b/tests/component/sections/shared/add-data-actions/AddDataActionsButton.spec.tsx index bdd636346..43407b797 100644 --- a/tests/component/sections/shared/add-data-actions/AddDataActionsButton.spec.tsx +++ b/tests/component/sections/shared/add-data-actions/AddDataActionsButton.spec.tsx @@ -2,7 +2,13 @@ import AddDataActionsButton from '../../../../../src/sections/shared/add-data-ac describe('AddDataActionsButton', () => { it('renders the button', () => { - cy.customMount() + cy.customMount( + + ) cy.findByRole('button', { name: /Add Data/i }).should('exist') cy.findByRole('button', { name: /Add Data/ }).click() @@ -10,15 +16,6 @@ describe('AddDataActionsButton', () => { cy.findByText('New Dataset').should('be.visible') }) - it('renders the new dataset button with the correct generated link', () => { - cy.customMount() - - cy.findByRole('button', { name: /Add Data/i }).click() - cy.findByText('New Dataset') - .should('be.visible') - .should('have.attr', 'href', '/datasets/root/create') - }) - it('renders the new dataset button with the correct generated link for specified collectionId', () => { const collectionId = 'some-collection-id' cy.customMount( @@ -36,7 +33,14 @@ describe('AddDataActionsButton', () => { }) it('shows New Collection button enabled if user has permissions to create collection', () => { - cy.customMount() + const collectionId = 'some-collection-id' + cy.customMount( + + ) cy.findByRole('button', { name: /Add Data/i }).as('addDataBtn') cy.get('@addDataBtn').should('exist') @@ -47,7 +51,14 @@ describe('AddDataActionsButton', () => { }) it('shows New Dataset button enabled if user has permissions to create dataset', () => { - cy.customMount() + const collectionId = 'some-collection-id' + cy.customMount( + + ) cy.findByRole('button', { name: /Add Data/i }).as('addDataBtn') cy.get('@addDataBtn').should('exist') @@ -58,7 +69,14 @@ describe('AddDataActionsButton', () => { }) it('shows New Collection button disabled if user does not have permissions to create collection', () => { - cy.customMount() + const collectionId = 'some-collection-id' + cy.customMount( + + ) cy.findByRole('button', { name: /Add Data/i }).as('addDataBtn') cy.get('@addDataBtn').should('exist') @@ -69,7 +87,14 @@ describe('AddDataActionsButton', () => { }) it('shows New Dataset button disabled if user does not have permissions to create dataset', () => { - cy.customMount() + const collectionId = 'some-collection-id' + cy.customMount( + + ) cy.findByRole('button', { name: /Add Data/i }).as('addDataBtn') cy.get('@addDataBtn').should('exist') diff --git a/tests/e2e-integration/e2e/sections/collection/Collection.spec.ts b/tests/e2e-integration/e2e/sections/collection/Collection.spec.ts index 8af6e0b6f..03bcf7b5b 100644 --- a/tests/e2e-integration/e2e/sections/collection/Collection.spec.ts +++ b/tests/e2e-integration/e2e/sections/collection/Collection.spec.ts @@ -38,7 +38,6 @@ describe('Collection Page', () => { cy.wrap(CollectionHelper.create(uniqueCollectionId)) .its('id') .then((collectionId: string) => { - console.log('collectionId', collectionId) cy.visit(`/spa/collections/${collectionId}`) cy.findByText('Unpublished').should('exist') cy.findByRole('button', { name: 'Publish' }).click() diff --git a/tests/e2e-integration/shared/collection/CollectionHelper.ts b/tests/e2e-integration/shared/collection/CollectionHelper.ts index 5fab95465..ebca9d668 100644 --- a/tests/e2e-integration/shared/collection/CollectionHelper.ts +++ b/tests/e2e-integration/shared/collection/CollectionHelper.ts @@ -43,7 +43,6 @@ export class CollectionHelper extends DataverseApiHelper { } static async createAndPublish(id = 'subcollection'): Promise { const collectionResponse = await CollectionHelper.create(id) - console.log(collectionResponse) if (!collectionResponse.isReleased) { await CollectionHelper.publish(collectionResponse.id) } diff --git a/tests/e2e-integration/shared/collection/ROOT_COLLECTION_ALIAS.ts b/tests/e2e-integration/shared/collection/ROOT_COLLECTION_ALIAS.ts new file mode 100644 index 000000000..2160f412a --- /dev/null +++ b/tests/e2e-integration/shared/collection/ROOT_COLLECTION_ALIAS.ts @@ -0,0 +1 @@ +export const ROOT_COLLECTION_ALIAS = 'root' diff --git a/tests/e2e-integration/shared/datasets/DatasetHelper.ts b/tests/e2e-integration/shared/datasets/DatasetHelper.ts index faba4c5e1..219b059e8 100644 --- a/tests/e2e-integration/shared/datasets/DatasetHelper.ts +++ b/tests/e2e-integration/shared/datasets/DatasetHelper.ts @@ -3,7 +3,8 @@ import { DataverseApiHelper } from '../DataverseApiHelper' import { FileData } from '../files/FileHelper' import { DatasetLockReason } from '../../../../src/dataset/domain/models/Dataset' import { TestsUtils } from '../TestsUtils' -import { ROOT_COLLECTION_ALIAS } from '../../../../src/collection/domain/models/Collection' + +import { ROOT_COLLECTION_ALIAS } from '@tests/e2e-integration/shared/collection/ROOT_COLLECTION_ALIAS' export interface DatasetResponse { persistentId: string