|
| 1 | +/* eslint no-unused-expressions: 0 */ |
| 2 | +const app = require('ampersand-app'); |
| 3 | +const sinon = require('sinon'); |
| 4 | +const { remote } = require('electron'); |
| 5 | +const chai = require('chai'); |
| 6 | +const sinonChai = require('sinon-chai'); |
| 7 | +const expect = chai.expect; |
| 8 | +const COMPASS_ICON_PATH = require('../../src/icon').path; |
| 9 | + |
| 10 | +// For `expect(mySpy).to.have.been.calledWith("foo");` syntax |
| 11 | +chai.use(sinonChai); |
| 12 | + |
| 13 | +describe('SchemaStore', function() { |
| 14 | + let writeText; |
| 15 | + let showMessageBox; |
| 16 | + |
| 17 | + beforeEach(function() { |
| 18 | + this.SchemaStore = app.appRegistry.getStore('Schema.Store'); |
| 19 | + this.clipboardSpy = sinon.spy(); |
| 20 | + this.messageBoxSpy = sinon.spy(); |
| 21 | + writeText = remote.clipboard.writeText; |
| 22 | + showMessageBox = remote.dialog.showMessageBox; |
| 23 | + remote.clipboard.writeText = this.clipboardSpy; |
| 24 | + remote.dialog.showMessageBox = this.messageBoxSpy; |
| 25 | + }); |
| 26 | + |
| 27 | + afterEach(function() { |
| 28 | + remote.clipboard.writeText = writeText; |
| 29 | + remote.dialog.showMessageBox = showMessageBox; |
| 30 | + }); |
| 31 | + |
| 32 | + context('shares a "null" schema as JSON', function() { |
| 33 | + beforeEach(function() { |
| 34 | + // Note that normally this menu option is only exposed after the user has |
| 35 | + // connected to an instance, navigated to a collection and sampled schema |
| 36 | + this.SchemaStore.handleSchemaShare(); |
| 37 | + }); |
| 38 | + it('copies to the clipboard', function() { |
| 39 | + expect(this.clipboardSpy).to.have.been.calledWith('null'); |
| 40 | + }); |
| 41 | + it('displays an informative message box', function() { |
| 42 | + expect(this.messageBoxSpy).to.have.been.calledWith(null, { |
| 43 | + buttons: ['OK'], |
| 44 | + detail: 'The schema definition of ' + |
| 45 | + 'undefined' + |
| 46 | + ' has been copied to your clipboard in JSON format.', |
| 47 | + icon: COMPASS_ICON_PATH, |
| 48 | + message: 'Share Schema', |
| 49 | + type: 'info' |
| 50 | + }); |
| 51 | + }); |
| 52 | + }); |
| 53 | +}); |
0 commit comments