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

divergence_graph_spec.js « components « branches « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9429a6e982c2136fbe7a5e09a40865930b1a437a (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
import { shallowMount } from '@vue/test-utils';
import DivergenceGraph from '~/branches/components/divergence_graph.vue';
import GraphBar from '~/branches/components/graph_bar.vue';

let vm;

function factory(propsData = {}) {
  vm = shallowMount(DivergenceGraph, { propsData });
}

describe('Branch divergence graph component', () => {
  afterEach(() => {
    vm.destroy();
  });

  it('renders ahead and behind count', () => {
    factory({
      defaultBranch: 'main',
      aheadCount: 10,
      behindCount: 10,
      maxCommits: 100,
    });

    expect(vm.findAllComponents(GraphBar).length).toBe(2);
    expect(vm.element).toMatchSnapshot();
  });

  it('sets title for ahead and behind count', () => {
    factory({
      defaultBranch: 'main',
      aheadCount: 10,
      behindCount: 10,
      maxCommits: 100,
    });

    expect(vm.attributes('title')).toBe('10 commits behind main, 10 commits ahead');
  });

  it('renders distance count', () => {
    factory({
      defaultBranch: 'main',
      aheadCount: 0,
      behindCount: 0,
      distance: 900,
      maxCommits: 100,
    });

    expect(vm.findAllComponents(GraphBar).length).toBe(1);
    expect(vm.element).toMatchSnapshot();
  });

  it.each`
    distance | titleText
    ${900}   | ${'900'}
    ${1100}  | ${'999+'}
  `('sets title for $distance as $titleText', ({ distance, titleText }) => {
    factory({
      defaultBranch: 'main',
      aheadCount: 0,
      behindCount: 0,
      distance,
      maxCommits: 100,
    });

    expect(vm.attributes('title')).toBe(`More than ${titleText} commits different with main`);
  });
});