From 4ced18a2d40d2ba671466d13b1370d3e63d3e1c7 Mon Sep 17 00:00:00 2001 From: Lucas Hrabovsky Date: Wed, 25 Jan 2017 11:06:42 -0500 Subject: [PATCH 1/5] COMPASS-586: Improve Linux appearance (logo in popups/about box, ...) (#762) * COMPASS-586: Improve Linux appearance (logo in popups/about box, ...) * assert.equals => assert.equal --- src/app/connect/index.js | 2 ++ src/icon.js | 19 +++++++++++++++++++ .../schema/lib/store/index.js | 3 +++ src/main/window-manager.js | 17 +++++++++++++---- test/unit/icon.test.js | 8 ++++++++ 5 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 src/icon.js create mode 100644 test/unit/icon.test.js diff --git a/src/app/connect/index.js b/src/app/connect/index.js index 3a78f9dff8f..d7b45f1cf45 100644 --- a/src/app/connect/index.js +++ b/src/app/connect/index.js @@ -16,6 +16,7 @@ var dialog = remote.dialog; var Clipboard = remote.clipboard; var BrowserWindow = remote.BrowserWindow; var metrics = require('mongodb-js-metrics')(); +var COMPASS_ICON = require('../../icon'); var debug = require('debug')('mongodb-compass:connect:index'); @@ -331,6 +332,7 @@ var ConnectView = View.extend({ // ask user if Compass should use it to fill out form dialog.showMessageBox(BrowserWindow.getFocusedWindow(), { type: 'info', + icon: COMPASS_ICON, message: 'MongoDB connection string detected', detail: 'Compass detected a MongoDB connection string in your ' + 'clipboard. Do you want to use the connection string to ' diff --git a/src/icon.js b/src/icon.js new file mode 100644 index 00000000000..9f5325ad201 --- /dev/null +++ b/src/icon.js @@ -0,0 +1,19 @@ +var path = require('path'); +var COMPASS_ICON = path.join(__dirname, 'app', 'images', 'compass-dialog-icon.png'); +var nativeImage = require('electron').nativeImage; + +/** + * Convenience for getting the app icon to customize native UI components + * via electron. + * + * @example + * ```javascript + * var icon = require('./icon'); + * var dialog = require('electron').dialog; + * dialog.showMessageBox({icon: icon, message: 'I have a nice Compass icon.'}); + * ``` + * + * @see https://jira.mongodb.org/browse/COMPASS-586 + */ +module.exports = nativeImage.createFromPath(COMPASS_ICON); +module.exports.path = COMPASS_ICON; diff --git a/src/internal-packages/schema/lib/store/index.js b/src/internal-packages/schema/lib/store/index.js index bfb9bcd425d..4a450e5ec21 100644 --- a/src/internal-packages/schema/lib/store/index.js +++ b/src/internal-packages/schema/lib/store/index.js @@ -7,6 +7,8 @@ const schemaStream = require('mongodb-schema').stream; const toNS = require('mongodb-ns'); const ReadPreference = require('mongodb').ReadPreference; +const COMPASS_ICON = require('../../../../icon'); + /** * The default read preference. */ @@ -72,6 +74,7 @@ const SchemaStore = Reflux.createStore({ dialog.showMessageBox(BrowserWindow.getFocusedWindow(), { type: 'info', + icon: COMPASS_ICON, message: 'Share Schema', detail: detail, buttons: ['OK'] diff --git a/src/main/window-manager.js b/src/main/window-manager.js index 07feff748e6..420cef0f2a1 100644 --- a/src/main/window-manager.js +++ b/src/main/window-manager.js @@ -14,6 +14,7 @@ var debug = require('debug')('mongodb-compass:electron:window-manager'); var dialog = electron.dialog; var path = require('path'); var ipc = require('hadron-ipc'); +var COMPASS_ICON = require('../icon'); /** * When running in electron, we're in `/src/main`. @@ -118,13 +119,21 @@ var createWindow = module.exports.create = function(opts) { width: DEFAULT_WIDTH, height: DEFAULT_HEIGHT, minwidth: MIN_WIDTH, - url: DEFAULT_URL + url: DEFAULT_URL, + /** + * On Windows and macOS, this will be set automatically to the optimal + * app icon. Only on Linux do we need to set this explictly. + * + * @see https://jira.mongodb.org/browse/COMPASS-586 + */ + icon: process.platform === 'linux' ? COMPASS_ICON : undefined }); debug('creating new window: ' + opts.url); var _window = new BrowserWindow({ width: opts.width, height: opts.height, + icon: opts.icon, 'min-width': opts.minwidth, 'web-preferences': { 'subpixel-font-scaling': true, @@ -164,9 +173,9 @@ function showConnectWindow() { function showAboutDialog() { dialog.showMessageBox({ type: 'info', - title: 'About MongoDB Compass', - icon: path.join(RESOURCES, 'images', 'compass-dialog-icon.png'), - message: 'MongoDB Compass', + title: 'About ' + app.getName(), + icon: COMPASS_ICON, + message: app.getName(), detail: 'Version ' + app.getVersion(), buttons: ['OK'] }); diff --git a/test/unit/icon.test.js b/test/unit/icon.test.js new file mode 100644 index 00000000000..5c278b40f23 --- /dev/null +++ b/test/unit/icon.test.js @@ -0,0 +1,8 @@ +var assert = require('assert'); +var icon = require('../../src/icon'); + +describe('icon', function() { + it('should be a non-empty nativeImage', function() { + assert.equal(icon.isEmpty(), false); + }); +}); From 01e8a139536eb3b8290b938003424c7c69a23c17 Mon Sep 17 00:00:00 2001 From: Peter Schmidt Date: Thu, 23 Feb 2017 08:17:23 +1100 Subject: [PATCH 2/5] COMPASS-788: mongodb:// in clipboard message has regressed on macOS / Red Hat (#787) * Fix white screen and icon on macOS If you have a string prefixed with `mongodb://`, e.g. every Atlas URL, present in your clipboard. * Fix icon on Share Schema as JSON message box Tested on a Red Hat VirtualBox VM, as per: https://github.com/10gen/compass-internal-docs/pull/4 * Add regression test for the share-schema-as-json feature Not unit testing the Ampersand View clipboard version as I have no idea how to do so. --- package.json | 1 + src/app/connect/index.js | 4 +- .../schema/lib/store/index.js | 4 +- test/renderer/share-schema-as-json.test.js | 52 +++++++++++++++++++ 4 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 test/renderer/share-schema-as-json.test.js diff --git a/package.json b/package.json index 4b4397e9af5..ce225d3d73e 100644 --- a/package.json +++ b/package.json @@ -200,6 +200,7 @@ "mongodb-runner": "^3.4.0", "react-addons-test-utils": "^15.2.1", "sinon": "^1.17.6", + "sinon-chai": "^2.8.0", "spectron": "^3.2.6", "xvfb-maybe": "^0.1.3" }, diff --git a/src/app/connect/index.js b/src/app/connect/index.js index d7b45f1cf45..c09cf774b5e 100644 --- a/src/app/connect/index.js +++ b/src/app/connect/index.js @@ -16,7 +16,7 @@ var dialog = remote.dialog; var Clipboard = remote.clipboard; var BrowserWindow = remote.BrowserWindow; var metrics = require('mongodb-js-metrics')(); -var COMPASS_ICON = require('../../icon'); +var COMPASS_ICON_PATH = require('../../icon').path; var debug = require('debug')('mongodb-compass:connect:index'); @@ -332,7 +332,7 @@ var ConnectView = View.extend({ // ask user if Compass should use it to fill out form dialog.showMessageBox(BrowserWindow.getFocusedWindow(), { type: 'info', - icon: COMPASS_ICON, + icon: COMPASS_ICON_PATH, message: 'MongoDB connection string detected', detail: 'Compass detected a MongoDB connection string in your ' + 'clipboard. Do you want to use the connection string to ' diff --git a/src/internal-packages/schema/lib/store/index.js b/src/internal-packages/schema/lib/store/index.js index 4a450e5ec21..5c2d36416ac 100644 --- a/src/internal-packages/schema/lib/store/index.js +++ b/src/internal-packages/schema/lib/store/index.js @@ -7,7 +7,7 @@ const schemaStream = require('mongodb-schema').stream; const toNS = require('mongodb-ns'); const ReadPreference = require('mongodb').ReadPreference; -const COMPASS_ICON = require('../../../../icon'); +const COMPASS_ICON_PATH = require('../../../../icon').path; /** * The default read preference. @@ -74,7 +74,7 @@ const SchemaStore = Reflux.createStore({ dialog.showMessageBox(BrowserWindow.getFocusedWindow(), { type: 'info', - icon: COMPASS_ICON, + icon: COMPASS_ICON_PATH, message: 'Share Schema', detail: detail, buttons: ['OK'] diff --git a/test/renderer/share-schema-as-json.test.js b/test/renderer/share-schema-as-json.test.js new file mode 100644 index 00000000000..c8c2aeef4e5 --- /dev/null +++ b/test/renderer/share-schema-as-json.test.js @@ -0,0 +1,52 @@ +/* eslint no-unused-expressions: 0 */ +const app = require('hadron-app'); +const sinon = require('sinon'); +const { remote } = require('electron'); +const chai = require('chai'); +const sinonChai = require('sinon-chai'); +const expect = chai.expect; +const COMPASS_ICON_PATH = require('../../src/icon').path; + +// For `expect(mySpy).to.have.been.calledWith("foo");` syntax +chai.use(sinonChai); + +describe('SchemaStore', function() { + let writeText; + let showMessageBox; + + beforeEach(function() { + this.SchemaStore = app.appRegistry.getStore('Schema.Store'); + this.clipboardSpy = sinon.spy(); + this.messageBoxSpy = sinon.spy(); + writeText = remote.clipboard.writeText; + showMessageBox = remote.dialog.showMessageBox; + remote.clipboard.writeText = this.clipboardSpy; + remote.dialog.showMessageBox = this.messageBoxSpy; + }); + + afterEach(function() { + remote.clipboard.writeText = writeText; + remote.dialog.showMessageBox = showMessageBox; + }); + + context('shares a "null" schema as JSON', function() { + beforeEach(function() { + // Note that normally this menu option is only exposed after the user has + // connected to an instance, navigated to a collection and sampled schema + this.SchemaStore.handleSchemaShare(); + }); + it('copies to the clipboard', function() { + expect(this.clipboardSpy).to.have.been.calledWith('null'); + }); + it('displays an informative message box', function() { + expect(this.messageBoxSpy).to.have.been.calledWith(null, { + buttons: ['OK'], + detail: 'The schema definition of ' + + ' has been copied to your clipboard in JSON format.', + icon: COMPASS_ICON_PATH, + message: 'Share Schema', + type: 'info' + }); + }); + }); +}); From 89006ca4484861a7d4619ea244c8cb912c7c4026 Mon Sep 17 00:00:00 2001 From: Peter Schmidt Date: Thu, 23 Feb 2017 11:32:24 +1100 Subject: [PATCH 3/5] Update hadron-app => ampersand-app MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As we don’t expect to back port b4a5a260aec9723ba09a87110467916958a31538 --- test/renderer/share-schema-as-json.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/renderer/share-schema-as-json.test.js b/test/renderer/share-schema-as-json.test.js index c8c2aeef4e5..f0d56f8478c 100644 --- a/test/renderer/share-schema-as-json.test.js +++ b/test/renderer/share-schema-as-json.test.js @@ -1,5 +1,5 @@ /* eslint no-unused-expressions: 0 */ -const app = require('hadron-app'); +const app = require('ampersand-app'); const sinon = require('sinon'); const { remote } = require('electron'); const chai = require('chai'); From 0a0a8b6f73dd29e4f29007c466d09a451284fd5a Mon Sep 17 00:00:00 2001 From: Peter Schmidt Date: Thu, 2 Feb 2017 23:05:12 +1100 Subject: [PATCH 4/5] [Selectively cherry-picked from COMPASS 701 Charts] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Extract PackageManager setup into its own file So I can possibly reuse it in tests where I’d like to test our listenToExternalStore wiring. * Expand the --renderer test so it can handle integration tests Tried several times to get this into the --unit tests, but our internal-packages tend to depend on “window” and “document” so that is not possible. Both those are genuinely available in the renderer process so it’s definitely a better home for these tests for now. We can decide later when we have more if they can or should be decoupled further. --- src/app/index.js | 6 +----- src/app/setup-package-manager.js | 8 ++++++++ test/renderer/_setup.js | 10 ++++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 src/app/setup-package-manager.js create mode 100644 test/renderer/_setup.js diff --git a/src/app/index.js b/src/app/index.js index 3afb1022151..b03c5d936b1 100644 --- a/src/app/index.js +++ b/src/app/index.js @@ -21,8 +21,6 @@ var ModuleCache = require('hadron-module-cache'); ModuleCache.register(resourcePath); ModuleCache.add(resourcePath); -var AppRegistry = require('hadron-app-registry'); -var PackageManager = require('hadron-package-manager').PackageManager; var pkg = require('../../package.json'); var CompileCache = require('hadron-compile-cache'); @@ -94,9 +92,7 @@ new StyleManager( // order to ensure that the compile cache has already been loaded and // hooked into require.extensions. Otherwise, packages will not have // use of the compile cache. -app.appRegistry = new AppRegistry(); -app.packageManager = new PackageManager(path.join(__dirname, '..', 'internal-packages')); -app.packageManager.activate(); +require('./setup-package-manager'); function getConnection(model, done) { function _fetch(fn) { diff --git a/src/app/setup-package-manager.js b/src/app/setup-package-manager.js new file mode 100644 index 00000000000..0c2b778f492 --- /dev/null +++ b/src/app/setup-package-manager.js @@ -0,0 +1,8 @@ +const app = require('ampersand-app'); +const path = require('path'); +const AppRegistry = require('hadron-app-registry'); +const { PackageManager } = require('hadron-package-manager'); + +app.appRegistry = new AppRegistry(); +app.packageManager = new PackageManager(path.join(__dirname, '..', 'internal-packages')); +app.packageManager.activate(); diff --git a/test/renderer/_setup.js b/test/renderer/_setup.js new file mode 100644 index 00000000000..d2a5d82a959 --- /dev/null +++ b/test/renderer/_setup.js @@ -0,0 +1,10 @@ +require('babel-register')(); + +require('../../src/app/reflux-listen-to-external-store'); + +// Would be nice not to need this jQuery being present +window.jQuery = require('jquery'); + +// Require our internal-packages so we can integration-test things fast, +// i.e. without requiring a full functional test +require('../../src/app/setup-package-manager'); From 10b58e48a8ce74402ec07aa4a745831c8c19a4de Mon Sep 17 00:00:00 2001 From: Peter Schmidt Date: Thu, 23 Feb 2017 18:14:15 +1100 Subject: [PATCH 5/5] =?UTF-8?q?Add=20=E2=80=98undefined=E2=80=99=20to=20sh?= =?UTF-8?q?are-schema-as-json=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Not sure why this is ‘undefined’ on this branch but not master, but there’s a lot of hadron-app and other changes floating around so it probably doesn’t matter. --- test/renderer/share-schema-as-json.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/renderer/share-schema-as-json.test.js b/test/renderer/share-schema-as-json.test.js index f0d56f8478c..0ce010678ec 100644 --- a/test/renderer/share-schema-as-json.test.js +++ b/test/renderer/share-schema-as-json.test.js @@ -42,6 +42,7 @@ describe('SchemaStore', function() { expect(this.messageBoxSpy).to.have.been.calledWith(null, { buttons: ['OK'], detail: 'The schema definition of ' + + 'undefined' + ' has been copied to your clipboard in JSON format.', icon: COMPASS_ICON_PATH, message: 'Share Schema',