mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-14 13:44:41 +08:00
886328ff7a
Great breakdown of React changes here: https://github.com/facebook/react/blob/master/CHANGELOG.md#0140-october-7-2015 Due to deprecation warnings, I don't think this will break third-party extensions unless they were doing really bad things.
101 lines
3.4 KiB
JavaScript
101 lines
3.4 KiB
JavaScript
import React from 'react';
|
|
import {findDOMNode} from 'react-dom';
|
|
import {findRenderedDOMComponentWithClass} from 'react-addons-test-utils';
|
|
|
|
import {Rx, DatabaseStore, DateUtils} from 'nylas-exports'
|
|
import SendLaterButton from '../lib/send-later-button';
|
|
import SendLaterActions from '../lib/send-later-actions';
|
|
import {renderIntoDocument} from '../../../spec/nylas-test-utils'
|
|
|
|
const makeButton = (props = {})=> {
|
|
const button = renderIntoDocument(<SendLaterButton {...props} draftClientId="1" />);
|
|
if (props.initialState) {
|
|
button.setState(props.initialState)
|
|
}
|
|
return button
|
|
};
|
|
|
|
describe('SendLaterButton', ()=> {
|
|
beforeEach(()=> {
|
|
spyOn(DatabaseStore, 'findBy')
|
|
spyOn(Rx.Observable, 'fromQuery').andReturn(Rx.Observable.empty())
|
|
spyOn(DateUtils, 'format').andReturn('formatted')
|
|
spyOn(SendLaterActions, 'sendLater')
|
|
});
|
|
|
|
describe('onMessageChanged', ()=> {
|
|
it('sets scheduled date correctly', ()=> {
|
|
const button = makeButton({initialState: {scheduledDate: 'old'}})
|
|
const message = {
|
|
metadataForPluginId: ()=> ({sendLaterDate: 'date'}),
|
|
}
|
|
spyOn(button, 'setState')
|
|
spyOn(NylasEnv, 'isComposerWindow').andReturn(false)
|
|
|
|
button.onMessageChanged(message)
|
|
|
|
expect(button.setState).toHaveBeenCalledWith({scheduledDate: 'date'})
|
|
});
|
|
|
|
it('closes window if window is composer window and saving has finished', ()=> {
|
|
const button = makeButton({initialState: {scheduledDate: 'saving'}})
|
|
const message = {
|
|
metadataForPluginId: ()=> ({sendLaterDate: 'date'}),
|
|
}
|
|
spyOn(button, 'setState')
|
|
spyOn(NylasEnv, 'close')
|
|
spyOn(NylasEnv, 'isComposerWindow').andReturn(true)
|
|
|
|
button.onMessageChanged(message)
|
|
|
|
expect(button.setState).toHaveBeenCalledWith({scheduledDate: 'date'})
|
|
expect(NylasEnv.close).toHaveBeenCalled()
|
|
});
|
|
|
|
it('does nothing if new date is the same as current date', ()=> {
|
|
const button = makeButton({initialState: {scheduledDate: 'date'}})
|
|
const message = {
|
|
metadataForPluginId: ()=> ({sendLaterDate: 'date'}),
|
|
}
|
|
spyOn(button, 'setState')
|
|
|
|
button.onMessageChanged(message)
|
|
|
|
expect(button.setState).not.toHaveBeenCalled()
|
|
});
|
|
});
|
|
|
|
describe('onSendLater', ()=> {
|
|
it('sets scheduled date to "saving" and dispatches action', ()=> {
|
|
const button = makeButton()
|
|
spyOn(button, 'setState')
|
|
button.onSendLater({utc: ()=> 'utc'})
|
|
|
|
expect(SendLaterActions.sendLater).toHaveBeenCalled()
|
|
expect(button.setState).toHaveBeenCalledWith({scheduledDate: 'saving'})
|
|
});
|
|
});
|
|
|
|
describe('render', ()=> {
|
|
it('renders spinner if saving', ()=> {
|
|
const button = findDOMNode(
|
|
makeButton({initialState: {scheduledDate: 'saving'}})
|
|
)
|
|
expect(button.title).toEqual('Saving send date...')
|
|
});
|
|
|
|
it('renders date if message is scheduled', ()=> {
|
|
spyOn(DateUtils, 'futureDateFromString').andReturn({fromNow: ()=> '5 minutes'})
|
|
const button = makeButton({initialState: {scheduledDate: 'date'}})
|
|
const span = findDOMNode(findRenderedDOMComponentWithClass(button, 'at'))
|
|
expect(span.textContent).toEqual('Sending in 5 minutes')
|
|
});
|
|
|
|
it('does not render date if message is not scheduled', ()=> {
|
|
const button = makeButton({initialState: {scheduledDate: null}})
|
|
expect(()=> {
|
|
findRenderedDOMComponentWithClass(button, 'at')
|
|
}).toThrow()
|
|
});
|
|
});
|
|
});
|