Skip to content

Commit

Permalink
[Test] Cover theme utils
Browse files Browse the repository at this point in the history
  • Loading branch information
wwebfor committed Oct 19, 2017
1 parent 3d79228 commit c47f507
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/tape/components/settings/show/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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');

Expand Down Expand Up @@ -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();
});
48 changes: 48 additions & 0 deletions test/tape/utils/theme.js
Original file line number Diff line number Diff line change
@@ -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();
});

0 comments on commit c47f507

Please sign in to comment.