@@ -51,6 +51,10 @@ export class EmailEditor implements IClientEditor, IStatusIndicator {
5151 }
5252
5353 async applyChange ( change : ExternalEdit ) : Promise < void > {
54+ if ( this . options . ignoreEmptyBodyUpdates && change . body === "" ) {
55+ return
56+ }
57+
5458 // TODO Should re-add HTML tags like `<p></p>` if stripped
5559 this . port . send ( change )
5660 }
@@ -86,3 +90,51 @@ function messageForStatus(status: ClientStatus): MessageId {
8690 return "src_client_status_error"
8791 }
8892}
93+
94+ if ( import . meta. vitest ) {
95+ const { describe, expect, it } = import . meta. vitest
96+
97+ describe ( EmailEditor , ( ) => {
98+ it ( "should not apply an empty body when ignoreEmptyBodyUpdates is enabled" , async ( ) => {
99+ const sent : unknown [ ] = [ ]
100+ const sut = makeSut ( { ignoreEmptyBodyUpdates : true , sent } )
101+
102+ await sut . applyChange ( { body : "" } )
103+
104+ expect ( sent ) . to . be . empty
105+ } )
106+
107+ it ( "should apply an empty body when ignoreEmptyBodyUpdates is disabled" , async ( ) => {
108+ const sent : unknown [ ] = [ ]
109+ const sut = makeSut ( { ignoreEmptyBodyUpdates : false , sent } )
110+
111+ const change : ExternalEdit = { body : "" }
112+ await sut . applyChange ( change )
113+
114+ expect ( sent ) . to . deep . equal ( [ change ] )
115+ } )
116+
117+ it ( "should apply a non-empty body even when ignoreEmptyBodyUpdates is enabled" , async ( ) => {
118+ const sent : unknown [ ] = [ ]
119+ const sut = makeSut ( { ignoreEmptyBodyUpdates : true , sent } )
120+
121+ const change : ExternalEdit = { body : "hello" }
122+ await sut . applyChange ( change )
123+
124+ expect ( sent ) . to . deep . equal ( [ change ] )
125+ } )
126+ } )
127+
128+ function makeSut ( opts : { ignoreEmptyBodyUpdates : boolean ; sent : unknown [ ] } ) : EmailEditor {
129+ const port = {
130+ send : ( m : never ) => opts . sent . push ( m ) ,
131+ } as unknown as IGhostServerPort
132+ const options = {
133+ clientHostName : "test.extension.localhost" ,
134+ serverUrl : new URL ( "http://localhost:4001/" ) ,
135+ enableNotifications : true ,
136+ ignoreEmptyBodyUpdates : opts . ignoreEmptyBodyUpdates ,
137+ } as ClientOptions
138+ return new EmailEditor ( { } as INotificationTray , { } as IComposeWindow , port , options )
139+ }
140+ }
0 commit comments