summaryrefslogtreecommitdiff
path: root/spec/javascripts
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-09-10 15:28:42 -0400
committerRobert Speicher <rspeicher@gmail.com>2015-09-10 15:38:24 -0400
commit404a01ab148417f6314c94d213769dd72fd0589e (patch)
treec6bd24884d9ff4c87cb31857d649d43ef6c48abc /spec/javascripts
parent7cbf5e4d18f6ba0bf1afbddcb090fa39837e9529 (diff)
downloadgitlab-ce-404a01ab148417f6314c94d213769dd72fd0589e.tar.gz
Add specs for syntax_highlight JS
Also makes it work when given a parent element containing a `.js-syntax-highlight` element so for dynamically-added things like notes or Markdown previews, we can more accurately target just the element we care about.
Diffstat (limited to 'spec/javascripts')
-rw-r--r--spec/javascripts/syntax_highlight_spec.js.coffee42
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/javascripts/syntax_highlight_spec.js.coffee b/spec/javascripts/syntax_highlight_spec.js.coffee
new file mode 100644
index 00000000000..6a73b6bf32c
--- /dev/null
+++ b/spec/javascripts/syntax_highlight_spec.js.coffee
@@ -0,0 +1,42 @@
+#= require syntax_highlight
+
+describe 'Syntax Highlighter', ->
+ stubUserColorScheme = (value) ->
+ window.gon ?= {}
+ window.gon.user_color_scheme = value
+
+ describe 'on a js-syntax-highlight element', ->
+ beforeEach ->
+ fixture.set('<div class="js-syntax-highlight"></div>')
+
+ it 'applies syntax highlighting', ->
+ stubUserColorScheme('monokai')
+
+ $('.js-syntax-highlight').syntaxHighlight()
+
+ expect($('.js-syntax-highlight')).toHaveClass('monokai')
+
+ describe 'on a parent element', ->
+ beforeEach ->
+ fixture.set """
+ <div class="parent">
+ <div class="js-syntax-highlight"></div>
+ <div class="foo"></div>
+ <div class="js-syntax-highlight"></div>
+ </div>
+ """
+
+ it 'applies highlighting to all applicable children', ->
+ stubUserColorScheme('monokai')
+
+ $('.parent').syntaxHighlight()
+
+ expect($('.parent, .foo')).not.toHaveClass('monokai')
+ expect($('.monokai').length).toBe(2)
+
+ it 'prevents an infinite loop when no matches exist', ->
+ fixture.set('<div></div>')
+
+ highlight = -> $('div').syntaxHighlight()
+
+ expect(highlight).not.toThrow()