From d23719c2a8cfff519cb269d0c093e34ed1d64e78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Tue, 13 Apr 2021 11:38:23 +0200 Subject: [PATCH] Added tests for toggles --- test/GlobalsForTesting.js | 10 ++ test/Test_Disp/Test_BeautifyFormatting.js | 106 ++++++++++++++++++++++ test/Test_Disp/Test_GetTimeColour.js | 48 ++++++++++ test/t_Config/t_Toggles/t_ToggleBotBar.js | 33 +++++++ 4 files changed, 197 insertions(+) create mode 100644 test/GlobalsForTesting.js create mode 100644 test/Test_Disp/Test_BeautifyFormatting.js create mode 100644 test/Test_Disp/Test_GetTimeColour.js create mode 100644 test/t_Config/t_Toggles/t_ToggleBotBar.js diff --git a/test/GlobalsForTesting.js b/test/GlobalsForTesting.js new file mode 100644 index 0000000..90f25b5 --- /dev/null +++ b/test/GlobalsForTesting.js @@ -0,0 +1,10 @@ +export function l(id) { + if (global.domids[id] === undefined) global.domids[id] = { style: {} }; + return global.domids[id]; +} + +export const Game = { + DrawBackground() {}, + Background: { canvas: { parentNode: {} } }, + LeftBackground: { canvas: { parentNode: {} } }, +}; diff --git a/test/Test_Disp/Test_BeautifyFormatting.js b/test/Test_Disp/Test_BeautifyFormatting.js new file mode 100644 index 0000000..4629c1c --- /dev/null +++ b/test/Test_Disp/Test_BeautifyFormatting.js @@ -0,0 +1,106 @@ +import { before, describe, it } from 'mocha'; +import { assert } from 'chai'; + +import FormatTime from '../../src/Disp/BeautifyAndFormatting/FormatTime'; +import { CMOptions } from '../../src/Config/VariablesAndData'; + +describe('FormatTime', function () { + it('Format when time is Infinity', function () { + assert.equal(FormatTime(Infinity, 0), Infinity); + }); + it('Format when time is negative', function () { + assert.equal(FormatTime(-1, 0), 'Negative time period'); + }); + describe('TimeFormat = 0', function () { + before(function () { + CMOptions.TimeFormat = 0; + }); + describe('Longformat = 0', function () { + it('Format when time is 0', function () { + assert.equal(FormatTime(0, 0), '0s'); + }); + it('Format when time is 1 second', function () { + assert.equal(FormatTime(1, 0), '1s'); + }); + it('Format when time is over 1 minute', function () { + assert.equal(FormatTime(61, 0), '1m, 1s'); + }); + it('Format when time is over 1 hour', function () { + assert.equal(FormatTime(3601, 0), '1h, 0m, 1s'); + }); + it('Format when time is over 1 day', function () { + assert.equal(FormatTime(86401, 0), '1d, 0h, 0m, 1s'); + }); + it('Format when time is over 1 year', function () { + assert.equal(FormatTime(31536001, 0), '1y, 0d, 0h, 0m, 1s'); + }); + it('Format when time is over >9000 days', function () { + assert.equal(FormatTime(777600001, 0), '>9000d'); + }); + it('Format when time is over >99.9 years', function () { + assert.equal(FormatTime(3155760001, 0), '>9000d'); + }); + }); + describe('Longformat = 1', function () { + it('Format when time is 0', function () { + assert.equal(FormatTime(0, 1), '0 seconds'); + }); + it('Format when time is 1 second', function () { + assert.equal(FormatTime(1, 1), '1 second'); + }); + it('Format when time is over 1 minute', function () { + assert.equal(FormatTime(61, 1), '1 minute, 1 second'); + }); + it('Format when time is over 1 hour', function () { + assert.equal(FormatTime(3601, 1), '1 hour, 0 minutes, 1 second'); + }); + it('Format when time is over 1 day', function () { + assert.equal( + FormatTime(86401, 1), + '1 day, 0 hours, 0 minutes, 1 second', + ); + }); + it('Format when time is over 1 year', function () { + assert.equal( + FormatTime(31536001, 1), + '1 year, 0 days, 0 hours, 0 minutes, 1 second', + ); + }); + it('Format when time is over >9000 days', function () { + assert.equal(FormatTime(777600001, 1), 'Over 9000 days!'); + }); + it('Format when time is over >99.9 years', function () { + assert.equal(FormatTime(3155760001, 1), 'Over 9000 days!'); + }); + }); + }); + describe('TimeFormat = 1', function () { + before(function () { + CMOptions.TimeFormat = 1; + }); + it('Format when time is 0', function () { + assert.equal(FormatTime(0, 0), '00:00:00:00:00'); + }); + it('Format when time is 1 second', function () { + assert.equal(FormatTime(1, 0), '00:00:00:00:01'); + }); + it('Format when time is over 1 minute', function () { + assert.equal(FormatTime(61, 0), '00:00:00:01:01'); + }); + it('Format when time is over 1 hour', function () { + assert.equal(FormatTime(3601, 0), '00:00:01:00:01'); + }); + it('Format when time is over 1 day', function () { + assert.equal(FormatTime(86401, 0), '00:01:00:00:01'); + }); + it('Format when time is over 1 year', function () { + assert.equal(FormatTime(31536001, 0), '01:00:00:00:01'); + }); + it('Format when time is over >9000 days', function () { + assert.equal(FormatTime(777600001, 0), '24:240:00:00:01'); + }); + it('Format when time is over >99.9 years', function () { + assert.equal(FormatTime(3155760001, 0), 'XX:XX:XX:XX:XX'); + }); + }); +}); diff --git a/test/Test_Disp/Test_GetTimeColour.js b/test/Test_Disp/Test_GetTimeColour.js new file mode 100644 index 0000000..5b3ba2e --- /dev/null +++ b/test/Test_Disp/Test_GetTimeColour.js @@ -0,0 +1,48 @@ +import { before, describe, it } from 'mocha'; +import { expect } from 'chai'; + +import GetTimeColour from '../../src/Disp/BeautifyAndFormatting/GetTimeColour'; +import { CMOptions } from '../../src/Config/VariablesAndData'; + +describe('GetTimeColour', function () { + it('Format when time is less than 60', function () { + expect(GetTimeColour(59).color).to.deep.equal('Yellow'); + }); + it('Format when time is more than 60', function () { + expect(GetTimeColour(61).color).to.deep.equal('Orange'); + }); + it('Format when time is more than 300', function () { + expect(GetTimeColour(301).color).to.deep.equal('Red'); + }); + describe('TimeFormat = 0', function () { + before(function () { + CMOptions.TimeFormat = 0; + }); + it('Format when time is 0', function () { + expect(GetTimeColour(0)).to.deep.equal({ text: 'Done!', color: 'Green' }); + }); + it('Format when time is negative', function () { + expect(GetTimeColour(-1)).to.deep.equal({ + text: 'Done!', + color: 'Green', + }); + }); + }); + describe('TimeFormat = 1', function () { + before(function () { + CMOptions.TimeFormat = 1; + }); + it('Format when time is 0', function () { + expect(GetTimeColour(0)).to.deep.equal({ + text: '00:00:00:00:00', + color: 'Green', + }); + }); + it('Format when time is negative', function () { + expect(GetTimeColour(-1)).to.deep.equal({ + text: '00:00:00:00:00', + color: 'Green', + }); + }); + }); +}); diff --git a/test/t_Config/t_Toggles/t_ToggleBotBar.js b/test/t_Config/t_Toggles/t_ToggleBotBar.js new file mode 100644 index 0000000..863eca6 --- /dev/null +++ b/test/t_Config/t_Toggles/t_ToggleBotBar.js @@ -0,0 +1,33 @@ +import { before, beforeEach, describe, it } from 'mocha'; +import { assert } from 'chai'; +import { l, Game } from '../../GlobalsForTesting'; // eslint-disable-line no-unused-vars + +import ToggleBotBar from '../../../src/Config/Toggles/ToggleBotBar'; +import { CMOptions } from '../../../src/Config/VariablesAndData'; + +describe('ToggleBotBar', function () { + global.l = l; + global.Game = Game; + + beforeEach(function () { + global.domids = {}; + ToggleBotBar(); + }); + + describe('BotBar = 0', function () { + before(function () { + CMOptions.BotBar = 0; + }); + it('Toggle style correctly', function () { + assert.equal(domids.CMBotBar.style.display, 'none'); // eslint-disable-line no-undef + }); + }); + describe('BotBar = 1', function () { + before(function () { + CMOptions.BotBar = 1; + }); + it('Toggle style correctly', function () { + assert.equal(domids.CMBotBar.style.display, ''); // eslint-disable-line no-undef + }); + }); +});