summaryrefslogtreecommitdiff
path: root/spec/javascripts/jobs/components/job_log_controllers_spec.js
blob: 3dcb57d23ce8b37ce5084f42ff7ccb3151624b31 (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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import Vue from 'vue';
import component from '~/jobs/components/job_log_controllers.vue';
import mountComponent from '../../helpers/vue_mount_component_helper';

describe('Job log controllers', () => {
  const Component = Vue.extend(component);
  let vm;

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

  const props = {
    rawPath: '/raw',
    erasePath: '/erase',
    size: 511952,
    isScrollTopDisabled: false,
    isScrollBottomDisabled: false,
    isScrollingDown: true,
    isTraceSizeVisible: true,
  };

  describe('Truncate information', () => {
    describe('with isTraceSizeVisible', () => {
      beforeEach(() => {
        vm = mountComponent(Component, props);
      });

      it('renders size information', () => {
        expect(vm.$el.querySelector('.js-truncated-info').textContent).toContain('499.95 KiB');
      });

      it('renders link to raw trace', () => {
        expect(vm.$el.querySelector('.js-raw-link').getAttribute('href')).toEqual('/raw');
      });
    });
  });

  describe('links section', () => {
    describe('with raw trace path', () => {
      it('renders raw trace link', () => {
        vm = mountComponent(Component, props);

        expect(vm.$el.querySelector('.js-raw-link-controller').getAttribute('href')).toEqual(
          '/raw',
        );
      });
    });

    describe('without raw trace path', () => {
      it('does not render raw trace link', () => {
        vm = mountComponent(Component, {
          erasePath: '/erase',
          size: 511952,
          isScrollTopDisabled: true,
          isScrollBottomDisabled: true,
          isScrollingDown: false,
          isTraceSizeVisible: true,
        });

        expect(vm.$el.querySelector('.js-raw-link-controller')).toBeNull();
      });
    });

    describe('when is erasable', () => {
      beforeEach(() => {
        vm = mountComponent(Component, props);
      });

      it('renders erase job link', () => {
        expect(vm.$el.querySelector('.js-erase-link')).not.toBeNull();
      });
    });

    describe('when it is not erasable', () => {
      it('does not render erase button', () => {
        vm = mountComponent(Component, {
          rawPath: '/raw',
          size: 511952,
          isScrollTopDisabled: true,
          isScrollBottomDisabled: true,
          isScrollingDown: false,
          isTraceSizeVisible: true,
        });

        expect(vm.$el.querySelector('.js-erase-link')).toBeNull();
      });
    });
  });

  describe('scroll buttons', () => {
    describe('scroll top button', () => {
      describe('when user can scroll top', () => {
        beforeEach(() => {
          vm = mountComponent(Component, props);
        });

        it('renders enabled scroll top button', () => {
          expect(vm.$el.querySelector('.js-scroll-top').getAttribute('disabled')).toBeNull();
        });

        it('emits scrollJobLogTop event on click', () => {
          spyOn(vm, '$emit');
          vm.$el.querySelector('.js-scroll-top').click();

          expect(vm.$emit).toHaveBeenCalledWith('scrollJobLogTop');
        });
      });

      describe('when user can not scroll top', () => {
        beforeEach(() => {
          vm = mountComponent(Component, {
            rawPath: '/raw',
            erasePath: '/erase',
            size: 511952,
            isScrollTopDisabled: true,
            isScrollBottomDisabled: false,
            isScrollingDown: false,
            isTraceSizeVisible: true,
          });
        });

        it('renders disabled scroll top button', () => {
          expect(vm.$el.querySelector('.js-scroll-top').getAttribute('disabled')).toEqual(
            'disabled',
          );
        });

        it('does not emit scrollJobLogTop event on click', () => {
          spyOn(vm, '$emit');
          vm.$el.querySelector('.js-scroll-top').click();

          expect(vm.$emit).not.toHaveBeenCalledWith('scrollJobLogTop');
        });
      });
    });

    describe('scroll bottom button', () => {
      describe('when user can scroll bottom', () => {
        beforeEach(() => {
          vm = mountComponent(Component, props);
        });

        it('renders enabled scroll bottom button', () => {
          expect(vm.$el.querySelector('.js-scroll-bottom').getAttribute('disabled')).toBeNull();
        });

        it('emits scrollJobLogBottom event on click', () => {
          spyOn(vm, '$emit');
          vm.$el.querySelector('.js-scroll-bottom').click();

          expect(vm.$emit).toHaveBeenCalledWith('scrollJobLogBottom');
        });
      });

      describe('when user can not scroll bottom', () => {
        beforeEach(() => {
          vm = mountComponent(Component, {
            rawPath: '/raw',
            erasePath: '/erase',
            size: 511952,
            isScrollTopDisabled: false,
            isScrollBottomDisabled: true,
            isScrollingDown: false,
            isTraceSizeVisible: true,
          });
        });

        it('renders disabled scroll bottom button', () => {
          expect(vm.$el.querySelector('.js-scroll-bottom').getAttribute('disabled')).toEqual(
            'disabled',
          );
        });

        it('does not emit scrollJobLogBottom event on click', () => {
          spyOn(vm, '$emit');
          vm.$el.querySelector('.js-scroll-bottom').click();

          expect(vm.$emit).not.toHaveBeenCalledWith('scrollJobLogBottom');
        });
      });

      describe('while isScrollingDown is true', () => {
        it('renders animate class for the scroll down button', () => {
          vm = mountComponent(Component, props);

          expect(vm.$el.querySelector('.js-scroll-bottom').className).toContain('animate');
        });
      });

      describe('while isScrollingDown is false', () => {
        it('does not render animate class for the scroll down button', () => {
          vm = mountComponent(Component, {
            rawPath: '/raw',
            erasePath: '/erase',
            size: 511952,
            isScrollTopDisabled: true,
            isScrollBottomDisabled: false,
            isScrollingDown: false,
            isTraceSizeVisible: true,
          });
          expect(vm.$el.querySelector('.js-scroll-bottom').className).not.toContain('animate');
        });
      });
    });
  });
});