Skip to content

Commit

Permalink
MMT-3410: Fixing test and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorlang committed Dec 19, 2023
1 parent aea26d7 commit 7dab0a4
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 31 deletions.
2 changes: 1 addition & 1 deletion static/src/js/components/DraftPreview/DraftPreview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ const DraftPreview = () => {
[
{
label: `${derivedConceptType} Drafts`,
to: `/drafts/${derivedConceptType.toLowerCase()}s`,
to: `/drafts/${derivedConceptType.toLowerCase()}s`
},
{
label: name || '<Blank Name>',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
} from 'react-router-dom'
import { ToolPreview } from '@edsc/metadata-preview'
import * as router from 'react-router'
import Breadcrumb from 'react-bootstrap/Breadcrumb'

import ummTSchema from '../../../schemas/umm/ummTSchema'
import toolsConfiguration from '../../../schemas/uiForms/toolsConfiguration'
Expand All @@ -29,7 +28,6 @@ import ErrorBanner from '../../ErrorBanner/ErrorBanner'
import PreviewProgress from '../../PreviewProgress/PreviewProgress'
import Providers from '../../../providers/Providers/Providers'

// jest.mock('react-bootstrap/Breadcrumb')
jest.mock('@edsc/metadata-preview')
jest.mock('../../ErrorBanner/ErrorBanner')
jest.mock('../../PreviewProgress/PreviewProgress')
Expand Down
12 changes: 3 additions & 9 deletions static/src/js/components/For/For.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,9 @@ export const For = ({

For.propTypes = {
children: PropTypes.func.isRequired,
each: PropTypes.arrayOf(
PropTypes.oneOfType(
[
PropTypes.shape(),
PropTypes.string,
PropTypes.number
]
)
).isRequired
// Disabling the following rule to allow undefined to be passed as a value in the array
// eslint-disable-next-line react/forbid-prop-types
each: PropTypes.array.isRequired
}

export default For
14 changes: 8 additions & 6 deletions static/src/js/components/MetadataForm/MetadataForm.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from 'react'
import { useNavigate, useParams } from 'react-router'
import { useMutation, useQuery } from '@apollo/client'
import { kebabCase } from 'lodash'
import { kebabCase } from 'lodash-es'
import validator from '@rjsf/validator-ajv8'
import Col from 'react-bootstrap/Col'
import Container from 'react-bootstrap/Container'
Expand Down Expand Up @@ -287,7 +287,7 @@ const MetadataForm = () => {
])])
}

const { name = '<Blank Name>' } = draft || {}
const name = draft?.name || '<Blank Name>'
const pageTitle = conceptId === 'new' ? `New ${derivedConceptType} Draft` : `Edit ${name}`

return (
Expand All @@ -300,10 +300,12 @@ const MetadataForm = () => {
label: `${derivedConceptType} Drafts`,
to: `/drafts/${draftType}`
},
{
label: name,
to: `/drafts/${draftType}/${conceptId}`
},
(
conceptId !== 'new' && {
label: name,
to: `/drafts/${draftType}/${conceptId}`
}
),
{
label: pageTitle,
active: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const mockDraft = {
conceptId: 'TD1000000-MMT',
conceptType: 'tool-draft',
deleted: false,
name: null,
name: 'Test Name',
nativeId: 'MMT_2331e312-cbbc-4e56-9d6f-fe217464be2c',
providerId: 'MMT_2',
revisionDate: '2023-12-08T16:14:28.177Z',
Expand Down Expand Up @@ -309,7 +309,7 @@ describe('MetadataForm', () => {
})
})

test.skip('renders the breadcrumbs', async () => {
test('renders the breadcrumbs', async () => {
setup({
pageUrl: '/drafts/tools/TD1000000-MMT/related-urls'
})
Expand All @@ -318,7 +318,7 @@ describe('MetadataForm', () => {

const breadcrumbs = screen.getByRole('navigation', { name: 'breadcrumb' })
const breadcrumbOne = within(breadcrumbs).getByText('Tool Drafts')
const breadcrumbTwo = within(breadcrumbs).getByText('Edit TD1000000-MMT')
const breadcrumbTwo = within(breadcrumbs).getByText('Edit Test Name')

expect(breadcrumbOne.href).toEqual('http://localhost/drafts/tools')
expect(breadcrumbTwo).toHaveClass('active')
Expand Down
28 changes: 18 additions & 10 deletions static/src/js/components/Page/Page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,20 @@ const Page = ({
<Breadcrumb>
<For each={breadcrumbs}>
{
({ active, label, to }, i) => (
<Breadcrumb.Item
key={`breadcrumb-link_${to}_${i}`}
active={active}
linkProps={{ to }}
linkAs={Link}
>
{label}
</Breadcrumb.Item>
)
({ active, label, to }, i) => {
if (!label) return null

return (
<Breadcrumb.Item
key={`breadcrumb-link_${to}_${i}`}
active={active}
linkProps={{ to }}
linkAs={Link}
>
{label}
</Breadcrumb.Item>
)
}
}
</For>
</Breadcrumb>
Expand Down Expand Up @@ -174,12 +178,16 @@ const Page = ({
}

Page.defaultProps = {
breadcrumbs: [],
headerActions: [],
pageType: 'primary',
title: null
}

Page.propTypes = {
// Disabling the following rule to allow undefined to be passed as a value in the array
// eslint-disable-next-line react/forbid-prop-types
breadcrumbs: PropTypes.array,
children: PropTypes.node.isRequired,
headerActions: PropTypes.arrayOf(
PropTypes.shape({
Expand Down

0 comments on commit 7dab0a4

Please sign in to comment.