From c47f507c0800cb76a34aa733670728733dec0e86 Mon Sep 17 00:00:00 2001 From: wwebfor Date: Fri, 20 Oct 2017 01:05:57 +0600 Subject: [PATCH] [Test] Cover theme utils --- test/tape/components/settings/show/general.js | 23 +++++++++ test/tape/utils/theme.js | 48 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 test/tape/utils/theme.js diff --git a/test/tape/components/settings/show/general.js b/test/tape/components/settings/show/general.js index 0ee8ef97a..0bff09c9f 100644 --- a/test/tape/components/settings/show/general.js +++ b/test/tape/components/settings/show/general.js @@ -26,6 +26,20 @@ test('settings/show/general/View: behaviors()', t => { t.end(); }); +test('settings/show/general/View: events()', t => { + const events = View.prototype.events(); + t.equal(typeof events, 'object', 'returns an object'); + t.equal(events['change @ui.theme'], 'previewTheme'); + t.end(); +}); + +test('settings/show/general/View: ui()', t => { + const ui = View.prototype.ui(); + t.equal(typeof ui, 'object', 'returns an object'); + t.equal(ui.theme, '#theme'); + t.end(); +}); + test('settings/show/general/View: serializeData()', t => { const collection = new Configs(); collection.resetFromObject(collection.configNames); @@ -37,7 +51,9 @@ test('settings/show/general/View: serializeData()', t => { t.equal(typeof res, 'object', 'returns an object'); t.equal(typeof res.locales, 'object', 'has locales'); t.deepEqual(res.models, collection.getConfigs(), 'has models'); + t.deepEqual(typeof res.themes, 'object', 'has themes'); t.equal(res.appLang, 'en', 'has appLang'); + t.equal(res.theme, 'default', 'has theme'); t.equal(res.profileId, 'test', 'has profileId'); t.equal(res.useDefault, useDefault.attributes, 'has useDefault model'); @@ -72,5 +88,12 @@ test('settings/show/general/View: templateContext()', t => { t.equal(context.selectLocale('fr'), undefined, 'does nothing if the locale is not equal to appLang'); + context.theme = 'default'; + t.equal(context.selectTheme('dark'), undefined, + 'returns nothing if the theme is not active'); + + t.equal(context.selectTheme('default'), ' selected', + 'selects the theme if it is active'); + t.end(); }); diff --git a/test/tape/utils/theme.js b/test/tape/utils/theme.js new file mode 100644 index 000000000..d8d3a4940 --- /dev/null +++ b/test/tape/utils/theme.js @@ -0,0 +1,48 @@ +/** + * Test: utils/theme.js + * @file + */ +import test from 'tape'; +import sinon from 'sinon'; +import Radio from 'backbone.radio'; +import theme from '../../../app/scripts/utils/theme'; + +let sand; +test('utils/theme: before()', t => { + sand = sinon.sandbox.create(); + t.end(); +}); + +test('utils/theme: applyTheme()', t => { + const attr = sand.stub(); + global.$ = sand.stub().returns({attr}); + + sand.stub(Radio, 'request') + .withArgs('collections/Configs', 'findConfig', {name: 'theme'}) + .returns('default'); + + theme.applyTheme(); + t.equal(attr.calledWithMatch('href', 'styles/theme-default.css'), true, + 'applies the default theme'); + + theme.applyTheme({name: 'dark'}); + t.equal(attr.calledWith('href', 'styles/theme-dark.css'), true, + 'applies the dark theme'); + + sand.restore(); + t.end(); +}); + +test('utils/theme: initializer()', t => { + const on = sand.stub(Radio, 'on'); + sand.stub(theme, 'applyTheme'); + + theme.initializer(); + + t.equal(theme.applyTheme.called, true, 'applies the theme'); + t.equal(on.calledWith('components/settings', 'changeTheme', theme.applyTheme), + true, 'listens to "changeTheme" event'); + + sand.restore(); + t.end(); +});