From e2343ce6a344883a347448f46dba52b12708bcc4 Mon Sep 17 00:00:00 2001 From: Ben Brooks Date: Thu, 14 Dec 2023 09:32:58 -0800 Subject: [PATCH] Combine effects test files --- test/unit/effects.js | 69 ---------------------------------------- test/unit/effectsTest.js | 68 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 69 deletions(-) delete mode 100644 test/unit/effects.js diff --git a/test/unit/effects.js b/test/unit/effects.js deleted file mode 100644 index f30d7578..00000000 --- a/test/unit/effects.js +++ /dev/null @@ -1,69 +0,0 @@ -const test = require('tape'); -const sinon = require('sinon'); -const helpers = require('../helpers/createDanceAPI'); -const constants = require("../../src/constants"); - -test('Background effects', async t => { - const nativeAPI = await helpers.createDanceAPI(); - nativeAPI.play({ - bpm: 120, - }); - - const spyNone = sinon.spy(nativeAPI.bgEffects_.none, 'draw'); - const spyRainbow = sinon.spy(nativeAPI.bgEffects_.rainbow, 'draw'); - const spyDisco = sinon.spy(nativeAPI.bgEffects_.disco, 'draw'); - - t.equal(spyNone.callCount, 0); - t.equal(spyRainbow.callCount, 0); - t.equal(spyDisco.callCount, 0); - - nativeAPI.draw(); - - t.equal(spyNone.callCount, 1); - t.equal(spyRainbow.callCount, 0); - t.equal(spyDisco.callCount, 0); - - nativeAPI.setBackgroundEffect('rainbow'); - nativeAPI.draw(); - - t.equal(spyNone.callCount, 1); - t.equal(spyRainbow.callCount, 1); - t.equal(spyDisco.callCount, 0); - - nativeAPI.setBackgroundEffect('disco'); - nativeAPI.draw(); - - t.equal(spyNone.callCount, 1); - t.equal(spyRainbow.callCount, 1); - t.equal(spyDisco.callCount, 1); - - nativeAPI.setBackground('blue'); - nativeAPI.draw(); - - t.equal(spyNone.callCount, 2); - t.equal(spyRainbow.callCount, 1); - t.equal(spyDisco.callCount, 1); - - nativeAPI.reset(); - t.end(); -}); - -test('All supported foreground effects exist', async t => { - const nativeAPI = await helpers.createDanceAPI(); - - const missingEffects = constants.FOREGROUND_EFFECTS.filter(effect => !nativeAPI.fgEffects_.hasOwnProperty(effect)); - t.equal(missingEffects.length, 0); - - nativeAPI.reset(); - t.end(); -}); - -test('All supported background effects exist', async t => { - const nativeAPI = await helpers.createDanceAPI(); - - const missingEffects = constants.BACKGROUND_EFFECTS.filter(effect => !nativeAPI.bgEffects_.hasOwnProperty(effect)); - t.equal(missingEffects.length, 0); - - nativeAPI.reset(); - t.end(); -}); diff --git a/test/unit/effectsTest.js b/test/unit/effectsTest.js index b3ca0668..77c6d2be 100644 --- a/test/unit/effectsTest.js +++ b/test/unit/effectsTest.js @@ -2,6 +2,7 @@ const test = require('tape'); const sinon = require('sinon'); const utils = require('../../src/utils'); const helpers = require('../helpers/createDanceAPI'); +const constants = require("../../src/constants"); test('setBackground clears the bgEffect and sets background_color', async t => { const nativeAPI = await helpers.createDanceAPI(); @@ -202,3 +203,70 @@ test('logs invalid background palette', async t => { nativeAPI.reset(); sinon.restore(); }); + + +test('Set background effect to none, unknown, and known effects', async t => { + const nativeAPI = await helpers.createDanceAPI(); + nativeAPI.play({ + bpm: 120, + }); + + const spyNone = sinon.spy(nativeAPI.bgEffects_.none, 'draw'); + const spyRainbow = sinon.spy(nativeAPI.bgEffects_.rainbow, 'draw'); + const spyDisco = sinon.spy(nativeAPI.bgEffects_.disco, 'draw'); + + t.equal(spyNone.callCount, 0); + t.equal(spyRainbow.callCount, 0); + t.equal(spyDisco.callCount, 0); + + nativeAPI.draw(); + + t.equal(spyNone.callCount, 1); + t.equal(spyRainbow.callCount, 0); + t.equal(spyDisco.callCount, 0); + + nativeAPI.setBackgroundEffect('rainbow'); + nativeAPI.draw(); + + t.equal(spyNone.callCount, 1); + t.equal(spyRainbow.callCount, 1); + t.equal(spyDisco.callCount, 0); + + nativeAPI.setBackgroundEffect('disco'); + nativeAPI.draw(); + + t.equal(spyNone.callCount, 1); + t.equal(spyRainbow.callCount, 1); + t.equal(spyDisco.callCount, 1); + + nativeAPI.setBackground('blue'); + nativeAPI.draw(); + + t.equal(spyNone.callCount, 2); + t.equal(spyRainbow.callCount, 1); + t.equal(spyDisco.callCount, 1); + + nativeAPI.reset(); + t.end(); +}); + +test('All supported foreground effects exist', async t => { + const nativeAPI = await helpers.createDanceAPI(); + + const missingEffects = constants.FOREGROUND_EFFECTS.filter(effect => !nativeAPI.fgEffects_.hasOwnProperty(effect)); + t.equal(missingEffects.length, 0); + + nativeAPI.reset(); + t.end(); +}); + +test('All supported background effects exist', async t => { + const nativeAPI = await helpers.createDanceAPI(); + + const missingEffects = constants.BACKGROUND_EFFECTS.filter(effect => !nativeAPI.bgEffects_.hasOwnProperty(effect)); + t.equal(missingEffects.length, 0); + + nativeAPI.reset(); + t.end(); +}); +