Skip to content

Commit

Permalink
add test for random action
Browse files Browse the repository at this point in the history
  • Loading branch information
jwetzell committed May 3, 2024
1 parent 3804196 commit 86afd81
Showing 1 changed file with 128 additions and 0 deletions.
128 changes: 128 additions & 0 deletions lib/tests/actions/random-action.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import assert from 'node:assert';
import { describe, test } from 'node:test';
import { RandomAction } from '../../src/actions/index.js';
import MIDIMessage from '../../src/messages/midi-message.js';

describe('RandomAction', () => {
test('create', () => {
const action = new RandomAction({
type: 'random',
params: {
duration: 100,
actions: [
{
type: 'log',
enabled: true,
},
],
},
transforms: [],
enabled: true,
});

assert.notEqual(action, undefined);
});

test('runs one action', async () => {
const action = new RandomAction({
type: 'random',
params: {
actions: [
{
type: 'log',
enabled: true,
},
],
},
transforms: [],
enabled: true,
});

const vars = {};

action.on('action', (actionPath, fired) => {
assert.equal(actionPath, 'actions/0');
assert.equal(fired, true);
});

action.run(new MIDIMessage([0x80, 60, 127], 'test'), vars);
});

test('emits sub action events', async () => {
const action = new RandomAction({
type: 'random',
params: {
actions: [
{
type: 'random',
params: {
actions: [
{
type: 'log',
enabled: true,
},
],
},
enabled: true,
},
],
},
transforms: [],
enabled: true,
});

const vars = {};

action.on('action', (actionPath, fired) => {
assert.equal(actionPath.startsWith('actions/0'), true);
assert.equal(fired, true);
});

action.run(new MIDIMessage([0x80, 60, 127], 'test'), vars);
});

test('emits transform events', async () => {
const action = new RandomAction({
type: 'random',
params: {
actions: [
{
type: 'random',
params: {
actions: [
{
type: 'log',
enabled: true,
},
],
},
transforms: [
{
type: 'scale',
params: {
property: 'note',
inRange: [0, 127],
outRange: [0, 1],
},
enabled: true,
},
],
enabled: true,
},
],
},
transforms: [],
enabled: true,
});

const vars = {};

action.on('transform', (transformPath, fired) => {
console.log(transformPath);
assert.equal(transformPath.startsWith('actions/0/transforms/0'), true);
assert.equal(fired, true);
});

action.run(new MIDIMessage([0x80, 60, 127], 'test'), vars);
});
});

0 comments on commit 86afd81

Please sign in to comment.