2016-03-29 16:41:24 +08:00
|
|
|
import React from 'react';
|
refactor(composer): Make session, draft available everywhere
Summary:
Up until now, we've been requiring that every plugin control in the composer take the draftClientId, retreive the session, listen to it, build state from the draft, etc. This is a huge pain and is hard to explain to newcomers becaus it frankly makes no sense.
In 0.3.45 we made it so that the ComposerView always has a non-null draft and session. (It isn't rendered until they're available). In this diff, I just pass those through to all the plugins and remove all the session retrieval cruft.
Almost none of the buttons have state of their own, which I think is appropriate.
They do render on every keystroke, but they were already running code (to recompute their state) on each keystroke and profiling suggests this has no impact.
Prepare for immutable
In preparation for Immutable models, make the draft store proxy returns a !== draft if any changes have been made. This means you can safely know that a draft has changed if `props.draft !== nextProps.draft`
Test Plan: Run tests
Reviewers: juan, evan
Reviewed By: juan, evan
Differential Revision: https://phab.nylas.com/D2902
2016-04-20 07:05:15 +08:00
|
|
|
import ReactDOM from 'react-dom';
|
2016-03-29 16:41:24 +08:00
|
|
|
import {findRenderedDOMComponentWithClass} from 'react-addons-test-utils';
|
|
|
|
|
refactor(composer): Make session, draft available everywhere
Summary:
Up until now, we've been requiring that every plugin control in the composer take the draftClientId, retreive the session, listen to it, build state from the draft, etc. This is a huge pain and is hard to explain to newcomers becaus it frankly makes no sense.
In 0.3.45 we made it so that the ComposerView always has a non-null draft and session. (It isn't rendered until they're available). In this diff, I just pass those through to all the plugins and remove all the session retrieval cruft.
Almost none of the buttons have state of their own, which I think is appropriate.
They do render on every keystroke, but they were already running code (to recompute their state) on each keystroke and profiling suggests this has no impact.
Prepare for immutable
In preparation for Immutable models, make the draft store proxy returns a !== draft if any changes have been made. This means you can safely know that a draft has changed if `props.draft !== nextProps.draft`
Test Plan: Run tests
Reviewers: juan, evan
Reviewed By: juan, evan
Differential Revision: https://phab.nylas.com/D2902
2016-04-20 07:05:15 +08:00
|
|
|
import {DateUtils} from 'nylas-exports'
|
2016-03-10 02:01:18 +08:00
|
|
|
import SendLaterButton from '../lib/send-later-button';
|
|
|
|
import SendLaterActions from '../lib/send-later-actions';
|
|
|
|
|
refactor(composer): Make session, draft available everywhere
Summary:
Up until now, we've been requiring that every plugin control in the composer take the draftClientId, retreive the session, listen to it, build state from the draft, etc. This is a huge pain and is hard to explain to newcomers becaus it frankly makes no sense.
In 0.3.45 we made it so that the ComposerView always has a non-null draft and session. (It isn't rendered until they're available). In this diff, I just pass those through to all the plugins and remove all the session retrieval cruft.
Almost none of the buttons have state of their own, which I think is appropriate.
They do render on every keystroke, but they were already running code (to recompute their state) on each keystroke and profiling suggests this has no impact.
Prepare for immutable
In preparation for Immutable models, make the draft store proxy returns a !== draft if any changes have been made. This means you can safely know that a draft has changed if `props.draft !== nextProps.draft`
Test Plan: Run tests
Reviewers: juan, evan
Reviewed By: juan, evan
Differential Revision: https://phab.nylas.com/D2902
2016-04-20 07:05:15 +08:00
|
|
|
const node = document.createElement('div');
|
|
|
|
|
|
|
|
const makeButton = (initialState, metadataValue)=> {
|
|
|
|
const message = {
|
|
|
|
metadataForPluginId: ()=> metadataValue,
|
|
|
|
}
|
|
|
|
const button = ReactDOM.render(<SendLaterButton draft={message} />, node);
|
|
|
|
if (initialState) {
|
|
|
|
button.setState(initialState)
|
2016-03-10 02:01:18 +08:00
|
|
|
}
|
|
|
|
return button
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('SendLaterButton', ()=> {
|
|
|
|
beforeEach(()=> {
|
|
|
|
spyOn(DateUtils, 'format').andReturn('formatted')
|
|
|
|
spyOn(SendLaterActions, 'sendLater')
|
|
|
|
});
|
|
|
|
|
refactor(composer): Make session, draft available everywhere
Summary:
Up until now, we've been requiring that every plugin control in the composer take the draftClientId, retreive the session, listen to it, build state from the draft, etc. This is a huge pain and is hard to explain to newcomers becaus it frankly makes no sense.
In 0.3.45 we made it so that the ComposerView always has a non-null draft and session. (It isn't rendered until they're available). In this diff, I just pass those through to all the plugins and remove all the session retrieval cruft.
Almost none of the buttons have state of their own, which I think is appropriate.
They do render on every keystroke, but they were already running code (to recompute their state) on each keystroke and profiling suggests this has no impact.
Prepare for immutable
In preparation for Immutable models, make the draft store proxy returns a !== draft if any changes have been made. This means you can safely know that a draft has changed if `props.draft !== nextProps.draft`
Test Plan: Run tests
Reviewers: juan, evan
Reviewed By: juan, evan
Differential Revision: https://phab.nylas.com/D2902
2016-04-20 07:05:15 +08:00
|
|
|
describe('componentWillReceiveProps', ()=> {
|
2016-03-10 02:01:18 +08:00
|
|
|
it('closes window if window is composer window and saving has finished', ()=> {
|
refactor(composer): Make session, draft available everywhere
Summary:
Up until now, we've been requiring that every plugin control in the composer take the draftClientId, retreive the session, listen to it, build state from the draft, etc. This is a huge pain and is hard to explain to newcomers becaus it frankly makes no sense.
In 0.3.45 we made it so that the ComposerView always has a non-null draft and session. (It isn't rendered until they're available). In this diff, I just pass those through to all the plugins and remove all the session retrieval cruft.
Almost none of the buttons have state of their own, which I think is appropriate.
They do render on every keystroke, but they were already running code (to recompute their state) on each keystroke and profiling suggests this has no impact.
Prepare for immutable
In preparation for Immutable models, make the draft store proxy returns a !== draft if any changes have been made. This means you can safely know that a draft has changed if `props.draft !== nextProps.draft`
Test Plan: Run tests
Reviewers: juan, evan
Reviewed By: juan, evan
Differential Revision: https://phab.nylas.com/D2902
2016-04-20 07:05:15 +08:00
|
|
|
makeButton({saving: true}, null)
|
2016-03-10 02:01:18 +08:00
|
|
|
spyOn(NylasEnv, 'close')
|
|
|
|
spyOn(NylasEnv, 'isComposerWindow').andReturn(true)
|
refactor(composer): Make session, draft available everywhere
Summary:
Up until now, we've been requiring that every plugin control in the composer take the draftClientId, retreive the session, listen to it, build state from the draft, etc. This is a huge pain and is hard to explain to newcomers becaus it frankly makes no sense.
In 0.3.45 we made it so that the ComposerView always has a non-null draft and session. (It isn't rendered until they're available). In this diff, I just pass those through to all the plugins and remove all the session retrieval cruft.
Almost none of the buttons have state of their own, which I think is appropriate.
They do render on every keystroke, but they were already running code (to recompute their state) on each keystroke and profiling suggests this has no impact.
Prepare for immutable
In preparation for Immutable models, make the draft store proxy returns a !== draft if any changes have been made. This means you can safely know that a draft has changed if `props.draft !== nextProps.draft`
Test Plan: Run tests
Reviewers: juan, evan
Reviewed By: juan, evan
Differential Revision: https://phab.nylas.com/D2902
2016-04-20 07:05:15 +08:00
|
|
|
makeButton(null, {sendLaterDate: 'date'})
|
2016-03-10 02:01:18 +08:00
|
|
|
expect(NylasEnv.close).toHaveBeenCalled()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onSendLater', ()=> {
|
|
|
|
it('sets scheduled date to "saving" and dispatches action', ()=> {
|
refactor(composer): Make session, draft available everywhere
Summary:
Up until now, we've been requiring that every plugin control in the composer take the draftClientId, retreive the session, listen to it, build state from the draft, etc. This is a huge pain and is hard to explain to newcomers becaus it frankly makes no sense.
In 0.3.45 we made it so that the ComposerView always has a non-null draft and session. (It isn't rendered until they're available). In this diff, I just pass those through to all the plugins and remove all the session retrieval cruft.
Almost none of the buttons have state of their own, which I think is appropriate.
They do render on every keystroke, but they were already running code (to recompute their state) on each keystroke and profiling suggests this has no impact.
Prepare for immutable
In preparation for Immutable models, make the draft store proxy returns a !== draft if any changes have been made. This means you can safely know that a draft has changed if `props.draft !== nextProps.draft`
Test Plan: Run tests
Reviewers: juan, evan
Reviewed By: juan, evan
Differential Revision: https://phab.nylas.com/D2902
2016-04-20 07:05:15 +08:00
|
|
|
const button = makeButton(null, {sendLaterDate: 'date'})
|
2016-03-10 02:01:18 +08:00
|
|
|
spyOn(button, 'setState')
|
|
|
|
button.onSendLater({utc: ()=> 'utc'})
|
|
|
|
|
|
|
|
expect(SendLaterActions.sendLater).toHaveBeenCalled()
|
refactor(composer): Make session, draft available everywhere
Summary:
Up until now, we've been requiring that every plugin control in the composer take the draftClientId, retreive the session, listen to it, build state from the draft, etc. This is a huge pain and is hard to explain to newcomers becaus it frankly makes no sense.
In 0.3.45 we made it so that the ComposerView always has a non-null draft and session. (It isn't rendered until they're available). In this diff, I just pass those through to all the plugins and remove all the session retrieval cruft.
Almost none of the buttons have state of their own, which I think is appropriate.
They do render on every keystroke, but they were already running code (to recompute their state) on each keystroke and profiling suggests this has no impact.
Prepare for immutable
In preparation for Immutable models, make the draft store proxy returns a !== draft if any changes have been made. This means you can safely know that a draft has changed if `props.draft !== nextProps.draft`
Test Plan: Run tests
Reviewers: juan, evan
Reviewed By: juan, evan
Differential Revision: https://phab.nylas.com/D2902
2016-04-20 07:05:15 +08:00
|
|
|
expect(button.setState).toHaveBeenCalledWith({saving: true})
|
2016-03-10 02:01:18 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('render', ()=> {
|
|
|
|
it('renders spinner if saving', ()=> {
|
refactor(composer): Make session, draft available everywhere
Summary:
Up until now, we've been requiring that every plugin control in the composer take the draftClientId, retreive the session, listen to it, build state from the draft, etc. This is a huge pain and is hard to explain to newcomers becaus it frankly makes no sense.
In 0.3.45 we made it so that the ComposerView always has a non-null draft and session. (It isn't rendered until they're available). In this diff, I just pass those through to all the plugins and remove all the session retrieval cruft.
Almost none of the buttons have state of their own, which I think is appropriate.
They do render on every keystroke, but they were already running code (to recompute their state) on each keystroke and profiling suggests this has no impact.
Prepare for immutable
In preparation for Immutable models, make the draft store proxy returns a !== draft if any changes have been made. This means you can safely know that a draft has changed if `props.draft !== nextProps.draft`
Test Plan: Run tests
Reviewers: juan, evan
Reviewed By: juan, evan
Differential Revision: https://phab.nylas.com/D2902
2016-04-20 07:05:15 +08:00
|
|
|
const button = ReactDOM.findDOMNode(makeButton({saving: true}, null))
|
2016-03-10 02:01:18 +08:00
|
|
|
expect(button.title).toEqual('Saving send date...')
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders date if message is scheduled', ()=> {
|
|
|
|
spyOn(DateUtils, 'futureDateFromString').andReturn({fromNow: ()=> '5 minutes'})
|
refactor(composer): Make session, draft available everywhere
Summary:
Up until now, we've been requiring that every plugin control in the composer take the draftClientId, retreive the session, listen to it, build state from the draft, etc. This is a huge pain and is hard to explain to newcomers becaus it frankly makes no sense.
In 0.3.45 we made it so that the ComposerView always has a non-null draft and session. (It isn't rendered until they're available). In this diff, I just pass those through to all the plugins and remove all the session retrieval cruft.
Almost none of the buttons have state of their own, which I think is appropriate.
They do render on every keystroke, but they were already running code (to recompute their state) on each keystroke and profiling suggests this has no impact.
Prepare for immutable
In preparation for Immutable models, make the draft store proxy returns a !== draft if any changes have been made. This means you can safely know that a draft has changed if `props.draft !== nextProps.draft`
Test Plan: Run tests
Reviewers: juan, evan
Reviewed By: juan, evan
Differential Revision: https://phab.nylas.com/D2902
2016-04-20 07:05:15 +08:00
|
|
|
const button = makeButton(null, {sendLaterDate: 'date'})
|
|
|
|
const span = ReactDOM.findDOMNode(findRenderedDOMComponentWithClass(button, 'at'))
|
2016-03-10 02:01:18 +08:00
|
|
|
expect(span.textContent).toEqual('Sending in 5 minutes')
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render date if message is not scheduled', ()=> {
|
refactor(composer): Make session, draft available everywhere
Summary:
Up until now, we've been requiring that every plugin control in the composer take the draftClientId, retreive the session, listen to it, build state from the draft, etc. This is a huge pain and is hard to explain to newcomers becaus it frankly makes no sense.
In 0.3.45 we made it so that the ComposerView always has a non-null draft and session. (It isn't rendered until they're available). In this diff, I just pass those through to all the plugins and remove all the session retrieval cruft.
Almost none of the buttons have state of their own, which I think is appropriate.
They do render on every keystroke, but they were already running code (to recompute their state) on each keystroke and profiling suggests this has no impact.
Prepare for immutable
In preparation for Immutable models, make the draft store proxy returns a !== draft if any changes have been made. This means you can safely know that a draft has changed if `props.draft !== nextProps.draft`
Test Plan: Run tests
Reviewers: juan, evan
Reviewed By: juan, evan
Differential Revision: https://phab.nylas.com/D2902
2016-04-20 07:05:15 +08:00
|
|
|
const button = makeButton(null, null)
|
2016-03-10 02:01:18 +08:00
|
|
|
expect(()=> {
|
|
|
|
findRenderedDOMComponentWithClass(button, 'at')
|
|
|
|
}).toThrow()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|