-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(EditFilesMenu): add dataset permissions
- Loading branch information
Showing
7 changed files
with
67 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 60 additions & 61 deletions
121
...ons/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesMenu.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,101 @@ | ||
import { EditFilesMenu } from '../../../../../../../../src/sections/dataset/dataset-files/files-table/file-actions/edit-files-menu/EditFilesMenu' | ||
import { UserMother } from '../../../../../../users/domain/models/UserMother' | ||
import { UserRepository } from '../../../../../../../../src/users/domain/repositories/UserRepository' | ||
import { SessionProvider } from '../../../../../../../../src/sections/session/SessionProvider' | ||
import { FileMother } from '../../../../../../files/domain/models/FileMother' | ||
import { FileRepository } from '../../../../../../../../src/files/domain/repositories/FileRepository' | ||
import { FileUserPermissionsMother } from '../../../../../../files/domain/models/FileUserPermissionsMother' | ||
import { FilePermissionsProvider } from '../../../../../../../../src/sections/file/file-permissions/FilePermissionsProvider' | ||
import { ReactNode } from 'react' | ||
import { Dataset as DatasetModel } from '../../../../../../../../src/dataset/domain/models/Dataset' | ||
import { DatasetProvider } from '../../../../../../../../src/sections/dataset/DatasetProvider' | ||
import { DatasetRepository } from '../../../../../../../../src/dataset/domain/repositories/DatasetRepository' | ||
import { | ||
DatasetLockMother, | ||
DatasetMother, | ||
DatasetPermissionsMother | ||
} from '../../../../../../dataset/domain/models/DatasetMother' | ||
|
||
const user = UserMother.create() | ||
const userRepository = {} as UserRepository | ||
const datasetRepository: DatasetRepository = {} as DatasetRepository | ||
const datasetWithUpdatePermissions = DatasetMother.create({ | ||
permissions: DatasetPermissionsMother.createWithUpdateDatasetAllowed(), | ||
hasValidTermsOfAccess: true | ||
}) | ||
const files = FileMother.createMany(2) | ||
const fileRepository: FileRepository = {} as FileRepository | ||
describe('EditFilesMenu', () => { | ||
beforeEach(() => { | ||
userRepository.getAuthenticated = cy.stub().resolves(user) | ||
userRepository.removeAuthenticated = cy.stub().resolves() | ||
fileRepository.getUserPermissionsById = cy.stub().resolves( | ||
FileUserPermissionsMother.create({ | ||
fileId: files[0].id, | ||
canEditDataset: true | ||
}) | ||
const withDataset = (component: ReactNode, dataset: DatasetModel | undefined) => { | ||
datasetRepository.getByPersistentId = cy.stub().resolves(dataset) | ||
datasetRepository.getByPrivateUrlToken = cy.stub().resolves(dataset) | ||
|
||
return ( | ||
<DatasetProvider | ||
repository={datasetRepository} | ||
searchParams={{ persistentId: 'some-persistent-id', version: 'some-version' }}> | ||
{component} | ||
</DatasetProvider> | ||
) | ||
}) | ||
} | ||
|
||
it('renders the Edit Files menu', () => { | ||
cy.customMount( | ||
<FilePermissionsProvider repository={fileRepository}> | ||
<SessionProvider repository={userRepository}> | ||
<EditFilesMenu files={files} /> | ||
</SessionProvider> | ||
</FilePermissionsProvider> | ||
cy.mountAuthenticated( | ||
withDataset(<EditFilesMenu files={files} />, datasetWithUpdatePermissions) | ||
) | ||
|
||
cy.findByRole('button', { name: 'Edit Files' }).should('exist') | ||
}) | ||
|
||
it('does not render the Edit Files menu when the user is not authenticated', () => { | ||
userRepository.getAuthenticated = cy.stub().resolves(null) | ||
|
||
cy.customMount( | ||
<FilePermissionsProvider repository={fileRepository}> | ||
<SessionProvider repository={userRepository}> | ||
<EditFilesMenu files={files} /> | ||
</SessionProvider> | ||
</FilePermissionsProvider> | ||
) | ||
cy.customMount(withDataset(<EditFilesMenu files={files} />, datasetWithUpdatePermissions)) | ||
|
||
cy.findByRole('button', { name: 'Edit Files' }).should('not.exist') | ||
}) | ||
|
||
it('does not render the Edit Files menu when there are no files in the dataset', () => { | ||
cy.customMount( | ||
<FilePermissionsProvider repository={fileRepository}> | ||
<SessionProvider repository={userRepository}> | ||
<EditFilesMenu files={[]} /> | ||
</SessionProvider> | ||
</FilePermissionsProvider> | ||
) | ||
cy.mountAuthenticated(withDataset(<EditFilesMenu files={[]} />, datasetWithUpdatePermissions)) | ||
|
||
cy.findByRole('button', { name: 'Edit Files' }).should('not.exist') | ||
}) | ||
|
||
it('renders the Edit Files options', () => { | ||
cy.customMount( | ||
<FilePermissionsProvider repository={fileRepository}> | ||
<SessionProvider repository={userRepository}> | ||
<EditFilesMenu files={files} /> | ||
</SessionProvider> | ||
</FilePermissionsProvider> | ||
cy.mountAuthenticated( | ||
withDataset(<EditFilesMenu files={files} />, datasetWithUpdatePermissions) | ||
) | ||
|
||
cy.findByRole('button', { name: 'Edit Files' }).click() | ||
cy.findByRole('button', { name: 'Metadata' }).should('exist') | ||
}) | ||
|
||
it.skip('does not render the Edit Files menu when the user does not have update dataset permissions', () => { | ||
fileRepository.getUserPermissionsById = cy.stub().resolves( | ||
FileUserPermissionsMother.create({ | ||
fileId: files[0].id, | ||
canEditDataset: false | ||
}) | ||
) | ||
it('does not render the Edit Files menu when the user does not have update dataset permissions', () => { | ||
const datasetWithNoUpdatePermissions = DatasetMother.create({ | ||
permissions: DatasetPermissionsMother.createWithUpdateDatasetNotAllowed() | ||
}) | ||
|
||
cy.customMount( | ||
<FilePermissionsProvider repository={fileRepository}> | ||
<SessionProvider repository={userRepository}> | ||
<EditFilesMenu files={files} /> | ||
</SessionProvider> | ||
</FilePermissionsProvider> | ||
cy.mountAuthenticated( | ||
withDataset(<EditFilesMenu files={files} />, datasetWithNoUpdatePermissions) | ||
) | ||
|
||
cy.findByRole('button', { name: 'Edit Files' }).should('not.exist') | ||
}) | ||
|
||
it.skip('renders the disabled Edit Files menu when the dataset is locked from edits', () => { | ||
// TODO: Implement this test | ||
it('renders the disabled Edit Files menu when the dataset is locked from edits', () => { | ||
const datasetWithUpdatePermissions = DatasetMother.create({ | ||
permissions: DatasetPermissionsMother.createWithUpdateDatasetAllowed(), | ||
locks: [DatasetLockMother.createLockedInEditInProgress()] | ||
}) | ||
|
||
cy.mountAuthenticated( | ||
withDataset(<EditFilesMenu files={files} />, datasetWithUpdatePermissions) | ||
) | ||
|
||
cy.findByRole('button', { name: 'Edit Files' }).should('be.disabled') | ||
}) | ||
|
||
it.skip('renders the disabled Edit Files menu when the dataset does not have valid terms of access', () => { | ||
// TODO: Implement this test | ||
it('renders the disabled Edit Files menu when the dataset does not have valid terms of access', () => { | ||
const datasetWithUpdatePermissions = DatasetMother.create({ | ||
permissions: DatasetPermissionsMother.createWithUpdateDatasetAllowed(), | ||
hasValidTermsOfAccess: false | ||
}) | ||
|
||
cy.mountAuthenticated( | ||
withDataset(<EditFilesMenu files={files} />, datasetWithUpdatePermissions) | ||
) | ||
|
||
cy.findByRole('button', { name: 'Edit Files' }).should('be.disabled') | ||
}) | ||
}) |