From 95383890a390b33f083e9b9176c7c344be5c3278 Mon Sep 17 00:00:00 2001 From: Sanchit Malhotra Date: Fri, 17 Nov 2023 12:45:40 -0500 Subject: [PATCH] Add unit tests --- test/unit/effectsTest.js | 64 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/test/unit/effectsTest.js b/test/unit/effectsTest.js index 00331eb3..c1f112a5 100644 --- a/test/unit/effectsTest.js +++ b/test/unit/effectsTest.js @@ -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 => { @@ -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(); +});