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

detail_spec.js « jobs « components « ide « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9122471d421e6981766192fca67ce202e9641de9 (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import Vue, { nextTick } from 'vue';
import { TEST_HOST } from 'helpers/test_constants';
import { createComponentWithStore } from 'helpers/vue_mount_component_helper';
import JobDetail from '~/ide/components/jobs/detail.vue';
import { createStore } from '~/ide/stores';
import { jobs } from '../../mock_data';

describe('IDE jobs detail view', () => {
  let vm;

  const createComponent = () => {
    const store = createStore();

    store.state.pipelines.detailJob = {
      ...jobs[0],
      isLoading: true,
      output: 'testing',
      rawPath: `${TEST_HOST}/raw`,
    };

    return createComponentWithStore(Vue.extend(JobDetail), store);
  };

  beforeEach(() => {
    vm = createComponent();

    jest.spyOn(vm, 'fetchJobLogs').mockResolvedValue();
  });

  afterEach(() => {
    vm.$destroy();
  });

  describe('mounted', () => {
    beforeEach(() => {
      vm = vm.$mount();
    });

    it('calls fetchJobLogs', () => {
      expect(vm.fetchJobLogs).toHaveBeenCalled();
    });

    it('scrolls to bottom', () => {
      expect(vm.$refs.buildJobLog.scrollTo).toHaveBeenCalled();
    });

    it('renders job output', () => {
      expect(vm.$el.querySelector('.bash').textContent).toContain('testing');
    });

    it('renders empty message output', async () => {
      vm.$store.state.pipelines.detailJob.output = '';

      await nextTick();
      expect(vm.$el.querySelector('.bash').textContent).toContain('No messages were logged');
    });

    it('renders loading icon', () => {
      expect(vm.$el.querySelector('.build-loader-animation')).not.toBe(null);
      expect(vm.$el.querySelector('.build-loader-animation').style.display).toBe('');
    });

    it('hides output when loading', () => {
      expect(vm.$el.querySelector('.bash')).not.toBe(null);
      expect(vm.$el.querySelector('.bash').style.display).toBe('none');
    });

    it('hide loading icon when isLoading is false', async () => {
      vm.$store.state.pipelines.detailJob.isLoading = false;

      await nextTick();
      expect(vm.$el.querySelector('.build-loader-animation').style.display).toBe('none');
    });

    it('resets detailJob when clicking header button', () => {
      jest.spyOn(vm, 'setDetailJob').mockImplementation();

      vm.$el.querySelector('.btn').click();

      expect(vm.setDetailJob).toHaveBeenCalledWith(null);
    });

    it('renders raw path link', () => {
      expect(vm.$el.querySelector('.controllers-buttons').getAttribute('href')).toBe(
        `${TEST_HOST}/raw`,
      );
    });
  });

  describe('scroll buttons', () => {
    beforeEach(() => {
      vm = createComponent();
      jest.spyOn(vm, 'fetchJobLogs').mockResolvedValue();
    });

    afterEach(() => {
      vm.$destroy();
    });

    it.each`
      fnName          | btnName   | scrollPos
      ${'scrollDown'} | ${'down'} | ${0}
      ${'scrollUp'}   | ${'up'}   | ${1}
    `('triggers $fnName when clicking $btnName button', async ({ fnName, scrollPos }) => {
      jest.spyOn(vm, fnName).mockImplementation();

      vm = vm.$mount();

      vm.scrollPos = scrollPos;

      await nextTick();
      vm.$el.querySelector('.btn-scroll:not([disabled])').click();
      expect(vm[fnName]).toHaveBeenCalled();
    });
  });

  describe('scrollDown', () => {
    beforeEach(() => {
      vm = vm.$mount();

      jest.spyOn(vm.$refs.buildJobLog, 'scrollTo').mockImplementation();
    });

    it('scrolls build trace to bottom', () => {
      jest.spyOn(vm.$refs.buildJobLog, 'scrollHeight', 'get').mockReturnValue(1000);

      vm.scrollDown();

      expect(vm.$refs.buildJobLog.scrollTo).toHaveBeenCalledWith(0, 1000);
    });
  });

  describe('scrollUp', () => {
    beforeEach(() => {
      vm = vm.$mount();

      jest.spyOn(vm.$refs.buildJobLog, 'scrollTo').mockImplementation();
    });

    it('scrolls build trace to top', () => {
      vm.scrollUp();

      expect(vm.$refs.buildJobLog.scrollTo).toHaveBeenCalledWith(0, 0);
    });
  });

  describe('scrollBuildLog', () => {
    beforeEach(() => {
      vm = vm.$mount();
      jest.spyOn(vm.$refs.buildJobLog, 'scrollTo').mockImplementation();
      jest.spyOn(vm.$refs.buildJobLog, 'offsetHeight', 'get').mockReturnValue(100);
      jest.spyOn(vm.$refs.buildJobLog, 'scrollHeight', 'get').mockReturnValue(200);
    });

    it('sets scrollPos to bottom when at the bottom', () => {
      jest.spyOn(vm.$refs.buildJobLog, 'scrollTop', 'get').mockReturnValue(100);

      vm.scrollBuildLog();

      expect(vm.scrollPos).toBe(1);
    });

    it('sets scrollPos to top when at the top', () => {
      jest.spyOn(vm.$refs.buildJobLog, 'scrollTop', 'get').mockReturnValue(0);
      vm.scrollPos = 1;

      vm.scrollBuildLog();

      expect(vm.scrollPos).toBe(0);
    });

    it('resets scrollPos when not at top or bottom', () => {
      jest.spyOn(vm.$refs.buildJobLog, 'scrollTop', 'get').mockReturnValue(10);

      vm.scrollBuildLog();

      expect(vm.scrollPos).toBe('');
    });
  });
});