Skip to content

Commit

Permalink
chore(compass): Add renderer test for theme (#2774)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anemy authored Feb 10, 2022
1 parent 0d3dc85 commit 5d22a79
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/compass/.mocharc.renderer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@mongodb-js/mocha-config-compass/compass-plugin');
4 changes: 3 additions & 1 deletion packages/compass/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@
"prestart": "npm run electron-rebuild",
"start": "npm run webpack serve -- --mode development",
"pretest": "npm run electron-rebuild",
"test": "xvfb-maybe electron-mocha --no-sandbox",
"test": "npm run test-main && npm run test-renderer",
"test-main": "xvfb-maybe electron-mocha --no-sandbox \"./src/main/**/*.spec.*\" \"./src/main/**/*.test.*\"",
"test-renderer": "xvfb-maybe electron-mocha --config ./.mocharc.renderer.js \"./src/app/**/*.spec.js\"",
"posttest": "node ../../scripts/rebuild.js kerberos keytar interruptor",
"check": "npm run lint && npm run depcheck",
"prewebpack": "rimraf ./build",
Expand Down
2 changes: 1 addition & 1 deletion packages/compass/src/app/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ module.exports = {
enableDarkTheme,
disableDarkTheme,
loadTheme
}
};
92 changes: 92 additions & 0 deletions packages/compass/src/app/theme.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
const { expect } = require('chai');
const sinon = require('sinon');

const {
enableDarkTheme,
disableDarkTheme,
loadTheme
} = require('./theme');

describe('theme', function() {
let appRegistryEmitSpy;

beforeEach(function() {
appRegistryEmitSpy = sinon.fake();

global.hadronApp = {
appRegistry: {
emit: appRegistryEmitSpy
}
};
});

describe('#enableDarkTheme', function() {
it('should set the dark theme on the global hadron app', function() {
expect(global.hadronApp.theme).to.equal(undefined);

enableDarkTheme();

expect(global.hadronApp.theme).to.equal('Dark');
});

it('should emit the dark theme to the app registry', function() {
expect(appRegistryEmitSpy.callCount).to.equal(0);

enableDarkTheme();

expect(appRegistryEmitSpy.callCount).to.equal(1);
expect(appRegistryEmitSpy.firstCall.args[0]).to.equal('darkmode-enable');
expect(global.hadronApp.theme).to.equal('Dark');
});
});

describe('#disableDarkTheme', function() {
it('should set the light theme on the global hadron app', function() {
expect(global.hadronApp.theme).to.equal(undefined);

disableDarkTheme();

expect(global.hadronApp.theme).to.equal('Light');
});

it('should emit disable dark theme to the app registry', function() {
expect(appRegistryEmitSpy.callCount).to.equal(0);

disableDarkTheme();

expect(appRegistryEmitSpy.callCount).to.equal(1);
expect(appRegistryEmitSpy.firstCall.args[0]).to.equal('darkmode-disable');
expect(global.hadronApp.theme).to.equal('Light');
});
});

describe('#loadTheme', function() {
it('should set the dark theme on the app registry', function() {
expect(global.hadronApp.theme).to.equal(undefined);

loadTheme('DARK');

expect(global.hadronApp.theme).to.equal('Dark');
expect(appRegistryEmitSpy.firstCall.args[0]).to.equal('darkmode-enable');
expect(appRegistryEmitSpy.callCount).to.equal(1);
});

it('should set the light theme on the app registry', function() {
expect(appRegistryEmitSpy.callCount).to.equal(0);

loadTheme('LIGHT');

expect(appRegistryEmitSpy.callCount).to.equal(1);
expect(appRegistryEmitSpy.firstCall.args[0]).to.equal('darkmode-disable');
expect(global.hadronApp.theme).to.equal('Light');
});

it('should set the theme on the app registry with os theme', function() {
expect(appRegistryEmitSpy.callCount).to.equal(0);

loadTheme('OS_THEME');

expect(appRegistryEmitSpy.callCount).to.equal(1);
})
});
});

0 comments on commit 5d22a79

Please sign in to comment.