2017-08-17 22:00:37 +05:30
|
|
|
/* eslint-disable space-before-function-paren, no-var, no-return-assign, quotes */
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
import $ from 'jquery';
|
2018-03-17 18:26:18 +05:30
|
|
|
import syntaxHighlight from '~/syntax_highlight';
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
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() {
|
|
|
|
return setFixtures('<div class="js-syntax-highlight"></div>');
|
2016-09-13 17:45:13 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
return it('applies syntax highlighting', function() {
|
|
|
|
stubUserColorScheme('monokai');
|
|
|
|
syntaxHighlight($('.js-syntax-highlight'));
|
|
|
|
return expect($('.js-syntax-highlight')).toHaveClass('monokai');
|
2016-09-13 17:45:13 +05:30
|
|
|
});
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
return describe('on a parent element', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
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>");
|
|
|
|
});
|
|
|
|
it('applies highlighting to all applicable children', function() {
|
|
|
|
stubUserColorScheme('monokai');
|
|
|
|
syntaxHighlight($('.parent'));
|
|
|
|
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;
|
|
|
|
setFixtures('<div></div>');
|
|
|
|
highlight = function() {
|
|
|
|
return syntaxHighlight($('div'));
|
|
|
|
};
|
|
|
|
return expect(highlight).not.toThrow();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|