Skip to content

Commit

Permalink
feat(DatasetActionButtons): add stories
Browse files Browse the repository at this point in the history
  • Loading branch information
MellyGray committed Sep 14, 2023
1 parent 750688d commit 068c6b9
Show file tree
Hide file tree
Showing 11 changed files with 274 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ $navbar-brand-font-size: $dv-brand-font-size;
}

.dropdown-menu > .dropdown > .dropdown-toggle {
width: 100%;
text-align: start;
background-color: transparent;
border-color: transparent;
}
Expand Down
2 changes: 2 additions & 0 deletions src/stories/WithSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export const WithSettings = (Story: StoryFn) => {
'Final Approval'
]) as Setting<T>
)
case SettingName.HAS_PUBLIC_STORE:
return Promise.resolve(SettingMother.createHasPublicStore(false) as Setting<T>)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export const WithPublishPermissions: Story = {
<DatasetActionButtons
dataset={DatasetMother.create({
permissions: DatasetPermissionsMother.createWithAllAllowed(),
version: DatasetVersionMother.createDraftAsLatestVersion()
version: DatasetVersionMother.createDraftAsLatestVersion(),
hasValidTermsOfAccess: true,
isValid: true,
isReleased: true
})}
/>
)
Expand All @@ -37,7 +40,10 @@ export const WithNoDatasetPermissions: Story = {
<DatasetActionButtons
dataset={DatasetMother.create({
permissions: DatasetPermissionsMother.createWithNoDatasetPermissions(),
version: DatasetVersionMother.createDraftAsLatestVersion()
version: DatasetVersionMother.createDraftAsLatestVersion(),
hasValidTermsOfAccess: true,
isValid: true,
isReleased: true
})}
/>
)
Expand All @@ -52,7 +58,10 @@ export const WithUpdateAndNoPublishDatasetPermissions: Story = {
canPublishDataset: false,
canUpdateDataset: true
}),
version: DatasetVersionMother.createDraftAsLatestVersion()
version: DatasetVersionMother.createDraftAsLatestVersion(),
hasValidTermsOfAccess: true,
isValid: true,
isReleased: true
})}
/>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Meta, StoryObj } from '@storybook/react'
import { WithI18next } from '../../../WithI18next'
import { WithSettings } from '../../../WithSettings'
import {
DatasetPermissionsMother,
DatasetVersionMother
} from '../../../../../tests/component/dataset/domain/models/DatasetMother'
import { AccessDatasetMenu } from '../../../../sections/dataset/dataset-action-buttons/access-dataset-menu/AccessDatasetMenu'

const meta: Meta<typeof AccessDatasetMenu> = {
title: 'Sections/Dataset Page/DatasetActionButtons/AccessDatasetMenu',
component: AccessDatasetMenu,
decorators: [WithI18next, WithSettings],
parameters: {
// Sets the delay for all stories.
chromatic: { delay: 15000, pauseAnimationAtEnd: true }
}
}

export default meta
type Story = StoryObj<typeof AccessDatasetMenu>

export const WithAllPermissions: Story = {
render: () => (
<AccessDatasetMenu
version={DatasetVersionMother.createReleased()}
permissions={DatasetPermissionsMother.createWithAllAllowed()}
/>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Meta, StoryObj } from '@storybook/react'
import { WithI18next } from '../../../WithI18next'
import { WithSettings } from '../../../WithSettings'
import {
DatasetMother,
DatasetPermissionsMother
} from '../../../../../tests/component/dataset/domain/models/DatasetMother'
import { EditDatasetMenu } from '../../../../sections/dataset/dataset-action-buttons/edit-dataset-menu/EditDatasetMenu'

const meta: Meta<typeof EditDatasetMenu> = {
title: 'Sections/Dataset Page/DatasetActionButtons/EditDatasetMenu',
component: EditDatasetMenu,
decorators: [WithI18next, WithSettings],
parameters: {
// Sets the delay for all stories.
chromatic: { delay: 15000, pauseAnimationAtEnd: true }
}
}

export default meta
type Story = StoryObj<typeof EditDatasetMenu>

export const WithAllPermissions: Story = {
render: () => (
<EditDatasetMenu
dataset={DatasetMother.create({
permissions: DatasetPermissionsMother.createWithAllAllowed(),
hasValidTermsOfAccess: true
})}
/>
)
}

export const WithManagePermissionsNotAllowed: Story = {
render: () => (
<EditDatasetMenu
dataset={DatasetMother.create({
permissions: DatasetPermissionsMother.createWithManagePermissionsNotAllowed(),
hasValidTermsOfAccess: true
})}
/>
)
}

export const WithNoValidTermsOfAccess: Story = {
render: () => (
<EditDatasetMenu
dataset={DatasetMother.create({
permissions: DatasetPermissionsMother.createWithAllAllowed(),
hasValidTermsOfAccess: false
})}
/>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Meta, StoryObj } from '@storybook/react'
import { WithI18next } from '../../../WithI18next'
import { WithSettings } from '../../../WithSettings'
import { DatasetMother } from '../../../../../tests/component/dataset/domain/models/DatasetMother'
import { LinkDatasetButton } from '../../../../sections/dataset/dataset-action-buttons/link-dataset-button/LinkDatasetButton'

const meta: Meta<typeof LinkDatasetButton> = {
title: 'Sections/Dataset Page/DatasetActionButtons/LinkDatasetButton',
component: LinkDatasetButton,
decorators: [WithI18next, WithSettings],
parameters: {
// Sets the delay for all stories.
chromatic: { delay: 15000, pauseAnimationAtEnd: true }
}
}

export default meta
type Story = StoryObj<typeof LinkDatasetButton>

export const ReleasedDataset: Story = {
render: () => <LinkDatasetButton dataset={DatasetMother.create({ isReleased: true })} />
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Meta, StoryObj } from '@storybook/react'
import { WithI18next } from '../../../WithI18next'
import { WithSettings } from '../../../WithSettings'
import {
DatasetMother,
DatasetPermissionsMother,
DatasetVersionMother
} from '../../../../../tests/component/dataset/domain/models/DatasetMother'
import { PublishDatasetMenu } from '../../../../sections/dataset/dataset-action-buttons/publish-dataset-menu/PublishDatasetMenu'

const meta: Meta<typeof PublishDatasetMenu> = {
title: 'Sections/Dataset Page/DatasetActionButtons/PublishDatasetMenu',
component: PublishDatasetMenu,
decorators: [WithI18next, WithSettings],
parameters: {
// Sets the delay for all stories.
chromatic: { delay: 15000, pauseAnimationAtEnd: true }
}
}

export default meta
type Story = StoryObj<typeof PublishDatasetMenu>

export const PublishingAllowed: Story = {
render: () => (
<PublishDatasetMenu
dataset={DatasetMother.create({
version: DatasetVersionMother.createDraftAsLatestVersion(),
permissions: DatasetPermissionsMother.createWithPublishingDatasetAllowed(),
locks: [],
hasValidTermsOfAccess: true,
isValid: true
})}
/>
)
}

export const NoValidTermsOfAccess: Story = {
render: () => (
<PublishDatasetMenu
dataset={DatasetMother.create({
version: DatasetVersionMother.createDraftAsLatestVersion(),
permissions: DatasetPermissionsMother.createWithPublishingDatasetAllowed(),
locks: [],
hasValidTermsOfAccess: false,
isValid: true
})}
/>
)
}

export const DatasetInReview: Story = {
render: () => (
<PublishDatasetMenu
dataset={DatasetMother.create({
version: DatasetVersionMother.createDraftAsLatestVersionInReview(),
permissions: DatasetPermissionsMother.createWithPublishingDatasetAllowed(),
locks: [],
hasValidTermsOfAccess: true,
isValid: true
})}
/>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { Meta, StoryObj } from '@storybook/react'
import { WithI18next } from '../../../WithI18next'
import { WithSettings } from '../../../WithSettings'
import {
DatasetLockMother,
DatasetMother,
DatasetPermissionsMother,
DatasetVersionMother
} from '../../../../../tests/component/dataset/domain/models/DatasetMother'
import { SubmitForReviewButton } from '../../../../sections/dataset/dataset-action-buttons/submit-for-review-button/SubmitForReviewButton'

const meta: Meta<typeof SubmitForReviewButton> = {
title: 'Sections/Dataset Page/DatasetActionButtons/SubmitForReviewButton',
component: SubmitForReviewButton,
decorators: [WithI18next, WithSettings],
parameters: {
// Sets the delay for all stories.
chromatic: { delay: 15000, pauseAnimationAtEnd: true }
}
}

export default meta
type Story = StoryObj<typeof SubmitForReviewButton>

export const CanSubmitForReview: Story = {
render: () => (
<SubmitForReviewButton
dataset={DatasetMother.create({
version: DatasetVersionMother.createDraftAsLatestVersion(),
permissions: DatasetPermissionsMother.create({
canUpdateDataset: true,
canPublishDataset: false
}),
locks: [],
hasValidTermsOfAccess: true,
isValid: true
})}
/>
)
}

export const AlreadySubmittedForReview: Story = {
render: () => (
<SubmitForReviewButton
dataset={DatasetMother.create({
version: DatasetVersionMother.createDraftAsLatestVersionInReview(),
permissions: DatasetPermissionsMother.create({
canUpdateDataset: true,
canPublishDataset: false
}),
locks: [DatasetLockMother.createLockedInReview()]
})}
/>
)
}

export const NoValidTermsOfAccess: Story = {
render: () => (
<SubmitForReviewButton
dataset={DatasetMother.create({
version: DatasetVersionMother.createDraftAsLatestVersion(),
permissions: DatasetPermissionsMother.create({
canUpdateDataset: true,
canPublishDataset: false
}),
locks: [],
hasValidTermsOfAccess: false,
isValid: true
})}
/>
)
}
15 changes: 11 additions & 4 deletions tests/component/dataset/domain/models/DatasetMother.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,24 @@ export class DatasetPermissionsMother {
return this.create({ canManageDatasetPermissions: false, canManageFilesPermissions: false })
}

static createWithManagePermissionsAllowed(): DatasetPermissions {
return this.create({ canManageDatasetPermissions: true, canManageFilesPermissions: true })
}

static createWithDeleteDatasetAllowed(): DatasetPermissions {
return this.create({ canDeleteDataset: true })
}

static createWithDeleteDatasetNotAllowed(): DatasetPermissions {
return this.create({ canDeleteDataset: false })
}

static createWithNoneAllowed(): DatasetPermissions {
return this.create({
canDownloadFiles: false,
canUpdateDataset: false,
canPublishDataset: false,
canManageDatasetPermissions: false,
canManageFilesPermissions: false,
canDeleteDataset: false
})
}
}

export class DatasetLockMother {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ describe('EditDatasetMenu', () => {
permissions: DatasetPermissionsMother.createWithAllAllowed(),
locks: [],
hasValidTermsOfAccess: true,
version: DatasetVersionMother.createReleasedWithLatestVersionIsADraft()
version: DatasetVersionMother.createReleasedWithLatestVersionIsADraft(),
isReleased: true
})

cy.customMount(<EditDatasetMenu dataset={dataset} />)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ describe('SubmitForReviewButton', () => {
canUpdateDataset: true,
canPublishDataset: false
}),
locks: []
locks: [],
hasValidTermsOfAccess: true,
isValid: true
})

cy.customMount(<SubmitForReviewButton dataset={dataset} />)
Expand Down

0 comments on commit 068c6b9

Please sign in to comment.