Skip to content

Commit

Permalink
fix: Add another tests for sound-position-timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
jkeen committed Oct 14, 2024
1 parent 9c07199 commit 0b2a93e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
6 changes: 1 addition & 5 deletions ember-stereo/src/helpers/sound-position-timestamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ export default class SoundPositionTimestamp extends StereoBaseIsHelper {
let currentTime = this.sound?.currentTime;
let startsAt = this.options?.startsAt;

if (startsAt && !this.sound?.isLoaded) {
return new Date(startsAt);
}

if (currentTime) {
if (currentTime && this.sound?.isLoaded) {
result = new Date(currentTime);
} else if (startsAt) {
result = add(new Date(startsAt), {
Expand Down
13 changes: 9 additions & 4 deletions ember-stereo/src/stereo-connections/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import hasEqualUrls from '../-private/utils/has-equal-urls';
import { getOwner } from '@ember/application';
import { registerDestructor } from '@ember/destroyable';
import { task, animationFrame, timeout, didCancel } from 'ember-concurrency';
import { macroCondition, isTesting } from '@embroider/macros';

/**
* This is the base sound object from which other sound objects are derived.
Expand Down Expand Up @@ -289,11 +290,15 @@ export default class Sound extends Evented {
newPosition: v,
});

yield timeout(50);
if (macroCondition(isTesting())) {
// in testing, we don't want to wait for the next animation frame
} else {
yield timeout(50);
}

next(() => {
this._position = this._setPosition(v);
});
// next(() => {
this._position = this._setPosition(v);
// });
}

/* we both want to query for the playing sounds position, and fire change events
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { setupStereoTest } from 'ember-stereo/test-support/stereo-setup';
import { render } from '@ember/test-helpers';
import { render, settled } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { add } from 'date-fns';

Expand Down Expand Up @@ -52,4 +52,23 @@ module('Integration | Helper | sound-position-timestamp', function (hooks) {

assert.strictEqual(this.element.textContent.trim(), '');
});

test('it returns the correct timestamp when currentTime is provided', async function (assert) {
let service = this.owner.lookup('service:stereo');

this.url = '/good/5000/position.mp3';
let { sound } = await service.play(this.url);
sound.position = 2000;

this.startsAt = new Date('2023-10-02T00:00:00Z');

await render(
hbs`{{sound-position-timestamp this.url startsAt=this.startsAt}}`
);

assert.strictEqual(
this.element.textContent.trim(),
new Date('2023-10-02T00:00:02Z').toString()
);
});
});

0 comments on commit 0b2a93e

Please sign in to comment.