@@ -530,41 +530,57 @@ describe("mobile composer drafts", () => {
530530 expect ( reloaded . cloudDrafts . signedOut ) . toEqual ( { } ) ;
531531 } ) ;
532532
533- it ( "removes a file only after its last reference is deleted, while retaining images" , async ( ) => {
534- const outboxLoad = vi . spyOn ( threadOutboxManager , "load" ) . mockResolvedValue ( true ) ;
535- onTestFinished ( ( ) => outboxLoad . mockRestore ( ) ) ;
536- const cleanup = Promise . withResolvers < void > ( ) ;
537- composerAttachmentCleanupMocks . remove . mockImplementationOnce ( async ( ) => {
538- cleanup . resolve ( ) ;
539- } ) ;
540- const key = "environment-1:remove-context-files" ;
541- const file = {
542- id : "file-1" ,
543- type : "file" as const ,
544- name : "notes.txt" ,
545- mimeType : "text/plain" ,
546- sizeBytes : 4 ,
547- fileUri : "file:///notes.txt" ,
548- } ;
549- const image = {
550- ...file ,
551- id : "image-1" ,
552- type : "image" as const ,
553- name : "image.png" ,
554- mimeType : "image/png" ,
555- fileUri : "file:///image.png" ,
556- previewUri : "file:///image.png" ,
557- } ;
558- appendComposerDraftAttachments ( key , [ file , image ] , { appendReference : true } ) ;
559- const fileLink = "[notes.txt](t3-context://v1/file/file-1)" ;
560- setComposerDraftText ( key , `${ fileLink } ${ fileLink } ` ) ;
561- expect ( getComposerDraftSnapshot ( key ) . attachments ) . toEqual ( [ file , image ] ) ;
562- setComposerDraftText ( key , fileLink ) ;
563- expect ( getComposerDraftSnapshot ( key ) . attachments ) . toEqual ( [ file , image ] ) ;
564- setComposerDraftText ( key , "plain text" ) ;
565- expect ( getComposerDraftSnapshot ( key ) . attachments ) . toEqual ( [ image ] ) ;
566- await cleanup . promise ;
567- } ) ;
533+ it . each ( [
534+ { name : "notes.txt" , mimeType : "text/plain" } ,
535+ { name : "document-photo.png" , mimeType : "image/png" } ,
536+ { name : "recording.mp4" , mimeType : "video/mp4" } ,
537+ ] ) (
538+ "removes $name after its last reference is deleted, while retaining native images" ,
539+ async ( { name, mimeType } ) => {
540+ const outboxLoad = vi . spyOn ( threadOutboxManager , "load" ) . mockResolvedValue ( true ) ;
541+ onTestFinished ( ( ) => outboxLoad . mockRestore ( ) ) ;
542+ const cleanup = Promise . withResolvers < void > ( ) ;
543+ composerAttachmentCleanupMocks . remove . mockImplementationOnce ( async ( ) => {
544+ cleanup . resolve ( ) ;
545+ } ) ;
546+ const key = "environment-1:remove-context-files" ;
547+ const file = {
548+ id : "file-1" ,
549+ type : "file" as const ,
550+ name,
551+ mimeType,
552+ sizeBytes : 4 ,
553+ fileUri : `file:///${ name } ` ,
554+ } ;
555+ const image = {
556+ ...file ,
557+ id : "image-1" ,
558+ type : "image" as const ,
559+ name : "image.png" ,
560+ mimeType : "image/png" ,
561+ fileUri : "file:///image.png" ,
562+ previewUri : "file:///image.png" ,
563+ } ;
564+ appendComposerDraftAttachments ( key , [ file , image ] , { appendReference : true } ) ;
565+ const fileLink = formatComposerContextReference (
566+ getComposerDraftSnapshot ( key ) . context ! . records [ 0 ] ! ,
567+ ) ;
568+ setComposerDraftText ( key , `${ fileLink } ${ fileLink } ` ) ;
569+ expect ( getComposerDraftSnapshot ( key ) . attachments ) . toEqual ( [ file , image ] ) ;
570+ setComposerDraftText ( key , fileLink ) ;
571+ expect ( getComposerDraftSnapshot ( key ) . attachments ) . toEqual ( [ file , image ] ) ;
572+ expect (
573+ countComposerDraftAttachmentsAfterSelection ( key , {
574+ text : fileLink ,
575+ start : 0 ,
576+ end : fileLink . length ,
577+ } ) ,
578+ ) . toBe ( 1 ) ;
579+ setComposerDraftText ( key , "plain text" ) ;
580+ expect ( getComposerDraftSnapshot ( key ) . attachments ) . toEqual ( [ image ] ) ;
581+ await cleanup . promise ;
582+ } ,
583+ ) ;
568584
569585 it ( "rejects attachments atomically when no context slots remain" , async ( ) => {
570586 const outboxLoad = vi . spyOn ( threadOutboxManager , "load" ) . mockResolvedValue ( true ) ;
0 commit comments