diff --git a/package.json b/package.json index fa279c5871c..06397cbee94 100644 --- a/package.json +++ b/package.json @@ -208,6 +208,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 e6344144bbc..5b966b2e961 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 18b7860523b..29c614e796a 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. @@ -78,7 +78,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' + }); + }); + }); +});