Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MMT-3554: As a user, I want to be able to download publish record #1116

Merged
merged 12 commits into from
Feb 6, 2024
28 changes: 28 additions & 0 deletions static/src/js/components/PublishPreview/PublishPreview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Page from '../Page/Page'
import useAppContext from '../../hooks/useAppContext'
import useIngestDraftMutation from '../../hooks/useIngestDraftMutation'
import removeMetadataKeys from '../../utils/removeMetadataKeys'
import constructDownloadableFile from '../../utils/constructDownloadableFile'

/**
* Renders a PublishPreview component
Expand Down Expand Up @@ -122,6 +123,13 @@ const PublishPreview = () => {
ingestMutation(derivedConceptType, ummMetadata, cloneNativeId, providerId)
}

// Handles the user selecting download record
const handleDownload = () => {
const contents = JSON.stringify(ummMetadata)

constructDownloadableFile(contents, conceptId)
}

// Handles the user selecting delete from the delete model
const handleDelete = () => {
deleteMutation({
Expand Down Expand Up @@ -180,6 +188,7 @@ const PublishPreview = () => {
<Page>
<Row>
<Col className="mb-5" md={12}>
{/* Edit Publish record link */}
<Button
className="btn btn-link"
type="button"
Expand All @@ -196,6 +205,7 @@ const PublishPreview = () => {
{' '}
Record
</Button>
{/* Clone Publish record link */}
<Button
className="btn btn-link"
type="button"
Expand All @@ -212,6 +222,24 @@ const PublishPreview = () => {
{' '}
Record
</Button>
{/* Download Publish record link */}
<Button
className="btn btn-link"
type="button"
variant="link"
onClick={
() => {
handleDownload()
}
}
>
Download
{' '}
{derivedConceptType}
{' '}
Record
</Button>
{/* Delete Publish record button */}
<Button
type="button"
variant="outline-danger"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import MetadataPreview from '../../MetadataPreview/MetadataPreview'
import PublishPreview from '../PublishPreview'
import errorLogger from '../../../utils/errorLogger'
import ErrorBanner from '../../ErrorBanner/ErrorBanner'
import constructDownloadableFile from '../../../utils/constructDownloadableFile'
import { GET_TOOL } from '../../../operations/queries/getTool'
import { DELETE_TOOL } from '../../../operations/mutations/deleteTool'
import { INGEST_DRAFT } from '../../../operations/mutations/ingestDraft'

jest.mock('../../../utils/constructDownloadableFile')
jest.mock('../../MetadataPreview/MetadataPreview')
jest.mock('../../ErrorBanner/ErrorBanner')
jest.mock('../../../utils/errorLogger')
Expand Down Expand Up @@ -489,4 +491,23 @@ describe('PublishPreview', () => {
expect(navigateSpy).toHaveBeenCalledWith('/drafts/tools/TD1000000-MMT')
})
})

describe('when clicking on Download Tool Record button', () => {
test('downloads the Tool Record', async () => {
const { user } = setup({})

await waitForResponse()

const downloadButton = screen.getByRole('button', { name: 'Download Tool Record' })
await user.click(downloadButton)

await waitForResponse()

expect(constructDownloadableFile).toHaveBeenCalledTimes(1)
expect(constructDownloadableFile).toHaveBeenCalledWith(
JSON.stringify(mock.ummMetadata, null, 2),
'T1000000-MMT'
)
})
})
})
Loading