-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathunittests.coffee
97 lines (81 loc) · 2.7 KB
/
unittests.coffee
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
86
87
88
89
90
91
92
93
94
95
96
createText = () ->
testContent = document.createElement 'div'
testContent.id = 'testContent'
header = document.createElement 'h1'
para = document.createElement 'p'
header.innerHTML = 'Test content'
para.innerHTML = 'This is a test!'
testContent.appendChild header
testContent.appendChild para
document.body.appendChild testContent
removeText = () ->
testContent = document.getElementById 'testContent'
if (testContent != null)
document.body.removeChild testContent
selectText = (element) ->
doc = document
text = doc.getElementById element, range, selection
if (doc.body.createTextRange) #ms
range = doc.body.createTextRange()
range.moveToElementText text
range.select()
else if (window.getSelection) #all others
selection = window.getSelection()
range = doc.createRange()
range.selectNodeContents text
selection.removeAllRanges()
selection.addRange range
module 'Page'
test 'simpleSelection', () =>
createText()
selectText 'testContent'
result = new Page(window).getSelectedText()
notEqual result.indexOf("Test content", 0), -1
notEqual result.indexOf("This is a test!", 0), -1
removeText()
module 'SrDialog'
test 'keypress', () =>
page = new Page window
dialog = new SrDialog page, new ElementCreator(page)
dialog.create()
SPACE_KEY_CODE = 32
spaceDetected = false
dialog.addKeyEvent SPACE_KEY_CODE, () =>
spaceDetected = true
return
evt = jQuery.Event "keydown"
evt.keyCode = SPACE_KEY_CODE
$("#srDialog").trigger(evt)
dialog.remove()
ok(spaceDetected)
dialog.clearKeyEvents()
module 'Splitter'
test 'splitIntoWords', () =>
result = Splitter.splitIntoWords "a b c d"
deepEqual result, ['a', 'b', 'c', 'd']
test 'basicSplit', () =>
input = "This is a test. Is a test! A test?"
expectedOutput = [ \
['This', 'is', 'a', 'test.', '' ], \
['Is', 'a', 'test!', ''], \
['A', 'test?', ''] ]
result = Splitter.splitIntoSentences input
deepEqual result, expectedOutput
test 'advancedSplit', () =>
input = 'This is test. "Still a test!" More test???'
expectedOutput = [ \
['This', 'is', 'test.', ''], \
['"Still', 'a', 'test!"', ''], \
['More', 'test???', ''] ]
result = Splitter.splitIntoSentences input
deepEqual result, expectedOutput
test 'emptyString', () =>
result = Splitter.splitIntoSentences ''
deepEqual result, [ ]
module 'WpmConverter'
test '100wpm', () =>
equal 600, WpmConverter.toInterval 100
test '300wpm', () =>
equal 200, WpmConverter.toInterval 300
test '550wpm', () =>
equal 109, WpmConverter.toInterval 550