11describe " Spell check" , ->
2- [workspaceElement , editor , editorElement ] = []
2+ [workspaceElement , editor , editorElement , spellCheckModule ] = []
33
4- textForDecoration = ({marker}) ->
5- editor .getTextInBufferRange (marker .getBufferRange ())
4+ textForMarker = (marker ) ->
5+ editor .getTextInBufferRange (marker .getRange ())
6+
7+ getMisspellingMarkers = ->
8+ spellCheckModule .misspellingMarkersForEditor (editor)
69
710 beforeEach ->
811 workspaceElement = atom .views .getView (atom .workspace )
@@ -20,7 +23,8 @@ describe "Spell check", ->
2023 atom .workspace .open (' sample.js' )
2124
2225 waitsForPromise ->
23- atom .packages .activatePackage (' spell-check' )
26+ atom .packages .activatePackage (' spell-check' ).then ({mainModule}) ->
27+ spellCheckModule = mainModule
2428
2529 runs ->
2630 jasmine .attachToDOM (workspaceElement)
@@ -31,67 +35,67 @@ describe "Spell check", ->
3135 editor .setText (" This middle of thiss\n sentencts\n\n has issues and the \" edn\" 'dsoe' too" )
3236 atom .config .set (' spell-check.grammars' , [' source.js' ])
3337
34- decorations = null
35-
38+ misspellingMarkers = null
3639 waitsFor ->
37- decorations = editor .getHighlightDecorations (class : ' spell-check-misspelling' )
38- decorations .length > 0
39-
40+ misspellingMarkers = getMisspellingMarkers ()
41+ misspellingMarkers .length > 0
4042
4143 runs ->
42- expect (decorations .length ).toBe 4
43- expect (textForDecoration (decorations [0 ])).toEqual " thiss"
44- expect (textForDecoration (decorations [1 ])).toEqual " sentencts"
45- expect (textForDecoration (decorations [2 ])).toEqual " edn"
46- expect (textForDecoration (decorations [3 ])).toEqual " dsoe"
44+ expect (misspellingMarkers .length ).toBe 4
45+ expect (textForMarker (misspellingMarkers [0 ])).toEqual " thiss"
46+ expect (textForMarker (misspellingMarkers [1 ])).toEqual " sentencts"
47+ expect (textForMarker (misspellingMarkers [2 ])).toEqual " edn"
48+ expect (textForMarker (misspellingMarkers [3 ])).toEqual " dsoe"
4749
4850 it " doesn't consider our company's name to be a spelling error" , ->
4951 editor .setText (" GitHub (aka github): Where codez are built." )
5052 atom .config .set (' spell-check.grammars' , [' source.js' ])
5153
52- decorations = null
53-
54+ misspellingMarkers = null
5455 waitsFor ->
55- decorations = editor . getHighlightDecorations ( class : ' spell-check-misspelling ' )
56- decorations .length > 0
56+ misspellingMarkers = getMisspellingMarkers ( )
57+ misspellingMarkers .length > 0
5758
5859 runs ->
59- expect (decorations .length ).toBe 1
60- expect (textForDecoration (decorations [0 ])).toBe " codez"
60+ expect (misspellingMarkers .length ).toBe 1
61+ expect (textForMarker (misspellingMarkers [0 ])).toBe " codez"
6162
6263 it " hides decorations when a misspelled word is edited" , ->
6364 editor .setText (' notaword' )
6465 advanceClock (editor .getBuffer ().getStoppedChangingDelay ())
6566 atom .config .set (' spell-check.grammars' , [' source.js' ])
6667
67- decorations = null
68+ misspellingMarkers = null
6869 waitsFor ->
69- decorations = editor . getHighlightDecorations ( class : ' spell-check-misspelling ' )
70- decorations .length > 0
70+ misspellingMarkers = getMisspellingMarkers ( )
71+ misspellingMarkers .length > 0
7172
7273 runs ->
73- expect (decorations .length ).toBe 1
74+ expect (misspellingMarkers .length ).toBe 1
7475 editor .moveToEndOfLine ()
7576 editor .insertText (' a' )
7677 advanceClock (editor .getBuffer ().getStoppedChangingDelay ())
77- decorations = editor .getHighlightDecorations (class : ' spell-check-misspelling' )
78- expect (decorations .length ).toBe 1
79- expect (decorations[0 ].marker .isValid ()).toBe false
78+
79+ misspellingMarkers = getMisspellingMarkers ()
80+
81+ expect (misspellingMarkers .length ).toBe 1
82+ expect (misspellingMarkers[0 ].isValid ()).toBe false
8083
8184 describe " when spell checking for a grammar is removed" , ->
8285 it " removes all the misspellings" , ->
8386 editor .setText (' notaword' )
8487 advanceClock (editor .getBuffer ().getStoppedChangingDelay ())
8588 atom .config .set (' spell-check.grammars' , [' source.js' ])
8689
87- decorations = null
90+ misspellingMarkers = null
8891 waitsFor ->
89- editor .getHighlightDecorations (class : ' spell-check-misspelling' ).length > 0
92+ misspellingMarkers = getMisspellingMarkers ()
93+ misspellingMarkers .length > 0
9094
9195 runs ->
92- expect (editor . getHighlightDecorations ( class : ' spell-check-misspelling ' ).length ).toBe 1
96+ expect (getMisspellingMarkers ( ).length ).toBe 1
9397 atom .config .set (' spell-check.grammars' , [])
94- expect (editor . getHighlightDecorations ( class : ' spell-check-misspelling ' ).length ).toBe 0
98+ expect (getMisspellingMarkers ( ).length ).toBe 0
9599
96100 describe " when the editor's grammar changes to one that does not have spell check enabled" , ->
97101 it " removes all the misspellings" , ->
@@ -100,12 +104,12 @@ describe "Spell check", ->
100104 atom .config .set (' spell-check.grammars' , [' source.js' ])
101105
102106 waitsFor ->
103- editor . getHighlightDecorations ( class : ' spell-check-misspelling ' ).length > 0
107+ getMisspellingMarkers ( ).length > 0
104108
105109 runs ->
106- expect (editor . getHighlightDecorations ( class : ' spell-check-misspelling ' ).length ).toBe 1
110+ expect (getMisspellingMarkers ( ).length ).toBe 1
107111 editor .setGrammar (atom .grammars .selectGrammar (' .txt' ))
108- expect (editor . getHighlightDecorations ( class : ' spell-check-misspelling ' ).length ).toBe 0
112+ expect (getMisspellingMarkers ( ).length ).toBe 0
109113
110114 describe " when 'spell-check:correct-misspelling' is triggered on the editor" , ->
111115 describe " when the cursor touches a misspelling that has corrections" , ->
@@ -115,9 +119,11 @@ describe "Spell check", ->
115119 atom .config .set (' spell-check.grammars' , [' source.js' ])
116120
117121 waitsFor ->
118- editor . getHighlightDecorations ( class : ' spell-check-misspelling ' ).length > 0
122+ getMisspellingMarkers ( ).length is 1
119123
120124 runs ->
125+ expect (getMisspellingMarkers ()[0 ].isValid ()).toBe true
126+
121127 atom .commands .dispatch editorElement, ' spell-check:correct-misspelling'
122128
123129 correctionsElement = editorElement .querySelector (' .corrections' )
@@ -129,8 +135,8 @@ describe "Spell check", ->
129135
130136 expect (editor .getText ()).toBe ' together'
131137 expect (editor .getCursorBufferPosition ()).toEqual [0 , 8 ]
132- advanceClock ( editor . getBuffer (). getStoppedChangingDelay ())
133- expect (editorElement . querySelectorAll ( ' .spell-check-misspelling ' ). length ) .toBe 0
138+
139+ expect (getMisspellingMarkers ()[ 0 ]. isValid ()) .toBe false
134140 expect (editorElement .querySelector (' .corrections' )).toBeNull ()
135141
136142 describe " when the cursor touches a misspelling that has no corrections" , ->
@@ -140,7 +146,7 @@ describe "Spell check", ->
140146 atom .config .set (' spell-check.grammars' , [' source.js' ])
141147
142148 waitsFor ->
143- editor . getHighlightDecorations ( class : ' spell-check-misspelling ' ).length > 0
149+ getMisspellingMarkers ( ).length > 0
144150
145151 runs ->
146152 atom .commands .dispatch editorElement, ' spell-check:correct-misspelling'
@@ -154,8 +160,8 @@ describe "Spell check", ->
154160 atom .config .set (' spell-check.grammars' , [' source.js' ])
155161
156162 waitsFor ->
157- editor . getHighlightDecorations ( class : ' spell-check-misspelling ' ).length > 0
163+ getMisspellingMarkers ( ).length > 0
158164
159165 runs ->
160166 editor .destroy ()
161- expect (editor . getMarkers ().length ).toBe 0
167+ expect (getMisspellingMarkers ().length ).toBe 0
0 commit comments