@@ -23,6 +23,7 @@ import * as router from 'react-router'
2323import conceptTypeDraftQueries from '@/js/constants/conceptTypeDraftQueries'
2424
2525import errorLogger from '@/js/utils/errorLogger'
26+ import getUmmVersion from '@/js/utils/getUmmVersion'
2627
2728import relatedUrlsUiSchema from '@/js/schemas/uiSchemas/tools/relatedUrls'
2829import toolInformationUiSchema from '@/js/schemas/uiSchemas/tools/toolInformation'
@@ -55,6 +56,30 @@ import { PUBLISH_DRAFT } from '@/js/operations/mutations/publishDraft'
5556
5657import 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+
5883vi . 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