2017-07-06 14:28:11 -04:00
|
|
|
const test = require('tap').test;
|
|
|
|
const Sound = require('../../src/blocks/scratch3_sound');
|
2017-07-06 17:23:25 -04:00
|
|
|
let playedSound;
|
2017-11-07 16:26:20 -05:00
|
|
|
|
|
|
|
const blocks = new Sound();
|
2017-07-06 14:28:11 -04:00
|
|
|
const util = {
|
|
|
|
target: {
|
|
|
|
sprite: {
|
|
|
|
sounds: [
|
2017-07-25 12:17:20 -04:00
|
|
|
{name: 'first name', soundId: 'first soundId'},
|
|
|
|
{name: 'second name', soundId: 'second soundId'},
|
|
|
|
{name: 'third name', soundId: 'third soundId'},
|
|
|
|
{name: '6', soundId: 'fourth soundId'}
|
2018-06-22 09:33:08 -04:00
|
|
|
],
|
|
|
|
soundBank: {
|
|
|
|
playSound: (target, soundId) => (playedSound = soundId)
|
|
|
|
}
|
2017-07-06 14:28:11 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
test('playSound with a name string works', t => {
|
|
|
|
const args = {SOUND_MENU: 'second name'};
|
|
|
|
blocks.playSound(args, util);
|
2017-07-25 12:17:20 -04:00
|
|
|
t.strictEqual(playedSound, 'second soundId');
|
2017-07-06 14:28:11 -04:00
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('playSound with a number string works 1-indexed', t => {
|
|
|
|
let args = {SOUND_MENU: '5'};
|
|
|
|
blocks.playSound(args, util);
|
2017-07-25 12:17:20 -04:00
|
|
|
t.strictEqual(playedSound, 'first soundId');
|
2017-07-06 14:28:11 -04:00
|
|
|
|
|
|
|
args = {SOUND_MENU: '1'};
|
|
|
|
blocks.playSound(args, util);
|
2017-07-25 12:17:20 -04:00
|
|
|
t.strictEqual(playedSound, 'first soundId');
|
2017-07-06 14:28:11 -04:00
|
|
|
|
|
|
|
args = {SOUND_MENU: '0'};
|
|
|
|
blocks.playSound(args, util);
|
2017-07-25 12:17:20 -04:00
|
|
|
t.strictEqual(playedSound, 'fourth soundId');
|
2017-07-06 14:28:11 -04:00
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('playSound with a number works 1-indexed', t => {
|
|
|
|
let args = {SOUND_MENU: 5};
|
|
|
|
blocks.playSound(args, util);
|
2017-07-25 12:17:20 -04:00
|
|
|
t.strictEqual(playedSound, 'first soundId');
|
2017-07-06 14:28:11 -04:00
|
|
|
|
|
|
|
args = {SOUND_MENU: 1};
|
|
|
|
blocks.playSound(args, util);
|
2017-07-25 12:17:20 -04:00
|
|
|
t.strictEqual(playedSound, 'first soundId');
|
2017-07-06 14:28:11 -04:00
|
|
|
|
|
|
|
args = {SOUND_MENU: 0};
|
|
|
|
blocks.playSound(args, util);
|
2017-07-25 12:17:20 -04:00
|
|
|
t.strictEqual(playedSound, 'fourth soundId');
|
2017-07-06 14:28:11 -04:00
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('playSound prioritizes sound index if given a number', t => {
|
|
|
|
const args = {SOUND_MENU: 6};
|
|
|
|
blocks.playSound(args, util);
|
|
|
|
// Ignore the sound named '6', wrapClamp to the second instead
|
2017-07-25 12:17:20 -04:00
|
|
|
t.strictEqual(playedSound, 'second soundId');
|
2017-07-06 14:28:11 -04:00
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('playSound prioritizes sound name if given a string', t => {
|
|
|
|
const args = {SOUND_MENU: '6'};
|
|
|
|
blocks.playSound(args, util);
|
|
|
|
// Use the sound named '6', which is the fourth
|
2017-07-25 12:17:20 -04:00
|
|
|
t.strictEqual(playedSound, 'fourth soundId');
|
2017-07-06 14:28:11 -04:00
|
|
|
t.end();
|
|
|
|
});
|