2016-03-04 04:37:20 +08:00
|
|
|
import React, {addons} from 'react/addons';
|
2016-03-10 02:01:18 +08:00
|
|
|
import {DateUtils} from 'nylas-exports'
|
2016-03-04 04:37:20 +08:00
|
|
|
import SendLaterPopover from '../lib/send-later-popover';
|
|
|
|
import {renderIntoDocument} from '../../../spec/nylas-test-utils'
|
|
|
|
|
|
|
|
const {findDOMNode} = React;
|
|
|
|
const {TestUtils: {
|
2016-03-10 02:01:18 +08:00
|
|
|
Simulate,
|
2016-03-04 04:37:20 +08:00
|
|
|
findRenderedDOMComponentWithClass,
|
|
|
|
}} = addons;
|
|
|
|
|
|
|
|
const makePopover = (props = {})=> {
|
2016-03-10 02:01:18 +08:00
|
|
|
return renderIntoDocument(
|
|
|
|
<SendLaterPopover
|
|
|
|
scheduledDate={null}
|
|
|
|
onSendLater={()=>{}}
|
|
|
|
onCancelSendLater={()=>{}}
|
|
|
|
{...props} />
|
|
|
|
);
|
2016-03-04 04:37:20 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
describe('SendLaterPopover', ()=> {
|
|
|
|
beforeEach(()=> {
|
|
|
|
spyOn(DateUtils, 'format').andReturn('formatted')
|
|
|
|
});
|
|
|
|
|
2016-03-10 02:01:18 +08:00
|
|
|
describe('selectDate', ()=> {
|
|
|
|
it('calls props.onSendLtaer', ()=> {
|
|
|
|
const onSendLater = jasmine.createSpy('onSendLater')
|
|
|
|
const popover = makePopover({onSendLater})
|
|
|
|
popover.selectDate({utc: ()=> 'utc'}, 'Custom')
|
2016-03-04 04:37:20 +08:00
|
|
|
|
2016-03-10 02:01:18 +08:00
|
|
|
expect(onSendLater).toHaveBeenCalledWith('formatted', 'Custom')
|
2016-03-04 04:37:20 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-03-10 02:01:18 +08:00
|
|
|
describe('onSelectCustomOption', ()=> {
|
|
|
|
it('selects date', ()=> {
|
2016-03-04 04:37:20 +08:00
|
|
|
const popover = makePopover()
|
2016-03-10 02:01:18 +08:00
|
|
|
spyOn(popover, 'selectDate')
|
|
|
|
popover.onSelectCustomOption('date', 'abc')
|
|
|
|
expect(popover.selectDate).toHaveBeenCalledWith('date', 'Custom')
|
|
|
|
});
|
2016-03-04 04:37:20 +08:00
|
|
|
|
2016-03-10 02:01:18 +08:00
|
|
|
it('throws error if date is invalid', ()=> {
|
|
|
|
spyOn(NylasEnv, 'showErrorDialog')
|
|
|
|
const popover = makePopover()
|
|
|
|
popover.onSelectCustomOption(null, 'abc')
|
|
|
|
expect(NylasEnv.showErrorDialog).toHaveBeenCalled()
|
2016-03-04 04:37:20 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-03-10 02:01:18 +08:00
|
|
|
describe('render', ()=> {
|
|
|
|
it('renders cancel button if scheduled', ()=> {
|
|
|
|
const onCancelSendLater = jasmine.createSpy('onCancelSendLater')
|
|
|
|
const popover = makePopover({onCancelSendLater, scheduledDate: 'date'})
|
2016-03-04 04:37:20 +08:00
|
|
|
const button = findDOMNode(
|
2016-03-10 02:01:18 +08:00
|
|
|
findRenderedDOMComponentWithClass(popover, 'btn-cancel')
|
2016-03-04 04:37:20 +08:00
|
|
|
)
|
2016-03-10 02:01:18 +08:00
|
|
|
Simulate.click(button)
|
|
|
|
expect(onCancelSendLater).toHaveBeenCalled()
|
2016-03-04 04:37:20 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|