Skip to content

Commit

Permalink
Merge pull request #1065 from araujoarthur0/electron-mocha-renderer-m…
Browse files Browse the repository at this point in the history
…igration
  • Loading branch information
tupaschoal authored Mar 10, 2024
2 parents a85f0d5 + be788cd commit 23f0560
Show file tree
Hide file tree
Showing 7 changed files with 1,428 additions and 31 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/Checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,17 @@ jobs:
fi
npm run test:electron-mocha-main
# Move initial coverage to avoid it being replaced below by renderer run
mv coverage_c8 coverage-electron-mocha-main
npm run test:electron-mocha-renderer
npm run test:jest
npm run test:mocha
- name: ' CodeCov'
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage_c8/coverage-final.json,coverage_jest/coverage-final.json,coverage_mocha/coverage-final.json
files: coverage-electron-mocha-main/coverage-final.json,coverage_c8/coverage-final.json,coverage_jest/coverage-final.json,coverage_mocha/coverage-final.json
name: codecov-${{ matrix.os }}
verbose: true
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']
}
]
};
Loading

0 comments on commit 23f0560

Please sign in to comment.