Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sanchitmalhotra126 committed Nov 17, 2023
1 parent be438da commit 9538389
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions test/unit/effectsTest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const test = require('tape');
const sinon = require('sinon');
const helpers = require('../helpers/createDanceAPI');

test('setBackground clears the bgEffect and sets background_color', async t => {
Expand Down Expand Up @@ -137,3 +138,66 @@ test('random foreground effect', async t => {
t.end();
nativeAPI.reset();
});

test('logs invalid background effect', async t => {
const invalidEffect = 'invalid';
const loggerSpy = {
logWarning: sinon.spy(),
};
const consoleSpy = sinon.spy(console, 'warn');
const nativeAPI = await helpers.createDanceAPI({
logger: loggerSpy
});

nativeAPI.setBackgroundEffect(invalidEffect);
t.equal(consoleSpy.callCount, 1);
t.equal(loggerSpy.logWarning.callCount, 1);
const warningMessage = loggerSpy.logWarning.firstCall.args[0];
t.true(warningMessage.includes(invalidEffect));

t.end();
nativeAPI.reset();
sinon.restore();
});

test('logs invalid foreground effect', async t => {
const invalidEffect = 'invalid';
const loggerSpy = {
logWarning: sinon.spy(),
};
const consoleSpy = sinon.spy(console, 'warn');
const nativeAPI = await helpers.createDanceAPI({
logger: loggerSpy
});

nativeAPI.setForegroundEffect(invalidEffect);
t.equal(consoleSpy.callCount, 1);
t.equal(loggerSpy.logWarning.callCount, 1);
const warningMessage = loggerSpy.logWarning.firstCall.args[0];
t.true(warningMessage.includes(invalidEffect));

t.end();
nativeAPI.reset();
sinon.restore();
});

test('logs invalid background palette', async t => {
const invalidPalette = 'invalid';
const loggerSpy = {
logWarning: sinon.spy(),
};
const consoleSpy = sinon.spy(console, 'warn');
const nativeAPI = await helpers.createDanceAPI({
logger: loggerSpy
});

nativeAPI.setBackgroundEffect('color_cycle', invalidPalette);
t.equal(consoleSpy.callCount, 1);
t.equal(loggerSpy.logWarning.callCount, 1);
const warningMessage = loggerSpy.logWarning.firstCall.args[0];
t.true(warningMessage.includes(invalidPalette));

t.end();
nativeAPI.reset();
sinon.restore();
});

0 comments on commit 9538389

Please sign in to comment.