Mailspring/internal_packages/send-later/spec/send-later-popover-spec.jsx
Ben Gotow 886328ff7a bump(react): 0.13.2 => 0.14.7
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.
2016-03-29 01:43:12 -07:00

62 lines
1.9 KiB
JavaScript

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