Commit 1bdf47ab authored by Fatih Acet's avatar Fatih Acet

Fix line_highlighter_spec.

parent 36a917e1
...@@ -18,19 +18,25 @@ import '~/line_highlighter'; ...@@ -18,19 +18,25 @@ import '~/line_highlighter';
beforeEach(function() { beforeEach(function() {
loadFixtures('static/line_highlighter.html.raw'); loadFixtures('static/line_highlighter.html.raw');
this["class"] = new LineHighlighter(); this["class"] = new LineHighlighter();
this.css = this["class"].highlightClass; this.css = this["class"].highlightLineClass;
return this.spies = { return this.spies = {
__setLocationHash__: spyOn(this["class"], '__setLocationHash__').and.callFake(function() {}) __setLocationHash__: spyOn(this["class"], '__setLocationHash__').and.callFake(function() {})
}; };
}); });
describe('behavior', function() { describe('behavior', function() {
it('highlights one line given in the URL hash', function() { it('highlights one line given in the URL hash', function() {
new LineHighlighter('#L13'); new LineHighlighter({ hash: '#L13' });
return expect($('#LC13')).toHaveClass(this.css); return expect($('#LC13')).toHaveClass(this.css);
}); });
it('highlights one line given in the URL hash with given CSS class name', function() {
const hiliter = new LineHighlighter({ hash: '#L13', highlightLineClass: 'hilite' });
expect(hiliter.highlightLineClass).toBe('hilite');
expect($('#LC13')).toHaveClass('hilite');
expect($('#LC13')).not.toHaveClass('hll');
});
it('highlights a range of lines given in the URL hash', function() { it('highlights a range of lines given in the URL hash', function() {
var line, results; var line, results;
new LineHighlighter('#L5-25'); new LineHighlighter({ hash: '#L5-25' });
expect($("." + this.css).length).toBe(21); expect($("." + this.css).length).toBe(21);
results = []; results = [];
for (line = 5; line <= 25; line += 1) { for (line = 5; line <= 25; line += 1) {
...@@ -41,7 +47,7 @@ import '~/line_highlighter'; ...@@ -41,7 +47,7 @@ import '~/line_highlighter';
it('scrolls to the first highlighted line on initial load', function() { it('scrolls to the first highlighted line on initial load', function() {
var spy; var spy;
spy = spyOn($, 'scrollTo'); spy = spyOn($, 'scrollTo');
new LineHighlighter('#L5-25'); new LineHighlighter({ hash: '#L5-25' });
return expect(spy).toHaveBeenCalledWith('#L5', jasmine.anything()); return expect(spy).toHaveBeenCalledWith('#L5', jasmine.anything());
}); });
it('discards click events', function() { it('discards click events', function() {
...@@ -50,10 +56,10 @@ import '~/line_highlighter'; ...@@ -50,10 +56,10 @@ import '~/line_highlighter';
clickLine(13); clickLine(13);
return expect(spy).toHaveBeenPrevented(); return expect(spy).toHaveBeenPrevented();
}); });
return it('handles garbage input from the hash', function() { it('handles garbage input from the hash', function() {
var func; var func;
func = function() { func = function() {
return new LineHighlighter('#blob-content-holder'); return new LineHighlighter({ fileHolderSelector: '#blob-content-holder' });
}; };
return expect(func).not.toThrow(); return expect(func).not.toThrow();
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment