-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathPointTarget-test.js
85 lines (69 loc) · 2.25 KB
/
PointTarget-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import expect from 'expect'
import React from 'react'
import { render } from 'react-dom'
import { Simulate } from 'react-dom/test-utils'
import PointTarget from '../PointTarget'
const touch = (clientX, clientY) => ({
clientX,
clientY
})
describe('A <PointTarget>', () => {
let node
beforeEach(() => {
node = document.createElement('div')
})
describe('with no children', () => {
it('renders a button', () => {
render(<PointTarget/>, node, () => {
expect(node.firstChild.tagName).toEqual('BUTTON')
})
})
})
describe('with children', () => {
it('renders them', () => {
render(<PointTarget><div/></PointTarget>, node, () => {
expect(node.firstChild.tagName).toEqual('DIV')
})
})
})
describe('when it is clicked', () => {
it('calls the onPoint callback', () => {
let called = false
render(<PointTarget onPoint={() => called = true}/>, node, () => {
Simulate.click(node.firstChild)
expect(called).toBe(true)
})
})
})
describe('when it is "tapped"', () => {
it('calls the onPoint callback', () => {
let called = false
render(<PointTarget onPoint={() => called = true}/>, node, () => {
Simulate.touchStart(node.firstChild, { touches: [ touch(0, 0) ] })
Simulate.touchEnd(node.firstChild, { touches: [ touch(0, 0) ] })
expect(called).toBe(true)
})
})
})
describe('when a touch moves around too much', () => {
it('does not call the onPoint callback', () => {
let called = false
render(<PointTarget onPoint={() => called = true}/>, node, () => {
Simulate.touchStart(node.firstChild, { touches: [ touch(0, 0) ] })
Simulate.touchMove(node.firstChild, { touches: [ touch(0, 20) ] })
Simulate.touchEnd(node.firstChild, { touches: [ touch(0, 0) ] })
expect(called).toBe(false)
})
})
})
describe('when a touch is canceled', () => {
it('does not call the onPoint callback', () => {
let called = false
render(<PointTarget onPoint={() => called = true}/>, node, () => {
Simulate.touchStart(node.firstChild, { touches: [ touch(0, 0) ] })
Simulate.touchCancel(node.firstChild)
expect(called).toBe(false)
})
})
})
})