|
1 | 1 | import { module, test } from 'qunit'; |
2 | 2 | import { setupTest } from 'ember-qunit'; |
| 3 | +import Service from '@ember/service'; |
3 | 4 |
|
4 | 5 | module('Unit | Service | studying-timer', function (hooks) { |
5 | 6 | setupTest(hooks); |
6 | 7 |
|
7 | | - // Replace this with your real tests. |
8 | 8 | test('it exists', function (assert) { |
9 | 9 | let service = this.owner.lookup('service:studying-timer'); |
10 | 10 | assert.ok(service); |
11 | 11 | }); |
| 12 | + |
| 13 | + 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 | + |
| 19 | + test('pauses when audio is not playing', function (assert) { |
| 20 | + const timer = withAudio(this.owner, false); |
| 21 | + timer.maybeIdlePause(); |
| 22 | + assert.true(timer.isPaused); |
| 23 | + }); |
| 24 | + |
| 25 | + test('does not pause when audio is playing', function (assert) { |
| 26 | + const timer = withAudio(this.owner, true); |
| 27 | + timer.maybeIdlePause(); |
| 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); |
| 37 | + }); |
| 38 | + }); |
12 | 39 | }); |
0 commit comments