Welcome to mirror list, hosted at ThFree Co, Russian Federation.

repo_helper_spec.js « helpers « repo « javascripts « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 422a2928753348b2f2b202172f4422fe95e59e41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import $ from 'jquery';
import RepoHelper from '~/repo/helpers/repo_helper';
import RepoStore from '~/repo/stores/repo_store';

describe('RepoHelper', () => {
  describe('highLightIfCurrentLine', () => {
    it('calls highlightLine if activeFile.currentLine is set', () => {
      const activeFile = {
        currentLine: '#L10',
      };
      RepoStore.activeFile = activeFile;

      spyOn(RepoHelper, 'highlightLine');

      RepoHelper.highLightIfCurrentLine();

      expect(RepoHelper.highlightLine).toHaveBeenCalledWith('10');
    });

    it('does not calls highlightLine if activeFile.currentLine is set', () => {
      const activeFile = {
        currentLine: undefined,
      };
      RepoStore.activeFile = activeFile;

      spyOn(RepoHelper, 'highlightLine');

      RepoHelper.highLightIfCurrentLine();

      expect(RepoHelper.highlightLine).not.toHaveBeenCalled();
    });
  });

  describe('diffLineNumClickWrapper', () => {
    it('queries data-line-number attr and called highlightLine', () => {
      const line = '10';
      const event = { target: {} };

      spyOn($.fn, 'attr').and.returnValue(line);
      spyOn(RepoHelper, 'highlightLine');

      RepoHelper.diffLineNumClickWrapper(event);

      expect($.fn.attr).toHaveBeenCalledWith('data-line-number');
      expect(RepoHelper.highlightLine).toHaveBeenCalledWith(line);
    });
  });

  describe('highlightLine', () => {
    it('sets background css of line', () => {
      const line = '10';
      const span = jasmine.createSpyObj('span', ['css']);
      const number = jasmine.createSpyObj('number', ['css']);

      spyOn($.fn, 'find').and.returnValues(span, number);

      RepoHelper.highlightLine(line);

      expect($.fn.find.calls.allArgs()[0][0]).toEqual('span.line');
      expect($.fn.find.calls.allArgs()[1][0]).toEqual(`.diff-line-num#LC${line}`);
      expect(span.css).toHaveBeenCalledWith('background', '#FFF');
      expect(number.css).toHaveBeenCalledWith('background', '#F8EEC7');
    });
  });

  describe('loadingError', () => {
    it('calls Flash', () => {
      spyOn(window, 'Flash');

      RepoHelper.loadingError();

      expect(window.Flash).toHaveBeenCalledWith('Unable to load the file at this time.');
    });
  });
});