|
| 1 | +import React from 'react'; |
| 2 | +import { shallow } from 'enzyme'; |
| 3 | +import ReactCSSTransitionGroup from 'react-addons-css-transition-group'; |
| 4 | +import Alert from '../Alert'; |
| 5 | + |
| 6 | +describe('Alert', () => { |
| 7 | + it('should render children', () => { |
| 8 | + const alert = shallow(<Alert>Yo!</Alert>).find('div'); |
| 9 | + expect(alert.text()).toBe('Yo!'); |
| 10 | + }); |
| 11 | + |
| 12 | + it('should transition on appear, enter, and leave using fade', () => { |
| 13 | + const alert = shallow(<Alert>Yo!</Alert>); |
| 14 | + expect(alert.prop('transitionName')).toEqual({ |
| 15 | + appear: 'fade', |
| 16 | + appearActive: 'in', |
| 17 | + enter: 'fade', |
| 18 | + enterActive: 'in', |
| 19 | + leave: 'fade', |
| 20 | + leaveActive: 'out' |
| 21 | + }); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should have default transitionTimeouts', () => { |
| 25 | + const alert = shallow(<Alert>Yo!</Alert>); |
| 26 | + |
| 27 | + expect(alert.prop('transitionAppearTimeout')).toBe(150); |
| 28 | + expect(alert.prop('transitionAppear')).toBe(true); |
| 29 | + expect(alert.prop('transitionEnterTimeout')).toBe(150); |
| 30 | + expect(alert.prop('transitionEnter')).toBe(true); |
| 31 | + expect(alert.prop('transitionLeaveTimeout')).toBe(150); |
| 32 | + expect(alert.prop('transitionLeave')).toBe(true); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should have support configurable transitionTimeouts', () => { |
| 36 | + const alert = shallow( |
| 37 | + <Alert |
| 38 | + transitionAppearTimeout={0} |
| 39 | + transitionEnterTimeout={0} |
| 40 | + transitionLeaveTimeout={0}> |
| 41 | + Yo! |
| 42 | + </Alert> |
| 43 | + ); |
| 44 | + |
| 45 | + expect(alert.prop('transitionAppearTimeout')).toBe(0); |
| 46 | + expect(alert.prop('transitionAppear')).toBe(false); |
| 47 | + expect(alert.prop('transitionEnterTimeout')).toBe(0); |
| 48 | + expect(alert.prop('transitionEnter')).toBe(false); |
| 49 | + expect(alert.prop('transitionLeaveTimeout')).toBe(0); |
| 50 | + expect(alert.prop('transitionLeave')).toBe(false); |
| 51 | + }); |
| 52 | + |
| 53 | + it('should have "success" as default color', () => { |
| 54 | + const alert = shallow(<Alert>Yo!</Alert>).find('div'); |
| 55 | + expect(alert.hasClass('alert-success')).toBe(true); |
| 56 | + }); |
| 57 | + |
| 58 | + it('should accept color prop', () => { |
| 59 | + const alert = shallow(<Alert color="warning">Yo!</Alert>).find('div'); |
| 60 | + expect(alert.hasClass('alert-warning')).toBe(true); |
| 61 | + }); |
| 62 | + |
| 63 | + it('should use a div tag by default', () => { |
| 64 | + const alert = shallow(<Alert>Yo!</Alert>).children().first(); |
| 65 | + expect(alert.type()).toBe('div'); |
| 66 | + }); |
| 67 | + |
| 68 | + it('should be non dismissible by default', () => { |
| 69 | + const alert = shallow(<Alert>Yo!</Alert>).find('div'); |
| 70 | + expect(alert.find('button').length).toEqual(0); |
| 71 | + expect(alert.hasClass('alert-dismissible')).toBe(false); |
| 72 | + }); |
| 73 | + |
| 74 | + it('should show dismiss button if passed toggle', () => { |
| 75 | + const alert = shallow(<Alert color="danger" toggle={() => {}}>Yo!</Alert>).find('div'); |
| 76 | + expect(alert.find('button').length).toEqual(1); |
| 77 | + expect(alert.hasClass('alert-dismissible')).toBe(true); |
| 78 | + }); |
| 79 | + |
| 80 | + it('should support custom tag', () => { |
| 81 | + const alert = shallow(<Alert tag="p">Yo!</Alert>).children().first(); |
| 82 | + expect(alert.type()).toBe('p'); |
| 83 | + }); |
| 84 | + |
| 85 | + it('should be empty if not isOpen', () => { |
| 86 | + const alert = shallow(<Alert isOpen={false}>Yo!</Alert>); |
| 87 | + expect(alert.html()).toBe(''); |
| 88 | + }); |
| 89 | + |
| 90 | + it('should be dismissible', () => { |
| 91 | + const onClick = jasmine.createSpy('onClick'); |
| 92 | + const alert = shallow(<Alert color="danger" toggle={onClick}>Yo!</Alert>); |
| 93 | + |
| 94 | + alert.find('button').simulate('click'); |
| 95 | + expect(onClick).toHaveBeenCalled(); |
| 96 | + }); |
| 97 | +}); |
0 commit comments