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

compare_versions_spec.js « components « diffs « javascripts « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d9d7f61785f08247c132441d91949d8c078c83ea (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import Vue from 'vue';
import CompareVersionsComponent from '~/diffs/components/compare_versions.vue';
import store from '~/mr_notes/stores';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import diffsMockData from '../mock_data/merge_request_diffs';

describe('CompareVersions', () => {
  let vm;
  const targetBranch = { branchName: 'tmp-wine-dev', versionIndex: -1 };

  beforeEach(() => {
    vm = createComponentWithStore(Vue.extend(CompareVersionsComponent), store, {
      mergeRequestDiffs: diffsMockData,
      mergeRequestDiff: diffsMockData[0],
      targetBranch,
    }).$mount();
  });

  describe('template', () => {
    it('should render Tree List toggle button with correct attribute values', () => {
      const treeListBtn = vm.$el.querySelector('.js-toggle-tree-list');

      expect(treeListBtn).not.toBeNull();
      expect(treeListBtn.dataset.originalTitle).toBe('Toggle file browser');
      expect(treeListBtn.querySelectorAll('svg use').length).not.toBe(0);
      expect(treeListBtn.querySelector('svg use').getAttribute('xlink:href')).toContain(
        '#hamburger',
      );
    });

    it('should render comparison dropdowns with correct values', () => {
      const sourceDropdown = vm.$el.querySelector('.mr-version-dropdown');
      const targetDropdown = vm.$el.querySelector('.mr-version-compare-dropdown');

      expect(sourceDropdown).not.toBeNull();
      expect(targetDropdown).not.toBeNull();
      expect(sourceDropdown.querySelector('a span').innerHTML).toContain('latest version');
      expect(targetDropdown.querySelector('a span').innerHTML).toContain(targetBranch.branchName);
    });

    it('should not render comparison dropdowns if no mergeRequestDiffs are specified', () => {
      vm.mergeRequestDiffs = [];

      vm.$nextTick(() => {
        const sourceDropdown = vm.$el.querySelector('.mr-version-dropdown');
        const targetDropdown = vm.$el.querySelector('.mr-version-compare-dropdown');

        expect(sourceDropdown).toBeNull();
        expect(targetDropdown).toBeNull();
      });
    });

    it('should render whitespace toggle button with correct attributes', () => {
      const whitespaceBtn = vm.$el.querySelector('.qa-toggle-whitespace');
      const href = vm.toggleWhitespacePath;

      expect(whitespaceBtn).not.toBeNull();
      expect(whitespaceBtn.getAttribute('href')).toEqual(href);
      expect(whitespaceBtn.innerHTML).toContain('Hide whitespace changes');
    });

    it('should render view types buttons with correct values', () => {
      const inlineBtn = vm.$el.querySelector('#inline-diff-btn');
      const parallelBtn = vm.$el.querySelector('#parallel-diff-btn');

      expect(inlineBtn).not.toBeNull();
      expect(parallelBtn).not.toBeNull();
      expect(inlineBtn.dataset.viewType).toEqual('inline');
      expect(parallelBtn.dataset.viewType).toEqual('parallel');
      expect(inlineBtn.innerHTML).toContain('Inline');
      expect(parallelBtn.innerHTML).toContain('Side-by-side');
    });
  });

  describe('setInlineDiffViewType', () => {
    it('should persist the view type in the url', () => {
      const viewTypeBtn = vm.$el.querySelector('#inline-diff-btn');
      viewTypeBtn.click();

      expect(window.location.toString()).toContain('?view=inline');
    });
  });

  describe('setParallelDiffViewType', () => {
    it('should persist the view type in the url', () => {
      const viewTypeBtn = vm.$el.querySelector('#parallel-diff-btn');
      viewTypeBtn.click();

      expect(window.location.toString()).toContain('?view=parallel');
    });
  });

  describe('comparableDiffs', () => {
    it('should not contain the first item in the mergeRequestDiffs property', () => {
      const { comparableDiffs } = vm;
      const comparableDiffsMock = diffsMockData.slice(1);

      expect(comparableDiffs).toEqual(comparableDiffsMock);
    });
  });

  describe('isWhitespaceVisible', () => {
    const originalHref = window.location.href;

    afterEach(() => {
      window.history.replaceState({}, null, originalHref);
    });

    it('should return "true" when no "w" flag is present in the URL (default)', () => {
      expect(vm.isWhitespaceVisible()).toBe(true);
    });

    it('should return "false" when the flag is set to "1" in the URL', () => {
      window.history.replaceState({}, null, '?w=1');

      expect(vm.isWhitespaceVisible()).toBe(false);
    });

    it('should return "true" when the flag is set to "0" in the URL', () => {
      window.history.replaceState({}, null, '?w=0');

      expect(vm.isWhitespaceVisible()).toBe(true);
    });
  });
});