@@ -11,24 +11,29 @@ module('Unit | Service | studying-timer', function (hooks) {
1111 } ) ;
1212
1313 module ( 'maybeIdlePause' , function ( ) {
14+ function withAudio ( owner , playing ) {
15+ owner . register ( 'service:audio' , class extends Service { isPlaying = playing ; } ) ;
16+ return owner . lookup ( 'service:studying-timer' ) ;
17+ }
18+
1419 test ( 'pauses when audio is not playing' , function ( assert ) {
15- this . owner . register (
16- 'service:audio' ,
17- class extends Service { isPlaying = false ; } ,
18- ) ;
19- const timer = this . owner . lookup ( 'service:studying-timer' ) ;
20+ const timer = withAudio ( this . owner , false ) ;
2021 timer . maybeIdlePause ( ) ;
21- assert . true ( timer . isPaused , 'isPaused set to true' ) ;
22+ assert . true ( timer . isPaused ) ;
2223 } ) ;
2324
2425 test ( 'does not pause when audio is playing' , function ( assert ) {
25- this . owner . register (
26- 'service:audio' ,
27- class extends Service { isPlaying = true ; } ,
28- ) ;
29- const timer = this . owner . lookup ( 'service:studying-timer' ) ;
26+ const timer = withAudio ( this . owner , true ) ;
3027 timer . maybeIdlePause ( ) ;
31- assert . false ( timer . isPaused , 'isPaused stays false during playback' ) ;
28+ assert . false ( timer . isPaused ) ;
29+ } ) ;
30+
31+ test ( 'user pause still works while audio plays' , function ( assert ) {
32+ // Regression guard: only maybeIdlePause should defer to audio state;
33+ // direct pause() (timer button click) must remain unconditional.
34+ const timer = withAudio ( this . owner , true ) ;
35+ timer . pause ( ) ;
36+ assert . true ( timer . isPaused ) ;
3237 } ) ;
3338 } ) ;
3439} ) ;
0 commit comments