From 0068e7d4a7d4a94f7777792d2cd73403b24778f4 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Tue, 17 Nov 2015 17:39:57 -0800 Subject: [PATCH] fix(specs): Update specs following 0.29.2 > 0.34.3 move --- .../composer/spec/composer-view-spec.cjsx | 15 +++++++++------ spec/module-cache-spec.coffee | 1 + spec/nylas-protocol-handler-spec.coffee | 2 +- spec/nylas-test-utils.coffee | 10 ++++++++++ src/components/key-commands-region.cjsx | 1 + 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/internal_packages/composer/spec/composer-view-spec.cjsx b/internal_packages/composer/spec/composer-view-spec.cjsx index 6f4e7cb19..6db0e2436 100644 --- a/internal_packages/composer/spec/composer-view-spec.cjsx +++ b/internal_packages/composer/spec/composer-view-spec.cjsx @@ -130,8 +130,8 @@ makeComposer = -> describe "populated composer", -> beforeEach -> - @isSending = {state: false} - spyOn(DraftStore, "isSendingDraft").andCallFake => @isSending.state + @isSending = false + spyOn(DraftStore, "isSendingDraft").andCallFake => @isSending afterEach -> DraftStore._cleanupAllSessions() @@ -524,7 +524,7 @@ describe "populated composer", -> useFullDraft.apply(@); makeComposer.call(@) sendBtn = React.findDOMNode(@composer.refs.sendButton) ReactTestUtils.Simulate.click sendBtn - @isSending.state = true + @isSending = true DraftStore.trigger() ReactTestUtils.Simulate.click sendBtn expect(Actions.sendDraft).toHaveBeenCalledWith(DRAFT_CLIENT_ID) @@ -537,17 +537,20 @@ describe "populated composer", -> NylasTestUtils.loadKeymap("internal_packages/composer/keymaps/composer") @$composer = @composer.refs.composerWrap - it "sends the draft on cmd-enter", -> + fit "sends the draft on cmd-enter", -> NylasTestUtils.keyPress("cmd-enter", React.findDOMNode(@$composer)) expect(Actions.sendDraft).toHaveBeenCalled() + expect(Actions.sendDraft.calls.length).toBe 1 it "does not send the draft on enter if the button isn't in focus", -> NylasTestUtils.keyPress("enter", React.findDOMNode(@$composer)) expect(Actions.sendDraft).not.toHaveBeenCalled() - it "doesn't let you send twice", -> + fit "doesn't let you send twice", -> NylasTestUtils.keyPress("cmd-enter", React.findDOMNode(@$composer)) - @isSending.state = true + expect(Actions.sendDraft).toHaveBeenCalled() + expect(Actions.sendDraft.calls.length).toBe 1 + @isSending = true DraftStore.trigger() NylasTestUtils.keyPress("cmd-enter", React.findDOMNode(@$composer)) expect(Actions.sendDraft).toHaveBeenCalled() diff --git a/spec/module-cache-spec.coffee b/spec/module-cache-spec.coffee index 85487280d..10d8bacde 100644 --- a/spec/module-cache-spec.coffee +++ b/spec/module-cache-spec.coffee @@ -86,6 +86,7 @@ describe 'ModuleCache', -> exports.load = function() { require('underscore'); }; """ + spyOn(process, 'cwd').andReturn('/') # Required when running this test from CLI packageMain = require(indexPath) Module._findPath.reset() expect(-> packageMain.load()).toThrow() diff --git a/spec/nylas-protocol-handler-spec.coffee b/spec/nylas-protocol-handler-spec.coffee index fa048ffc5..e3b7b9312 100644 --- a/spec/nylas-protocol-handler-spec.coffee +++ b/spec/nylas-protocol-handler-spec.coffee @@ -3,7 +3,7 @@ describe '"nylas" protocol URL', -> called = false request = new XMLHttpRequest() request.addEventListener('load', -> called = true) - request.open('GET', 'nylas://async/package.json', true) + request.open('GET', 'nylas://account-sidebar/package.json', true) request.send() waitsFor 'request to be done', -> called is true diff --git a/spec/nylas-test-utils.coffee b/spec/nylas-test-utils.coffee index 079d36faf..453438a48 100644 --- a/spec/nylas-test-utils.coffee +++ b/spec/nylas-test-utils.coffee @@ -13,6 +13,16 @@ NylasTestUtils = NylasEnv.keymaps.loadKeymap(keymapPath) keyPress: (key, target) -> + # React's "renderIntoDocument" does not /actually/ attach the component + # to the document. It's a sham: http://dragon.ak.fbcdn.net/hphotos-ak-xpf1/t39.3284-6/10956909_1423563877937976_838415501_n.js + # The Atom keymap manager doesn't work correctly on elements outside of the + # DOM tree, so we need to attach it. + unless document.contains(target) + parent = target + while parent.parentNode? + parent = parent.parentNode + document.documentElement.appendChild(parent) + event = KeymapManager.buildKeydownEvent(key, target: target) NylasEnv.keymaps.handleKeyboardEvent(event) diff --git a/src/components/key-commands-region.cjsx b/src/components/key-commands-region.cjsx index 684150ebf..8d5d4fa29 100644 --- a/src/components/key-commands-region.cjsx +++ b/src/components/key-commands-region.cjsx @@ -101,6 +101,7 @@ class KeyCommandsRegion extends React.Component componentWillUnmount: -> @_unmountListeners() + @_mounted = false # When the {KeymapManager} finds a valid keymap in a `.cson` file, it # will create a CustomEvent with the command name as its type. That