@@ -47,10 +47,10 @@ vi.mock('../studio-design/packages-io.js', async (importOriginal) => ({
4747 { id : 'com.example.bare' , namespace : null } ,
4848 ] ,
4949} ) ) ;
50- const publish = vi . fn ( async ( ) => ( { ok : true } ) ) ;
50+ const publish = vi . fn ( async ( ... _args : unknown [ ] ) => ( { ok : true } ) ) ;
5151vi . mock ( '../studio-design/studioSaveBar.js' , async ( importOriginal ) => ( {
5252 ...( await importOriginal < Record < string , unknown > > ( ) ) ,
53- publishSavedItem : ( ...args : unknown [ ] ) => publish ( ...( args as [ ] ) ) ,
53+ publishSavedItem : ( ...args : unknown [ ] ) => publish ( ...args ) ,
5454} ) ) ;
5555const taken = vi . fn ( async ( ..._args : unknown [ ] ) : Promise < { name : string ; label : string } | null > => null ) ;
5656vi . mock ( '../studio-design/StudioPillarKit.js' , async ( importOriginal ) => ( {
@@ -63,8 +63,16 @@ vi.mock('../studio-design/newObjectJoinsAppMenu.js', async (importOriginal) => (
6363 addNewObjectToAppMenu : ( ...args : unknown [ ] ) => joinMenu ( ...( args as [ ] ) ) ,
6464} ) ) ;
6565
66+ /** objectstack#36904 — the package's own objects, read when an identifier is taken. */
67+ const surfaces = vi . fn ( async ( ..._args : unknown [ ] ) : Promise < Array < { type : string ; name : string } > > => [ ] ) ;
68+ vi . mock ( '../studio-design/packageSurfaces.js' , async ( importOriginal ) => ( {
69+ ...( await importOriginal < Record < string , unknown > > ( ) ) ,
70+ loadPackageSurfaces : ( ...args : unknown [ ] ) => surfaces ( ...args ) ,
71+ } ) ) ;
72+
6673import { MetadataListCreateDialog } from './MetadataListCreateDialog' ;
67- import { t } from './i18n' ;
74+ import { publishCreated } from '../studio-design/studioSaveBar.js' ;
75+ import { t , tFormat } from './i18n' ;
6876
6977afterEach ( ( ) => {
7078 cleanup ( ) ;
@@ -73,7 +81,7 @@ afterEach(() => {
7381
7482const L = 'en-US' as const ;
7583
76- function open ( type : 'object' | 'flow' , packageId : string , inPair : boolean ) {
84+ function open ( type : 'object' | 'flow' , packageId : string , inPair : boolean , onOpenExisting ?: ( path : string ) => void ) {
7785 const onCreated = vi . fn ( ) ;
7886 render (
7987 < MetadataListCreateDialog
@@ -84,6 +92,7 @@ function open(type: 'object' | 'flow', packageId: string, inPair: boolean) {
8492 inPair = { inPair }
8593 locale = { L }
8694 onCreated = { onCreated }
95+ onOpenExisting = { onOpenExisting }
8796 /> ,
8897 ) ;
8998 return onCreated ;
@@ -108,7 +117,7 @@ describe('list 「新建」 lands in the paired .custom package on a read-only b
108117 expect ( [ type , name ] ) . toEqual ( [ 'object' , 'hrx_leave_request' ] ) ;
109118 expect ( opts ) . toMatchObject ( { mode : 'draft' , packageId : 'com.vendor.hr.custom' , ifNoneMatch : '*' } ) ;
110119 expect ( body ) . toHaveProperty ( 'sharingModel' , 'public_read' ) ;
111- expect ( publish ) . toHaveBeenCalledWith ( expect . anything ( ) , { type : 'object' , name : 'hrx_leave_request' , packageId : 'com.vendor.hr.custom' } , false ) ;
120+ expect ( publish ) . toHaveBeenCalledWith ( expect . anything ( ) , { type : 'object' , name : 'hrx_leave_request' , packageId : 'com.vendor.hr.custom' } , false , publishCreated ) ;
112121 expect ( onCreated ) . toHaveBeenCalledWith ( { name : 'hrx_leave_request' , packageId : 'com.vendor.hr.custom' } ) ;
113122 expect ( joinMenu ) . not . toHaveBeenCalled ( ) ;
114123 } ) ;
@@ -181,9 +190,40 @@ describe('list 「新建」 for an object: the create the object designer no lon
181190 const onCreated = open ( 'object' , 'com.example.crm' , false ) ;
182191 fill ( 'engine.studio.data.nameLabel' , 'engine.studio.data.idLabel' , 'Visit' , 'visit' ) ;
183192 await waitFor ( ( ) => expect ( taken ) . toHaveBeenCalled ( ) ) ;
184- expect ( await screen . findByTestId ( 'object-create-taken' ) ) . toHaveTextContent ( 'crm_visit' ) ;
193+ const notice = await screen . findByTestId ( 'object-create-taken' ) ;
194+ expect ( notice ) . toHaveTextContent ( 'crm_visit' ) ;
185195 expect ( save ) . not . toHaveBeenCalled ( ) ;
186196 expect ( publish ) . not . toHaveBeenCalled ( ) ;
187197 expect ( onCreated ) . not . toHaveBeenCalled ( ) ;
198+ // CONTROL (objectstack#36904): held outside this package, it names the holder and offers no Open.
199+ expect ( notice ) . toHaveTextContent (
200+ tFormat ( 'engine.studio.data.createTakenElsewhere' , L , { label : 'Visit' , name : 'crm_visit' } ) ,
201+ ) ;
202+ expect ( screen . queryByTestId ( 'object-create-open-existing' ) ) . toBeNull ( ) ;
203+ } ) ;
204+
205+ // objectstack#36904 — the in-page create offered to open an object its rail held; the list's does too.
206+ it ( 'an identifier this package holds says so, and Open goes to that object\'s designer' , async ( ) => {
207+ taken . mockResolvedValueOnce ( { name : 'crm_visit' , label : 'Visit' } ) ;
208+ surfaces . mockResolvedValueOnce ( [ { type : 'object' , name : 'crm_visit' } ] ) ;
209+ const onOpenExisting = vi . fn ( ) ;
210+ const onCreated = open ( 'object' , 'com.example.crm' , false , onOpenExisting ) ;
211+ fill ( 'engine.studio.data.nameLabel' , 'engine.studio.data.idLabel' , 'Visit' , 'visit' ) ;
212+ const notice = await screen . findByTestId ( 'object-create-taken' ) ;
213+ expect ( notice ) . toHaveTextContent ( tFormat ( 'engine.studio.data.createTaken' , L , { label : 'Visit' , name : 'crm_visit' } ) ) ;
214+ expect ( surfaces ) . toHaveBeenCalledWith ( expect . anything ( ) , 'object' , 'com.example.crm' , L ) ;
215+ fireEvent . click ( screen . getByTestId ( 'object-create-open-existing' ) ) ;
216+ expect ( onOpenExisting ) . toHaveBeenCalledWith ( '/studio/com.example.crm/metadata/object/crm_visit' ) ;
217+ expect ( save ) . not . toHaveBeenCalled ( ) ;
218+ expect ( onCreated ) . not . toHaveBeenCalled ( ) ;
219+ } ) ;
220+
221+ // objectstack#36726 — as the flow create: no live row was there at the check, so the publish is `If-None-Match: *`.
222+ it ( 'publishes the created object pinned, so a row published under the name since is refused' , async ( ) => {
223+ const onCreated = open ( 'object' , 'com.example.crm' , false ) ;
224+ fill ( 'engine.studio.data.nameLabel' , 'engine.studio.data.idLabel' , 'Visit' , 'visit' ) ;
225+ await waitFor ( ( ) => expect ( onCreated ) . toHaveBeenCalled ( ) ) ;
226+ expect ( publish ) . toHaveBeenCalledTimes ( 1 ) ;
227+ expect ( publish . mock . calls [ 0 ] ?. [ 3 ] ) . toBe ( publishCreated ) ;
188228 } ) ;
189229} ) ;
0 commit comments