Skip to content

Commit

Permalink
Adding npm script for renderer tests & migrating themes.js
Browse files Browse the repository at this point in the history
  • Loading branch information
araujoarthur0 committed Mar 9, 2024
1 parent 708d438 commit e17a536
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
28 changes: 22 additions & 6 deletions __tests__/__renderer__/themes.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
/* eslint-disable no-undef */
'use strict';

const assert = require('assert');
import assert from 'assert';
import { stub } from 'sinon';

import {
applyTheme,
isValidTheme
} from '../../renderer/themes.js';
window.$ = window.jQuery = require('jquery');

// Stub $ and window.matchMedia for applyTheme()
global.$ = stub().returns({'attr': stub()});
global.window = { matchMedia: stub().returns({matches: true}) };

describe('Theme Functions', function()
{
describe('isValidTheme()', function()
{
test('should validate', () =>
it('should validate', () =>
{
assert.strictEqual(isValidTheme('system-default'), true);
assert.strictEqual(isValidTheme('light'), true);
Expand All @@ -24,7 +28,7 @@ describe('Theme Functions', function()

describe('isValidTheme()', function()
{
test('should not validate', () =>
it('should not validate', () =>
{
assert.strictEqual(isValidTheme('foo'), false);
assert.strictEqual(isValidTheme('bar'), false);
Expand All @@ -33,18 +37,30 @@ describe('Theme Functions', function()

describe('applyTheme()', function()
{
test('should apply', () =>
beforeEach(() =>
{
global.window.matchMedia.resetHistory();
global.$.resetHistory();
});

it('should apply', () =>
{
assert.strictEqual(applyTheme('system-default'), true);
assert.strictEqual(applyTheme('light'), true);
assert.strictEqual(applyTheme('dark'), true);
assert.strictEqual(applyTheme('cadent-star'), true);

assert.strictEqual(global.window.matchMedia.callCount, 1);
assert.strictEqual(global.$.callCount, 4);
});

test('should not apply', function()
it('should not apply', function()
{
assert.strictEqual(applyTheme('foo'), false);
assert.strictEqual(applyTheme('bar'), false);

assert.strictEqual(global.window.matchMedia.callCount, 0);
assert.strictEqual(global.$.callCount, 0);
});
});
});
5 changes: 5 additions & 0 deletions __tests__/electron-mocha-renderer.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const data = require('./mocha-base.config.cjs');

data.spec = ['__tests__/__renderer__/themes.js'];

module.exports = data;
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {
displayName: 'RENDERER',
runner: '@jest-runner/electron',
testEnvironment: '@jest-runner/electron/environment',
testMatch: ['**/__tests__/**renderer**/*.js', '**/__tests__/**renderer**/classes/*.js']
testMatch: ['**/__tests__/**renderer**/*.js', '**/__tests__/**renderer**/classes/*.js', '!**/themes.js']
}
]
};

0 comments on commit e17a536

Please sign in to comment.