2017-11-07 16:26:20 -05:00
|
|
|
const test = require('tap').test;
|
2017-11-14 14:58:16 -05:00
|
|
|
const Music = require('../../src/extensions/scratch3_music/index.js');
|
2017-11-21 10:36:28 -05:00
|
|
|
|
2018-02-27 15:38:34 -05:00
|
|
|
const fakeRuntime = {
|
2018-04-05 15:01:52 -04:00
|
|
|
getTargetForStage: () => ({tempo: 60}),
|
|
|
|
on: () => {} // Stub out listener methods used in constructor.
|
2018-02-27 15:38:34 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
const blocks = new Music(fakeRuntime);
|
2017-11-15 14:10:50 -05:00
|
|
|
|
2017-11-07 16:26:20 -05:00
|
|
|
const util = {
|
2017-11-15 14:10:50 -05:00
|
|
|
stackFrame: Object.create(null),
|
2017-11-07 16:26:20 -05:00
|
|
|
target: {
|
2017-11-15 14:10:50 -05:00
|
|
|
audioPlayer: null
|
2017-11-13 10:57:36 -05:00
|
|
|
},
|
2017-11-15 14:10:50 -05:00
|
|
|
yield: () => null
|
2017-11-07 16:26:20 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
test('playDrum uses 1-indexing and wrap clamps', t => {
|
2017-11-21 10:36:28 -05:00
|
|
|
// Stub playDrumNum
|
|
|
|
let playedDrum;
|
|
|
|
blocks._playDrumNum = (_util, drum) => (playedDrum = drum);
|
|
|
|
|
2017-11-07 16:26:20 -05:00
|
|
|
let args = {DRUM: 1};
|
|
|
|
blocks.playDrumForBeats(args, util);
|
|
|
|
t.strictEqual(playedDrum, 0);
|
|
|
|
|
2017-11-15 14:10:50 -05:00
|
|
|
args = {DRUM: blocks.DRUM_INFO.length + 1};
|
2017-11-07 16:26:20 -05:00
|
|
|
blocks.playDrumForBeats(args, util);
|
|
|
|
t.strictEqual(playedDrum, 0);
|
|
|
|
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('setInstrument uses 1-indexing and wrap clamps', t => {
|
|
|
|
// Stub getMusicState
|
2017-11-21 10:36:28 -05:00
|
|
|
const state = {currentInstrument: 0};
|
|
|
|
blocks._getMusicState = () => state;
|
2017-11-07 16:26:20 -05:00
|
|
|
|
|
|
|
let args = {INSTRUMENT: 1};
|
|
|
|
blocks.setInstrument(args, util);
|
2017-11-21 10:36:28 -05:00
|
|
|
t.strictEqual(state.currentInstrument, 0);
|
2017-11-07 16:26:20 -05:00
|
|
|
|
2017-11-21 10:36:28 -05:00
|
|
|
args = {INSTRUMENT: blocks.INSTRUMENT_INFO.length + 1};
|
2017-11-07 16:26:20 -05:00
|
|
|
blocks.setInstrument(args, util);
|
2017-11-21 10:36:28 -05:00
|
|
|
t.strictEqual(state.currentInstrument, 0);
|
2017-11-07 16:26:20 -05:00
|
|
|
|
|
|
|
t.end();
|
|
|
|
});
|