From b826097237d61fc778189fdfdb4c8c21d74d0e9d Mon Sep 17 00:00:00 2001 From: Evan Hahn <69474926+EvanHahn-Signal@users.noreply.github.com> Date: Wed, 28 Jul 2021 18:46:25 -0500 Subject: [PATCH] Show window titlebar in test --- main.js | 19 ++++++++----------- ts/environment.ts | 3 +++ ts/test-both/environment_test.ts | 19 ++++++++++++++++++- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/main.js b/main.js index c738eafee..c42125a4b 100644 --- a/main.js +++ b/main.js @@ -120,7 +120,7 @@ const { getTitleBarVisibility, TitleBarVisibility, } = require('./ts/types/Settings'); -const { Environment } = require('./ts/environment'); +const { Environment, isTestEnvironment } = require('./ts/environment'); const { ChallengeMainHandler } = require('./ts/main/challengeMain'); const { NativeThemeNotifier } = require('./ts/main/NativeThemeNotifier'); const { PowerChannel } = require('./ts/main/powerChannel'); @@ -362,13 +362,13 @@ async function createWindow() { minHeight: MIN_HEIGHT, autoHideMenuBar: false, titleBarStyle: - getTitleBarVisibility() === TitleBarVisibility.Hidden + getTitleBarVisibility() === TitleBarVisibility.Hidden && + !isTestEnvironment(config.environment) ? 'hidden' : 'default', - backgroundColor: - config.environment === 'test' || config.environment === 'test-lib' - ? '#ffffff' // Tests should always be rendered on a white background - : '#3a76f0', + backgroundColor: isTestEnvironment(config.environment) + ? '#ffffff' // Tests should always be rendered on a white background + : '#3a76f0', webPreferences: { ...defaultWebPrefs, nodeIntegration: false, @@ -518,8 +518,7 @@ async function createWindow() { }); // If the application is terminating, just do the default if ( - config.environment === 'test' || - config.environment === 'test-lib' || + isTestEnvironment(config.environment) || (mainWindow.readyForShutdown && windowState.shouldQuit()) ) { return; @@ -1478,9 +1477,7 @@ app.on('window-all-closed', () => { // On OS X it is common for applications and their menu bar // to stay active until the user quits explicitly with Cmd + Q const shouldAutoClose = - !OS.isMacOS() || - config.environment === 'test' || - config.environment === 'test-lib'; + !OS.isMacOS() || isTestEnvironment(config.environment); // Only automatically quit if the main window has been created // This is necessary because `window-all-closed` can be triggered by the diff --git a/ts/environment.ts b/ts/environment.ts index 92795de6a..8a64af416 100644 --- a/ts/environment.ts +++ b/ts/environment.ts @@ -39,3 +39,6 @@ export const parseEnvironment = makeEnumParser( Environment, Environment.Production ); + +export const isTestEnvironment = (env: Environment): boolean => + env === Environment.Test || env === Environment.TestLib; diff --git a/ts/test-both/environment_test.ts b/ts/test-both/environment_test.ts index 604c47cda..5fbebefb2 100644 --- a/ts/test-both/environment_test.ts +++ b/ts/test-both/environment_test.ts @@ -3,7 +3,11 @@ import { assert } from 'chai'; -import { parseEnvironment, Environment } from '../environment'; +import { + Environment, + isTestEnvironment, + parseEnvironment, +} from '../environment'; describe('environment utilities', () => { describe('parseEnvironment', () => { @@ -38,4 +42,17 @@ describe('environment utilities', () => { assert.equal(parseEnvironment('test-lib'), Environment.TestLib); }); }); + + describe('isTestEnvironment', () => { + it('returns false for non-test environments', () => { + assert.isFalse(isTestEnvironment(Environment.Development)); + assert.isFalse(isTestEnvironment(Environment.Production)); + assert.isFalse(isTestEnvironment(Environment.Staging)); + }); + + it('returns true for test environments', () => { + assert.isTrue(isTestEnvironment(Environment.Test)); + assert.isTrue(isTestEnvironment(Environment.TestLib)); + }); + }); });