Commit 3bcc26ef authored by Utkarsh Gupta's avatar Utkarsh Gupta

Remove var from line_highlighter_spec.js

parent 1f8c149a
/* eslint-disable no-var, no-else-return, dot-notation, no-return-assign, no-new, no-underscore-dangle */ /* eslint-disable no-else-return, dot-notation, no-return-assign, no-new, no-underscore-dangle */
import $ from 'jquery'; import $ from 'jquery';
import LineHighlighter from '~/line_highlighter'; import LineHighlighter from '~/line_highlighter';
describe('LineHighlighter', function() { describe('LineHighlighter', function() {
var clickLine;
preloadFixtures('static/line_highlighter.html'); preloadFixtures('static/line_highlighter.html');
clickLine = function(number, eventData = {}) { const clickLine = function(number, eventData = {}) {
if ($.isEmptyObject(eventData)) { if ($.isEmptyObject(eventData)) {
return $(`#L${number}`).click(); return $(`#L${number}`).click();
} else { } else {
...@@ -39,34 +38,30 @@ describe('LineHighlighter', function() { ...@@ -39,34 +38,30 @@ describe('LineHighlighter', function() {
}); });
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;
new LineHighlighter({ hash: '#L5-25' }); new LineHighlighter({ hash: '#L5-25' });
expect($(`.${this.css}`).length).toBe(21); expect($(`.${this.css}`).length).toBe(21);
for (line = 5; line <= 25; line += 1) { for (let line = 5; line <= 25; line += 1) {
expect($(`#LC${line}`)).toHaveClass(this.css); expect($(`#LC${line}`)).toHaveClass(this.css);
} }
}); });
it('scrolls to the first highlighted line on initial load', function() { it('scrolls to the first highlighted line on initial load', function() {
var spy; const spy = spyOn($, 'scrollTo');
spy = spyOn($, 'scrollTo');
new LineHighlighter({ hash: '#L5-25' }); new LineHighlighter({ hash: '#L5-25' });
expect(spy).toHaveBeenCalledWith('#L5', jasmine.anything()); expect(spy).toHaveBeenCalledWith('#L5', jasmine.anything());
}); });
it('discards click events', function() { it('discards click events', function() {
var spy; const spy = spyOnEvent('a[data-line-number]', 'click');
spy = spyOnEvent('a[data-line-number]', 'click');
clickLine(13); clickLine(13);
expect(spy).toHaveBeenPrevented(); expect(spy).toHaveBeenPrevented();
}); });
it('handles garbage input from the hash', function() { it('handles garbage input from the hash', function() {
var func; const func = function() {
func = function() {
return new LineHighlighter({ fileHolderSelector: '#blob-content-holder' }); return new LineHighlighter({ fileHolderSelector: '#blob-content-holder' });
}; };
...@@ -76,8 +71,7 @@ describe('LineHighlighter', function() { ...@@ -76,8 +71,7 @@ describe('LineHighlighter', function() {
describe('clickHandler', function() { describe('clickHandler', function() {
it('handles clicking on a child icon element', function() { it('handles clicking on a child icon element', function() {
var spy; const spy = spyOn(this['class'], 'setHash').and.callThrough();
spy = spyOn(this['class'], 'setHash').and.callThrough();
$('#L13 i') $('#L13 i')
.mousedown() .mousedown()
.click(); .click();
...@@ -102,8 +96,7 @@ describe('LineHighlighter', function() { ...@@ -102,8 +96,7 @@ describe('LineHighlighter', function() {
}); });
it('sets the hash', function() { it('sets the hash', function() {
var spy; const spy = spyOn(this['class'], 'setHash').and.callThrough();
spy = spyOn(this['class'], 'setHash').and.callThrough();
clickLine(13); clickLine(13);
expect(spy).toHaveBeenCalledWith(13); expect(spy).toHaveBeenCalledWith(13);
...@@ -112,8 +105,7 @@ describe('LineHighlighter', function() { ...@@ -112,8 +105,7 @@ describe('LineHighlighter', function() {
describe('with shiftKey', function() { describe('with shiftKey', function() {
it('sets the hash', function() { it('sets the hash', function() {
var spy; const spy = spyOn(this['class'], 'setHash').and.callThrough();
spy = spyOn(this['class'], 'setHash').and.callThrough();
clickLine(13); clickLine(13);
clickLine(20, { clickLine(20, {
shiftKey: true, shiftKey: true,
...@@ -134,8 +126,7 @@ describe('LineHighlighter', function() { ...@@ -134,8 +126,7 @@ describe('LineHighlighter', function() {
}); });
it('sets the hash', function() { it('sets the hash', function() {
var spy; const spy = spyOn(this['class'], 'setHash');
spy = spyOn(this['class'], 'setHash');
clickLine(13, { clickLine(13, {
shiftKey: true, shiftKey: true,
}); });
...@@ -146,27 +137,25 @@ describe('LineHighlighter', function() { ...@@ -146,27 +137,25 @@ describe('LineHighlighter', function() {
describe('with existing single-line highlight', function() { describe('with existing single-line highlight', function() {
it('uses existing line as last line when target is lesser', function() { it('uses existing line as last line when target is lesser', function() {
var line;
clickLine(20); clickLine(20);
clickLine(15, { clickLine(15, {
shiftKey: true, shiftKey: true,
}); });
expect($(`.${this.css}`).length).toBe(6); expect($(`.${this.css}`).length).toBe(6);
for (line = 15; line <= 20; line += 1) { for (let line = 15; line <= 20; line += 1) {
expect($(`#LC${line}`)).toHaveClass(this.css); expect($(`#LC${line}`)).toHaveClass(this.css);
} }
}); });
it('uses existing line as first line when target is greater', function() { it('uses existing line as first line when target is greater', function() {
var line;
clickLine(5); clickLine(5);
clickLine(10, { clickLine(10, {
shiftKey: true, shiftKey: true,
}); });
expect($(`.${this.css}`).length).toBe(6); expect($(`.${this.css}`).length).toBe(6);
for (line = 5; line <= 10; line += 1) { for (let line = 5; line <= 10; line += 1) {
expect($(`#LC${line}`)).toHaveClass(this.css); expect($(`#LC${line}`)).toHaveClass(this.css);
} }
}); });
...@@ -183,25 +172,23 @@ describe('LineHighlighter', function() { ...@@ -183,25 +172,23 @@ describe('LineHighlighter', function() {
}); });
it('uses target as first line when it is less than existing first line', function() { it('uses target as first line when it is less than existing first line', function() {
var line;
clickLine(5, { clickLine(5, {
shiftKey: true, shiftKey: true,
}); });
expect($(`.${this.css}`).length).toBe(6); expect($(`.${this.css}`).length).toBe(6);
for (line = 5; line <= 10; line += 1) { for (let line = 5; line <= 10; line += 1) {
expect($(`#LC${line}`)).toHaveClass(this.css); expect($(`#LC${line}`)).toHaveClass(this.css);
} }
}); });
it('uses target as last line when it is greater than existing first line', function() { it('uses target as last line when it is greater than existing first line', function() {
var line;
clickLine(15, { clickLine(15, {
shiftKey: true, shiftKey: true,
}); });
expect($(`.${this.css}`).length).toBe(6); expect($(`.${this.css}`).length).toBe(6);
for (line = 10; line <= 15; line += 1) { for (let line = 10; line <= 15; line += 1) {
expect($(`#LC${line}`)).toHaveClass(this.css); expect($(`#LC${line}`)).toHaveClass(this.css);
} }
}); });
......
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