Skip to content

Commit 898d1fb

Browse files
authored
MMT-3995: As a user, I can edit Visualization Information and Science Keywords (#1362)
* MMT-3995: As a user, I can edit Visualization Information and Science Keywords * MMT-3995: Fixing test * MMT-3995: Code Coverage * MMT-3995: Addressing PR feedback * MMT-3995: Creating work around * MMT-3995: Adding test files * MMT-3995: Removing console.log
1 parent 18976b3 commit 898d1fb

File tree

13 files changed

+760
-20
lines changed

13 files changed

+760
-20
lines changed

static/src/js/components/MetadataForm/MetadataForm.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import getFormSchema from '@/js/utils/getFormSchema'
4545
import getNextFormName from '@/js/utils/getNextFormName'
4646
import getUiSchema from '@/js/utils/getUiSchema'
4747
import getUmmSchema from '@/js/utils/getUmmSchema'
48+
import getUmmVersion from '@/js/utils/getUmmVersion'
4849
import removeEmpty from '@/js/utils/removeEmpty'
4950
import toKebabCase from '@/js/utils/toKebabCase'
5051

@@ -203,8 +204,7 @@ const MetadataForm = () => {
203204
metadata: removeEmpty(ummMetadata),
204205
nativeId,
205206
providerId: fetchedMetadataProviderId || providerId,
206-
// TODO pull this version number from a config
207-
ummVersion: '1.0.0'
207+
ummVersion: getUmmVersion(derivedConceptType)
208208
},
209209
onCompleted: (mutationData) => {
210210
const { ingestDraft } = mutationData

static/src/js/components/MetadataForm/__tests__/MetadataForm.test.jsx

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import * as router from 'react-router'
2323
import conceptTypeDraftQueries from '@/js/constants/conceptTypeDraftQueries'
2424

2525
import errorLogger from '@/js/utils/errorLogger'
26+
import getUmmVersion from '@/js/utils/getUmmVersion'
2627

2728
import relatedUrlsUiSchema from '@/js/schemas/uiSchemas/tools/relatedUrls'
2829
import toolInformationUiSchema from '@/js/schemas/uiSchemas/tools/toolInformation'
@@ -55,6 +56,30 @@ import { PUBLISH_DRAFT } from '@/js/operations/mutations/publishDraft'
5556

5657
import MetadataForm from '../MetadataForm'
5758

59+
vi.mock('@/js/hooks/usePublishMutation', () => ({
60+
default: vi.fn(() => {
61+
const [publishDraft, setPublishDraft] = React.useState(null)
62+
const [error] = React.useState(null)
63+
64+
const publishMutation = vi.fn(() => new Promise((resolve) => {
65+
setTimeout(() => {
66+
setPublishDraft({
67+
conceptId: 'T1000000-MMT',
68+
revisionId: '1'
69+
})
70+
71+
resolve()
72+
}, 100)
73+
}))
74+
75+
return {
76+
publishMutation,
77+
publishDraft,
78+
error
79+
}
80+
})
81+
}))
82+
5883
vi.mock('@rjsf/core', () => ({
5984
default: vi.fn(({
6085
onChange,
@@ -580,7 +605,7 @@ describe('MetadataForm', () => {
580605
},
581606
nativeId: 'MMT_2331e312-cbbc-4e56-9d6f-fe217464be2c',
582607
providerId: 'MMT_2',
583-
ummVersion: '1.0.0'
608+
ummVersion: getUmmVersion('Tool')
584609
}
585610
},
586611
result: {
@@ -629,7 +654,7 @@ describe('MetadataForm', () => {
629654
},
630655
nativeId: 'MMT_2331e312-cbbc-4e56-9d6f-fe217464be2c',
631656
providerId: 'MMT_2',
632-
ummVersion: '1.0.0'
657+
ummVersion: getUmmVersion('Tool')
633658
}
634659
},
635660
result: {
@@ -675,7 +700,7 @@ describe('MetadataForm', () => {
675700
},
676701
nativeId: 'MMT_2331e312-cbbc-4e56-9d6f-fe217464be2c',
677702
providerId: 'MMT_2',
678-
ummVersion: '1.0.0'
703+
ummVersion: getUmmVersion('Tool')
679704
}
680705
},
681706
result: {
@@ -800,7 +825,7 @@ describe('MetadataForm', () => {
800825
metadata: ummMetadata,
801826
nativeId: 'MMT_2331e312-cbbc-4e56-9d6f-fe217464be2c',
802827
providerId: 'MMT_2',
803-
ummVersion: '1.0.0'
828+
ummVersion: getUmmVersion('Tool')
804829
}
805830
},
806831
result: {
@@ -817,7 +842,7 @@ describe('MetadataForm', () => {
817842
variables: {
818843
draftConceptId: 'TD1000000-MMT',
819844
nativeId: 'MMT_2331e312-cbbc-4e56-9d6f-fe217464be2c',
820-
ummVersion: '1.2.0'
845+
ummVersion: getUmmVersion('Tool')
821846
}
822847
},
823848
result: {
@@ -838,8 +863,12 @@ describe('MetadataForm', () => {
838863
const button = screen.getByRole('button', { name: 'Save & Publish' })
839864
await user.click(button)
840865

841-
expect(navigateSpy).toHaveBeenCalledTimes(2)
842-
expect(navigateSpy).toHaveBeenCalledWith('/tools/T1000000-MMT')
866+
await waitFor(() => {
867+
expect(navigateSpy).toHaveBeenCalledTimes(2)
868+
}, { timeout: 5000 })
869+
870+
expect(navigateSpy).toHaveBeenNthCalledWith(1, '/drafts/tools/TD1000000-MMT/tool-information?revisionId=1', expect.anything())
871+
expect(navigateSpy).toHaveBeenNthCalledWith(2, '/tools/T1000000-MMT')
843872
})
844873
})
845874

@@ -864,7 +893,7 @@ describe('MetadataForm', () => {
864893
},
865894
nativeId: 'MMT_2331e312-cbbc-4e56-9d6f-fe217464be2c',
866895
providerId: 'MMT_2',
867-
ummVersion: '1.0.0'
896+
ummVersion: getUmmVersion('Tool')
868897
}
869898
},
870899
error: new Error('An error occured')
@@ -882,6 +911,10 @@ describe('MetadataForm', () => {
882911
})
883912

884913
describe('when saving a new draft', () => {
914+
afterEach(() => {
915+
vi.restoreAllMocks()
916+
})
917+
885918
test('navigates to the current form and calls scrolls to the top', async () => {
886919
const navigateSpy = vi.fn()
887920
vi.spyOn(router, 'useNavigate').mockImplementation(() => navigateSpy)
@@ -928,7 +961,7 @@ describe('MetadataForm', () => {
928961
},
929962
nativeId: 'MMT_mock-uuid',
930963
providerId: 'MMT_1',
931-
ummVersion: '1.0.0'
964+
ummVersion: getUmmVersion('Collection')
932965
}
933966
},
934967
result: {

0 commit comments

Comments
 (0)