-
Notifications
You must be signed in to change notification settings - Fork 19
Feature/83/create datasummary with markdown #91
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
Merged
kcondon
merged 16 commits into
develop
from
feature/83/create-datasummary-with-markdown
May 17, 2023
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ad1f55c
Created DatasetSummary component, added fields to Dataset model
ekraffmiller 6b23597
Add array of SummaryFields to model, add SanitizedHTML
ekraffmiller c0b93a0
Replace SanitizedHtml with MarkdownComponent
ekraffmiller 43eab7f
Add Cypress test for MarkdownComponent, and remove SanitizedHtml.
ekraffmiller 181291d
Added Licence Row to DatasetSummary
ekraffmiller bbbe9ae
Added alt text to license image
ekraffmiller bc4c7dd
Separate DatasetSummary into smaller components, move interfaces to D…
ekraffmiller fcaa144
Remove SanitizedHtml.test.tsx, fix import in MarkdownComponent.spec.tsx
ekraffmiller 1cec134
fix unit and component tests
ekraffmiller f4d1985
merge with 78-create-the-boilerplate-of-the-dataset-page
ekraffmiller b6bec60
fix datasetSummary folder name, add undefined optional type
ekraffmiller 4c1b37b
added back <Col> element to Dataset.tsx
ekraffmiller 751b37b
add design-system/.nyc_output to .gitignore
ekraffmiller 2061337
Merge branch 'feature/78-create-the-boilerplate-of-the-dataset-page' …
MellyGray 22eb0c6
remove check for null in DatasetSummary components
ekraffmiller f38acee
fix(DatasetSummary): remove check and update Dataset mock
MellyGray File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { DatasetField } from '../../../../src/dataset/domain/models/Dataset' | ||
| import { SummaryFields } from './SummaryFields' | ||
| import { License as LicenseModel } from './../../../../src/dataset/domain/models/Dataset' | ||
| import { License } from './License' | ||
| interface DatasetSummaryProps { | ||
| summaryFields: DatasetField[] | ||
| license: LicenseModel | ||
| } | ||
|
|
||
| export function DatasetSummary({ summaryFields, license }: DatasetSummaryProps) { | ||
| return ( | ||
| <article> | ||
| <SummaryFields summaryFields={summaryFields}></SummaryFields> | ||
| <License license={license}></License> | ||
| </article> | ||
| ) | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { Row, Col } from 'dataverse-design-system' | ||
| import { License as LicenseModel } from '../../../dataset/domain/models/Dataset' | ||
| interface LicenseProps { | ||
| license: LicenseModel | ||
| } | ||
|
|
||
| export function License({ license }: LicenseProps) { | ||
| return ( | ||
| <article> | ||
| <Row> | ||
| <Col sm={3}> | ||
| <b>License/Data Use Agreement</b> | ||
| </Col> | ||
| <Col> | ||
| {' '} | ||
| <img | ||
| alt={license.name + ' license icon'} | ||
| src={license.iconUrl} | ||
| title={license.shortDescription}></img>{' '} | ||
| <a href={license.uri}>{license.name}</a> | ||
| </Col> | ||
| </Row> | ||
| </article> | ||
| ) | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { Row, Col, Tooltip } from 'dataverse-design-system' | ||
| import { MarkdownComponent } from '../markdown/MarkdownComponent' | ||
| import { DatasetField } from '../../../dataset/domain/models/Dataset' | ||
| interface SummaryFieldsProps { | ||
| summaryFields: DatasetField[] | ||
| } | ||
|
|
||
| export function SummaryFields({ summaryFields }: SummaryFieldsProps) { | ||
| return ( | ||
| <article> | ||
| {summaryFields.map((field, index) => ( | ||
| <Row key={index}> | ||
| <Col sm={3}> | ||
| <b>{field.title}</b> <Tooltip placement="right" message={field.description}></Tooltip> | ||
| </Col> | ||
| <Col> | ||
| {' '} | ||
| <MarkdownComponent markdown={field.value} /> | ||
| </Col> | ||
| </Row> | ||
| ))} | ||
| </article> | ||
| ) | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import ReactMarkdown from 'react-markdown' | ||
| import { useRef } from 'react' | ||
| interface Props { | ||
| markdown: string | ||
| } | ||
| export function MarkdownComponent({ markdown }: Props) { | ||
| const containerRef = useRef<HTMLDivElement>(null) | ||
| return ( | ||
| <div ref={containerRef}> | ||
| <ReactMarkdown>{markdown}</ReactMarkdown> | ||
| </div> | ||
| ) | ||
| } |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import type { Meta, StoryObj } from '@storybook/react' | ||
| import { WithI18next } from '../WithI18next' | ||
|
|
||
| import { DatasetSummary } from '../../sections/dataset/dataset-summary/DatasetSummary' | ||
| import { faker } from '@faker-js/faker' | ||
| import { DatasetField, License } from '../../dataset/domain/models/Dataset' | ||
|
|
||
| const meta: Meta<typeof DatasetSummary> = { | ||
| title: 'Sections/Dataset Page/DatasetSummary', | ||
| component: DatasetSummary, | ||
| decorators: [WithI18next] | ||
| } | ||
|
|
||
| const licenseMock: License = { | ||
| name: 'CC0 1.0', | ||
| shortDescription: 'CC0 1.0 Universal Public Domain Dedication', | ||
| uri: 'https://creativecommons.org/publicdomain/zero/1.0/', | ||
| iconUrl: 'https://licensebuttons.net/p/zero/1.0/88x31.png' | ||
| } | ||
| const summaryFieldsMock: DatasetField[] = [ | ||
| { | ||
| title: 'Description', | ||
| description: 'this is the description field', | ||
| value: | ||
| 'This is the description field. Here is [a link](https://dataverse.org). ' + | ||
| 'This text is *italic* and this is **bold**. Here is an image  ' | ||
| }, | ||
| { | ||
| title: 'Keyword', | ||
| description: 'this is the keyword field', | ||
| value: 'Malaria, Tuberculosis, Drug Resistant' | ||
| }, | ||
| { | ||
| title: 'Subject', | ||
| description: 'this is the subject field', | ||
| value: 'Medicine, Health and Life Sciences, Social Sciences' | ||
| }, | ||
| { | ||
| title: 'Related Publication', | ||
| description: 'this is the keyword field', | ||
| value: 'CNN Journal [CNN.com](https://cnn.com)' | ||
| }, | ||
| { | ||
| title: 'Notes', | ||
| description: 'this is the notes field', | ||
| value: faker.lorem.paragraph(3) | ||
| } | ||
| ] | ||
|
|
||
| export default meta | ||
| type Story = StoryObj<typeof DatasetSummary> | ||
|
|
||
| export const Default: Story = { | ||
| render: () => <DatasetSummary summaryFields={summaryFieldsMock} license={licenseMock} /> | ||
| } |
This file contains hidden or 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
50 changes: 50 additions & 0 deletions
50
tests/component/sections/dataset/dataset-summary/DatasetSummary.spec.tsx
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import { DatasetSummary } from '../../../../../src/sections/dataset/dataset-summary/DatasetSummary' | ||
| import { DatasetField, License } from '../../../../../src/dataset/domain/models/Dataset' | ||
| import { faker } from '@faker-js/faker' | ||
|
|
||
| describe('DatasetSummary', () => { | ||
| const licenseMock: License = { | ||
| name: 'CC0 1.0', | ||
| shortDescription: 'CC0 1.0 Universal Public Domain Dedication', | ||
| uri: 'https://creativecommons.org/publicdomain/zero/1.0/', | ||
| iconUrl: 'https://licensebuttons.net/p/zero/1.0/88x31.png' | ||
| } | ||
| const summaryFieldsMock: DatasetField[] = [ | ||
| { | ||
| title: 'Description', | ||
| description: 'this is the description field', | ||
| value: 'This is the description field. This is where we describe the dataset' | ||
| }, | ||
| { | ||
| title: 'Keyword', | ||
| description: 'this is the keyword field', | ||
| value: 'Malaria, Tuberculosis, Drug Resistant' | ||
| }, | ||
| { | ||
| title: 'Subject', | ||
| description: 'this is the subject field', | ||
| value: 'Medicine, Health and Life Sciences, Social Sciences' | ||
| }, | ||
| { | ||
| title: 'Related Publication', | ||
| description: 'this is the keyword field', | ||
| value: 'keyword1, keyword2' | ||
| }, | ||
| { | ||
| title: 'Notes', | ||
| description: 'this is the notes field', | ||
| value: faker.lorem.paragraph(3) | ||
| } | ||
| ] | ||
|
|
||
| it('renders the DatasetSummary fields', () => { | ||
| cy.mount(<DatasetSummary summaryFields={summaryFieldsMock} license={licenseMock} />) | ||
| summaryFieldsMock.map((field) => { | ||
| cy.findByText(field.title).should('exist') | ||
| cy.findByText(field.value).should('exist') | ||
| }) | ||
|
|
||
| cy.get('img').should('exist') | ||
| cy.findByText(licenseMock.name).should('exist') | ||
| }) | ||
| }) |
32 changes: 32 additions & 0 deletions
32
tests/component/sections/dataset/dataset-summary/License.spec.tsx
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { License } from '../../../../../src/sections/dataset/dataset-summary/License' | ||
|
|
||
| describe('DatasetSummary', () => { | ||
| it('renders the license information correctly', () => { | ||
| // Mock license data | ||
| const license = { | ||
| name: 'Test License', | ||
| iconUrl: 'https://example.com/icon.png', | ||
| shortDescription: 'Test description', | ||
| uri: 'https://example.com/license' | ||
| } | ||
|
|
||
| cy.customMount(<License license={license} />) | ||
|
|
||
| // Check if the License component is rendered | ||
| cy.get('article').should('exist') | ||
|
|
||
| // Check if the license name is displayed | ||
| cy.get('article').contains('Test License').should('exist') | ||
| cy.findByText('License/Data Use Agreement').should('exist') | ||
| // Check if the license icon is displayed | ||
| cy.get('img') | ||
| .should('have.attr', 'alt', 'Test License license icon') | ||
| .and('have.attr', 'src', 'https://example.com/icon.png') | ||
| .and('have.attr', 'title', 'Test description') | ||
|
|
||
| // Check if the license link is correct | ||
| cy.get('a') | ||
| .should('have.attr', 'href', 'https://example.com/license') | ||
| .and('have.text', 'Test License') | ||
| }) | ||
| }) |
29 changes: 29 additions & 0 deletions
29
tests/component/sections/dataset/dataset-summary/MarkdownComponent.spec.tsx
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { MarkdownComponent } from '../../../../../src/sections/dataset/markdown/MarkdownComponent' | ||
|
|
||
| describe('MarkdownComponent', () => { | ||
| it('renders Markdown correctly', () => { | ||
| const markdown = | ||
| '# Heading\n\nThis is some **bold** text ' + | ||
| 'This is the description field. Here is [a link](https://dataverse.org). ' + | ||
| ' Here is an image  ' | ||
|
|
||
| cy.customMount(<MarkdownComponent markdown={markdown} />) | ||
| cy.get('h1').should('have.text', 'Heading') | ||
| cy.get('strong').should('have.text', 'bold') | ||
| cy.get('p').should('exist') | ||
| cy.get('a').should('have.attr', 'href').and('eq', 'https://dataverse.org') | ||
| }) | ||
| }) | ||
|
|
||
| it('updates Markdown correctly', () => { | ||
| const initialMarkdown = '# Heading\n\nThis is some **bold** text' | ||
| const updatedMarkdown = '# New heading\n\nThis is some _italic_ text' | ||
| cy.customMount(<MarkdownComponent markdown={initialMarkdown} />) | ||
|
|
||
| cy.get('h1').should('have.text', 'Heading') | ||
| cy.get('strong').should('have.text', 'bold') | ||
| cy.get('p').should('exist') | ||
| cy.customMount(<MarkdownComponent markdown={updatedMarkdown} />) | ||
| cy.get('h1').should('have.text', 'New heading') | ||
| cy.get('em').should('have.text', 'italic') | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.