11import React from 'react' ;
2- import { mount } from 'enzyme' ;
2+ import { mount , shallow } from 'enzyme' ;
3+ import { Popper } from 'react-popper' ;
34import { DropdownMenu } from '../' ;
45
56describe ( 'DropdownMenu' , ( ) => {
@@ -63,6 +64,19 @@ describe('DropdownMenu', () => {
6364 expect ( wrapper . find ( '.show' ) . length ) . toBe ( 1 ) ;
6465 } ) ;
6566
67+ it ( 'should render left aligned menus by default' , ( ) => {
68+ isOpen = true ;
69+ const wrapper = mount (
70+ < DropdownMenu > Ello world</ DropdownMenu > ,
71+ {
72+ context : { isOpen, dropup, popperManager } ,
73+ childContextTypes : { popperManager }
74+ }
75+ ) ;
76+
77+ expect ( wrapper . find ( '.dropdown-menu' ) . hasClass ( 'dropdown-menu-right' ) ) . toBe ( false ) ;
78+ } ) ;
79+
6680 it ( 'should render right aligned menus' , ( ) => {
6781 isOpen = true ;
6882 const wrapper = mount (
@@ -76,6 +90,72 @@ describe('DropdownMenu', () => {
7690 expect ( wrapper . find ( '.dropdown-menu' ) . hasClass ( 'dropdown-menu-right' ) ) . toBe ( true ) ;
7791 } ) ;
7892
93+ it ( 'should render down when dropup is false on the context' , ( ) => {
94+ isOpen = true ;
95+ const wrapper = shallow (
96+ < DropdownMenu > Ello world</ DropdownMenu > ,
97+ {
98+ context : { isOpen, dropup, popperManager } ,
99+ childContextTypes : { popperManager }
100+ }
101+ ) ;
102+
103+ expect ( wrapper . find ( Popper ) . prop ( 'placement' ) ) . toBe ( 'bottom-start' ) ;
104+ } ) ;
105+
106+ it ( 'should render up when dropup is true on the context' , ( ) => {
107+ isOpen = true ;
108+ dropup = true ;
109+ const wrapper = shallow (
110+ < DropdownMenu > Ello world</ DropdownMenu > ,
111+ {
112+ context : { isOpen, dropup, popperManager } ,
113+ childContextTypes : { popperManager }
114+ }
115+ ) ;
116+
117+ expect ( wrapper . find ( Popper ) . prop ( 'placement' ) ) . toBe ( 'top-start' ) ;
118+ } ) ;
119+
120+ it ( 'should render down when dropup is false on the context' , ( ) => {
121+ isOpen = true ;
122+ const wrapper = shallow (
123+ < DropdownMenu > Ello world</ DropdownMenu > ,
124+ {
125+ context : { isOpen, dropup, popperManager } ,
126+ childContextTypes : { popperManager }
127+ }
128+ ) ;
129+
130+ expect ( wrapper . find ( Popper ) . prop ( 'placement' ) ) . toBe ( 'bottom-start' ) ;
131+ } ) ;
132+
133+ it ( 'should not disable flip modifier by default' , ( ) => {
134+ isOpen = true ;
135+ const wrapper = shallow (
136+ < DropdownMenu > Ello world</ DropdownMenu > ,
137+ {
138+ context : { isOpen, dropup, popperManager } ,
139+ childContextTypes : { popperManager }
140+ }
141+ ) ;
142+
143+ expect ( wrapper . find ( Popper ) . prop ( 'modifiers' ) . flip ) . toBe ( undefined ) ;
144+ } ) ;
145+
146+ it ( 'should disable flip modifier when flip is false' , ( ) => {
147+ isOpen = true ;
148+ const wrapper = shallow (
149+ < DropdownMenu flip = { false } > Ello world</ DropdownMenu > ,
150+ {
151+ context : { isOpen, dropup, popperManager } ,
152+ childContextTypes : { popperManager }
153+ }
154+ ) ;
155+
156+ expect ( wrapper . find ( Popper ) . prop ( 'modifiers' ) ) . toEqual ( { flip : { enabled : false } } ) ;
157+ } ) ;
158+
79159 it ( 'should not render multiple children when isOpen is false' , ( ) => {
80160 const wrapper = mount (
81161 < DropdownMenu right > Ello world</ DropdownMenu > ,
0 commit comments