debian-mirror-gitlab/spec/javascripts/syntax_highlight_spec.js

51 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-12-26 22:10:19 +05:30
/* eslint-disable no-return-assign */
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() {
2019-12-26 22:10:19 +05:30
const stubUserColorScheme = function(value) {
2018-03-17 18:26:18 +05:30
if (window.gon == null) {
window.gon = {};
}
2018-12-13 13:39:08 +05:30
return (window.gon.user_color_scheme = value);
2018-03-17 18:26:18 +05:30
};
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-12-13 13:39:08 +05:30
it('applies syntax highlighting', function() {
2018-03-17 18:26:18 +05:30
stubUserColorScheme('monokai');
syntaxHighlight($('.js-syntax-highlight'));
2018-12-13 13:39:08 +05:30
expect($('.js-syntax-highlight')).toHaveClass('monokai');
2016-09-13 17:45:13 +05:30
});
});
2018-12-13 13:39:08 +05:30
describe('on a parent element', function() {
2018-03-17 18:26:18 +05:30
beforeEach(function() {
2018-12-13 13:39:08 +05:30
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>',
);
2018-03-17 18:26:18 +05:30
});
2018-12-13 13:39:08 +05:30
2018-03-17 18:26:18 +05:30
it('applies highlighting to all applicable children', function() {
stubUserColorScheme('monokai');
syntaxHighlight($('.parent'));
2018-12-13 13:39:08 +05:30
2018-03-17 18:26:18 +05:30
expect($('.parent, .foo')).not.toHaveClass('monokai');
2018-12-13 13:39:08 +05:30
expect($('.monokai').length).toBe(2);
2018-03-17 18:26:18 +05:30
});
2018-12-13 13:39:08 +05:30
it('prevents an infinite loop when no matches exist', function() {
2018-03-17 18:26:18 +05:30
setFixtures('<div></div>');
2019-12-26 22:10:19 +05:30
const highlight = function() {
2018-03-17 18:26:18 +05:30
return syntaxHighlight($('div'));
};
2018-12-13 13:39:08 +05:30
expect(highlight).not.toThrow();
2018-03-17 18:26:18 +05:30
});
});
});