2017-01-10 18:02:20 -05:00
|
|
|
/* eslint-disable space-before-function-paren, no-var, no-return-assign, quotes */
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-01-09 18:23:54 -05:00
|
|
|
require('~/syntax_highlight');
|
2016-07-24 16:45:11 -04:00
|
|
|
|
|
|
|
(function() {
|
|
|
|
describe('Syntax Highlighter', function() {
|
|
|
|
var stubUserColorScheme;
|
|
|
|
stubUserColorScheme = function(value) {
|
|
|
|
if (window.gon == null) {
|
|
|
|
window.gon = {};
|
|
|
|
}
|
|
|
|
return window.gon.user_color_scheme = value;
|
|
|
|
};
|
|
|
|
describe('on a js-syntax-highlight element', function() {
|
|
|
|
beforeEach(function() {
|
2016-12-30 19:14:33 -05:00
|
|
|
return setFixtures('<div class="js-syntax-highlight"></div>');
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
return it('applies syntax highlighting', function() {
|
|
|
|
stubUserColorScheme('monokai');
|
|
|
|
$('.js-syntax-highlight').syntaxHighlight();
|
|
|
|
return expect($('.js-syntax-highlight')).toHaveClass('monokai');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return describe('on a parent element', function() {
|
|
|
|
beforeEach(function() {
|
2016-12-30 19:14:33 -05:00
|
|
|
return setFixtures("<div class=\"parent\">\n <div class=\"js-syntax-highlight\"></div>\n <div class=\"foo\"></div>\n <div class=\"js-syntax-highlight\"></div>\n</div>");
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
it('applies highlighting to all applicable children', function() {
|
|
|
|
stubUserColorScheme('monokai');
|
|
|
|
$('.parent').syntaxHighlight();
|
|
|
|
expect($('.parent, .foo')).not.toHaveClass('monokai');
|
|
|
|
return expect($('.monokai').length).toBe(2);
|
|
|
|
});
|
|
|
|
return it('prevents an infinite loop when no matches exist', function() {
|
|
|
|
var highlight;
|
2016-12-30 19:14:33 -05:00
|
|
|
setFixtures('<div></div>');
|
2016-07-24 16:45:11 -04:00
|
|
|
highlight = function() {
|
|
|
|
return $('div').syntaxHighlight();
|
|
|
|
};
|
|
|
|
return expect(highlight).not.toThrow();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}).call(this);
|