1
1
/* eslint-env mocha */
2
- import 'should' ;
3
- import sinon from 'sinon' ;
4
- import React from 'react' ;
5
- import ReactDOM from 'react-dom' ;
6
- import TestUtils from 'react-dom/test-utils' ;
7
- import Modal from '../src/components/Modal.js' ;
2
+ import "should" ;
3
+ import sinon from "sinon" ;
8
4
import {
9
- moverlay , mcontent ,
10
- clickAt , mouseDownAt , mouseUpAt , escKeyDown , tabKeyDown ,
11
- renderModal , emptyDOM
12
- } from './helper' ;
5
+ moverlay ,
6
+ mcontent ,
7
+ clickAt ,
8
+ mouseDownAt ,
9
+ mouseUpAt ,
10
+ escKeyDown ,
11
+ tabKeyDown ,
12
+ renderModal ,
13
+ emptyDOM
14
+ } from "./helper" ;
13
15
14
16
export default ( ) => {
15
- afterEach ( ' Unmount modal' , emptyDOM ) ;
17
+ afterEach ( " Unmount modal" , emptyDOM ) ;
16
18
17
- it ( ' should trigger the onAfterOpen callback' , ( ) => {
19
+ it ( " should trigger the onAfterOpen callback" , ( ) => {
18
20
const afterOpenCallback = sinon . spy ( ) ;
19
21
renderModal ( { isOpen : true , onAfterOpen : afterOpenCallback } ) ;
20
22
afterOpenCallback . called . should . be . ok ( ) ;
21
23
} ) ;
22
24
23
- it ( ' keeps focus inside the modal when child has no tabbable elements' , ( ) => {
25
+ it ( " keeps focus inside the modal when child has no tabbable elements" , ( ) => {
24
26
let tabPrevented = false ;
25
- const modal = renderModal ( { isOpen : true } , ' hello' ) ;
27
+ const modal = renderModal ( { isOpen : true } , " hello" ) ;
26
28
const content = mcontent ( modal ) ;
27
29
document . activeElement . should . be . eql ( content ) ;
28
30
tabKeyDown ( content , {
29
- preventDefault ( ) { tabPrevented = true ; }
31
+ preventDefault ( ) {
32
+ tabPrevented = true ;
33
+ }
30
34
} ) ;
31
35
tabPrevented . should . be . eql ( true ) ;
32
36
} ) ;
33
37
34
- it ( ' handles case when child has no tabbable elements' , ( ) => {
35
- const modal = renderModal ( { isOpen : true } , ' hello' ) ;
38
+ it ( " handles case when child has no tabbable elements" , ( ) => {
39
+ const modal = renderModal ( { isOpen : true } , " hello" ) ;
36
40
const content = mcontent ( modal ) ;
37
41
tabKeyDown ( content ) ;
38
42
document . activeElement . should . be . eql ( content ) ;
39
43
} ) ;
40
44
41
- it ( ' should close on Esc key event' , ( ) => {
45
+ it ( " should close on Esc key event" , ( ) => {
42
46
const requestCloseCallback = sinon . spy ( ) ;
43
47
const modal = renderModal ( {
44
48
isOpen : true ,
@@ -52,8 +56,8 @@ export default () => {
52
56
ev . should . be . ok ( ) ;
53
57
} ) ;
54
58
55
- describe ( ' shouldCloseOnoverlayClick' , ( ) => {
56
- it ( ' when false, click on overlay should not close' , ( ) => {
59
+ describe ( " shouldCloseOnoverlayClick" , ( ) => {
60
+ it ( " when false, click on overlay should not close" , ( ) => {
57
61
const requestCloseCallback = sinon . spy ( ) ;
58
62
const modal = renderModal ( {
59
63
isOpen : true ,
@@ -64,7 +68,7 @@ export default () => {
64
68
requestCloseCallback . called . should . not . be . ok ( ) ;
65
69
} ) ;
66
70
67
- it ( ' when true, click on overlay must close' , ( ) => {
71
+ it ( " when true, click on overlay must close" , ( ) => {
68
72
const requestCloseCallback = sinon . spy ( ) ;
69
73
const modal = renderModal ( {
70
74
isOpen : true ,
@@ -75,7 +79,7 @@ export default () => {
75
79
requestCloseCallback . called . should . be . ok ( ) ;
76
80
} ) ;
77
81
78
- it ( ' overlay mouse down and content mouse up, should not close' , ( ) => {
82
+ it ( " overlay mouse down and content mouse up, should not close" , ( ) => {
79
83
const requestCloseCallback = sinon . spy ( ) ;
80
84
const modal = renderModal ( {
81
85
isOpen : true ,
@@ -87,7 +91,7 @@ export default () => {
87
91
requestCloseCallback . called . should . not . be . ok ( ) ;
88
92
} ) ;
89
93
90
- it ( ' content mouse down and overlay mouse up, should not close' , ( ) => {
94
+ it ( " content mouse down and overlay mouse up, should not close" , ( ) => {
91
95
const requestCloseCallback = sinon . spy ( ) ;
92
96
const modal = renderModal ( {
93
97
isOpen : true ,
@@ -100,20 +104,20 @@ export default () => {
100
104
} ) ;
101
105
} ) ;
102
106
103
- it ( ' should not stop event propagation' , ( ) => {
107
+ it ( " should not stop event propagation" , ( ) => {
104
108
let hasPropagated = false ;
105
109
const modal = renderModal ( {
106
110
isOpen : true ,
107
111
shouldCloseOnOverlayClick : true
108
112
} ) ;
109
- window . addEventListener ( ' click' , ( ) => {
113
+ window . addEventListener ( " click" , ( ) => {
110
114
hasPropagated = true ;
111
115
} ) ;
112
- moverlay ( modal ) . dispatchEvent ( new MouseEvent ( ' click' , { bubbles : true } ) ) ;
116
+ moverlay ( modal ) . dispatchEvent ( new MouseEvent ( " click" , { bubbles : true } ) ) ;
113
117
hasPropagated . should . be . ok ( ) ;
114
118
} ) ;
115
119
116
- it ( ' verify event passing on overlay click' , ( ) => {
120
+ it ( " verify event passing on overlay click" , ( ) => {
117
121
const requestCloseCallback = sinon . spy ( ) ;
118
122
const modal = renderModal ( {
119
123
isOpen : true ,
@@ -123,7 +127,7 @@ export default () => {
123
127
// click the overlay
124
128
clickAt ( moverlay ( modal ) , {
125
129
// Used to test that this was the event received
126
- fakeData : ' ABC'
130
+ fakeData : " ABC"
127
131
} ) ;
128
132
requestCloseCallback . called . should . be . ok ( ) ;
129
133
// Check if event is passed to onRequestClose callback.
0 commit comments