summaryrefslogtreecommitdiff
path: root/spec/javascripts/jobs/components/job_log_spec.js
blob: 24bb6b9a48b404284a092e89fd7f7f3f9c03930f (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
import Vue from 'vue';
import component from '~/jobs/components/job_log.vue';
import createStore from '~/jobs/store';
import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import { resetStore } from '../store/helpers';
import { logWithCollapsibleSections } from '../mock_data';

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

  const trace =
    '<span>Running with gitlab-runner 12.1.0 (de7731dd)<br/></span><span>  on docker-auto-scale-com d5ae8d25<br/></span><div class="js-section-start fa fa-caret-down append-right-8 cursor-pointer" data-timestamp="1565502765" data-section="prepare-executor" role="button"></div><span class="section js-section-header section-header js-s-prepare-executor">Using Docker executor with image ruby:2.6 ...<br/></span>';

  beforeEach(() => {
    store = createStore();
  });

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

  it('renders provided trace', () => {
    vm = mountComponentWithStore(Component, {
      props: {
        trace,
        isComplete: true,
      },
      store,
    });

    expect(vm.$el.querySelector('code').textContent).toContain(
      'Running with gitlab-runner 12.1.0 (de7731dd)',
    );
  });

  describe('while receiving trace', () => {
    it('renders animation', () => {
      vm = mountComponentWithStore(Component, {
        props: {
          trace,
          isComplete: false,
        },
        store,
      });

      expect(vm.$el.querySelector('.js-log-animation')).not.toBeNull();
    });
  });

  describe('when build trace has finishes', () => {
    it('does not render animation', () => {
      vm = mountComponentWithStore(Component, {
        props: {
          trace,
          isComplete: true,
        },
        store,
      });

      expect(vm.$el.querySelector('.js-log-animation')).toBeNull();
    });
  });

  describe('Collapsible sections', () => {
    beforeEach(() => {
      vm = mountComponentWithStore(Component, {
        props: {
          trace: logWithCollapsibleSections.html,
          isComplete: true,
        },
        store,
      });
    });

    it('renders open arrow', () => {
      expect(vm.$el.querySelector('.fa-caret-down')).not.toBeNull();
    });

    it('toggles hidden class to the sibilings rows when arrow is clicked', done => {
      vm.$nextTick()
        .then(() => {
          const { section } = vm.$el.querySelector('.js-section-start').dataset;
          vm.$el.querySelector('.js-section-start').click();

          vm.$el.querySelectorAll(`.js-s-${section}:not(.js-section-header)`).forEach(el => {
            expect(el.classList.contains('hidden')).toEqual(true);
          });

          vm.$el.querySelector('.js-section-start').click();

          vm.$el.querySelectorAll(`.js-s-${section}:not(.js-section-header)`).forEach(el => {
            expect(el.classList.contains('hidden')).toEqual(false);
          });
        })
        .then(done)
        .catch(done.fail);
    });

    it('toggles hidden class to the sibilings rows when header section is clicked', done => {
      vm.$nextTick()
        .then(() => {
          const { section } = vm.$el.querySelector('.js-section-header').dataset;
          vm.$el.querySelector('.js-section-header').click();

          vm.$el.querySelectorAll(`.js-s-${section}:not(.js-section-header)`).forEach(el => {
            expect(el.classList.contains('hidden')).toEqual(true);
          });

          vm.$el.querySelector('.js-section-header').click();

          vm.$el.querySelectorAll(`.js-s-${section}:not(.js-section-header)`).forEach(el => {
            expect(el.classList.contains('hidden')).toEqual(false);
          });
        })
        .then(done)
        .catch(done.fail);
    });
  });
});