@@ -32,6 +32,7 @@ class FakeRecorder {
3232 resumeCount = 0 ;
3333 started = false ;
3434 stopped = false ;
35+ chunk = new Blob ( [ "audio" ] ) ;
3536 ondataavailable : ( ( e : { data : Blob } ) => void ) | null = null ;
3637 onstop : ( ( ) => void ) | null = null ;
3738 mimeType = "audio/webm" ;
@@ -56,7 +57,7 @@ class FakeRecorder {
5657 stop ( ) {
5758 this . stopped = true ;
5859 this . state = "inactive" ;
59- this . ondataavailable ?.( { data : new Blob ( [ "audio" ] ) } ) ;
60+ this . ondataavailable ?.( { data : this . chunk } ) ;
6061 this . onstop ?.( ) ;
6162 }
6263}
@@ -187,6 +188,59 @@ describe("AddAudioLayerDialog", () => {
187188 unmount ( ) ;
188189 expect ( addAudioAsset ) . not . toHaveBeenCalled ( ) ;
189190 } ) ;
191+
192+ it ( "reports an empty microphone take without saving or importing it" , async ( ) => {
193+ const { props } = renderDialog ( ) ;
194+ await act ( async ( ) => {
195+ fireEvent . click ( screen . getByText ( "audio.record" ) ) ;
196+ } ) ;
197+ FakeRecorder . instances [ 0 ] . chunk = new Blob ( [ ] ) ;
198+ await act ( async ( ) => {
199+ fireEvent . click ( screen . getByText ( "audio.stop" ) ) ;
200+ } ) ;
201+ expect ( toast . error ) . toHaveBeenCalledWith ( "audio.emptyRecording" ) ;
202+ expect ( window . electronAPI . saveRecordedVoiceover ) . not . toHaveBeenCalled ( ) ;
203+ expect ( addAudioAsset ) . not . toHaveBeenCalled ( ) ;
204+ expect ( props . onComplete ) . not . toHaveBeenCalled ( ) ;
205+ expect ( props . onRecordingStop ) . toHaveBeenCalledOnce ( ) ;
206+ expect ( stopTrack ) . toHaveBeenCalledOnce ( ) ;
207+ } ) ;
208+
209+ it ( "reports a refused save without importing a temporary blob URL" , async ( ) => {
210+ const createObjectURL = vi . fn ( ( ) => "blob:unpersisted-voiceover" ) ;
211+ vi . stubGlobal (
212+ "URL" ,
213+ class extends URL {
214+ static createObjectURL = createObjectURL ;
215+ } ,
216+ ) ;
217+ vi . mocked ( window . electronAPI . saveRecordedVoiceover ) . mockResolvedValueOnce ( {
218+ success : false ,
219+ message : "Disk unavailable" ,
220+ } ) ;
221+ const { props } = renderDialog ( ) ;
222+ await act ( async ( ) => {
223+ fireEvent . click ( screen . getByText ( "audio.record" ) ) ;
224+ } ) ;
225+ await act ( async ( ) => {
226+ fireEvent . click ( screen . getByText ( "audio.stop" ) ) ;
227+ } ) ;
228+ expect ( toast . error ) . toHaveBeenCalledWith ( "audio.saveFailed" ) ;
229+ expect ( createObjectURL ) . not . toHaveBeenCalled ( ) ;
230+ expect ( addAudioAsset ) . not . toHaveBeenCalled ( ) ;
231+ expect ( props . onComplete ) . not . toHaveBeenCalled ( ) ;
232+ } ) ;
233+
234+ it ( "does not acquire the microphone when persistence is unavailable" , async ( ) => {
235+ Object . defineProperty ( window , "electronAPI" , { configurable : true , value : { } } ) ;
236+ renderDialog ( ) ;
237+ await act ( async ( ) => {
238+ fireEvent . click ( screen . getByText ( "audio.record" ) ) ;
239+ } ) ;
240+ expect ( toast . error ) . toHaveBeenCalledWith ( "audio.recordingUnavailable" ) ;
241+ expect ( navigator . mediaDevices . getUserMedia ) . not . toHaveBeenCalled ( ) ;
242+ expect ( FakeRecorder . instances ) . toHaveLength ( 0 ) ;
243+ } ) ;
190244} ) ;
191245
192246describe ( "voiceover pause and resume" , ( ) => {
0 commit comments