Mailspring/packages/client-app/spec/components/date-picker-popover-spec.jsx

82 lines
2.3 KiB
React
Raw Normal View History

import React from 'react';
import {mount} from 'enzyme'
import {DateUtils} from 'nylas-exports'
import {DatePickerPopover} from 'nylas-component-kit'
const makePopover = (props = {}) => {
return mount(
<DatePickerPopover
dateOptions={{}}
header={<span className="header">my header</span>}
onSelectDate={() => {}}
{...props}
/>
);
};
describe('DatePickerPopover', function sendLaterPopover() {
beforeEach(() => {
spyOn(DateUtils, 'format').andReturn('formatted')
});
describe('selectDate', () => {
it('calls props.onSelectDate', () => {
const onSelectDate = jasmine.createSpy('onSelectDate')
const popover = makePopover({onSelectDate})
popover.instance().selectDate({utc: () => 'utc'}, 'Custom')
expect(onSelectDate).toHaveBeenCalledWith('formatted', 'Custom')
});
});
describe('onSelectMenuOption', () => {
});
2016-10-28 02:44:19 +08:00
describe('onCustomDateSelected', () => {
it('selects date', () => {
const popover = makePopover()
const instance = popover.instance()
spyOn(instance, 'selectDate')
2016-10-28 02:44:19 +08:00
instance.onCustomDateSelected('date', 'abc')
expect(instance.selectDate).toHaveBeenCalledWith('date', 'Custom')
});
it('throws error if date is invalid', () => {
spyOn(NylasEnv, 'showErrorDialog')
const popover = makePopover()
2016-10-28 02:44:19 +08:00
popover.instance().onCustomDateSelected(null, 'abc')
expect(NylasEnv.showErrorDialog).toHaveBeenCalled()
});
});
describe('render', () => {
it('renders the provided dateOptions', () => {
const popover = makePopover({
dateOptions: {
'label 1-': () => {},
'label 2-': () => {},
},
})
const items = popover.find('.item')
expect(items.at(0).text()).toEqual('label 1-formatted')
expect(items.at(1).text()).toEqual('label 2-formatted')
});
it('renders header components', () => {
const popover = makePopover()
expect(popover.find('.header').text()).toEqual('my header')
})
it('renders footer components', () => {
const popover = makePopover({
footer: <span key="footer" className="footer">footer</span>,
})
expect(popover.find('.footer').text()).toEqual('footer')
2017-02-10 07:29:30 +08:00
expect(popover.find('.date-input-section').exists()).toBe(true)
});
});
});