BigW Consortium Gitlab

sidebar_details_block_spec.js 2.93 KB
Newer Older
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
import Vue from 'vue';
import sidebarDetailsBlock from '~/jobs/components/sidebar_details_block.vue';
import job from './mock_data';

describe('Sidebar details block', () => {
  let SidebarComponent;
  let vm;

  function trimWhitespace(element) {
    return element.textContent.replace(/\s+/g, ' ').trim();
  }

  beforeEach(() => {
    SidebarComponent = Vue.extend(sidebarDetailsBlock);
  });

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

  describe('when it is loading', () => {
    it('should render a loading spinner', () => {
      vm = new SidebarComponent({
        propsData: {
          job: {},
          isLoading: true,
        },
      }).$mount();

      expect(vm.$el.querySelector('.fa-spinner')).toBeDefined();
    });
  });

  beforeEach(() => {
    vm = new SidebarComponent({
      propsData: {
        job,
        isLoading: false,
      },
    }).$mount();
  });

  describe('actions', () => {
    it('should render link to new issue', () => {
      expect(vm.$el.querySelector('.js-new-issue').getAttribute('href')).toEqual(job.new_issue_path);
      expect(vm.$el.querySelector('.js-new-issue').textContent.trim()).toEqual('New issue');
    });

    it('should render link to retry job', () => {
      expect(vm.$el.querySelector('.js-retry-job').getAttribute('href')).toEqual(job.retry_path);
    });

    it('should render link to cancel job', () => {
      expect(vm.$el.querySelector('.js-cancel-job').getAttribute('href')).toEqual(job.cancel_path);
    });
  });

  describe('information', () => {
    it('should render merge request link', () => {
      expect(
        trimWhitespace(vm.$el.querySelector('.js-job-mr')),
      ).toEqual('Merge Request: !2');

      expect(
        vm.$el.querySelector('.js-job-mr a').getAttribute('href'),
      ).toEqual(job.merge_request.path);
    });

    it('should render job duration', () => {
      expect(
        trimWhitespace(vm.$el.querySelector('.js-job-duration')),
      ).toEqual('Duration: 6 seconds');
    });

    it('should render erased date', () => {
      expect(
        trimWhitespace(vm.$el.querySelector('.js-job-erased')),
      ).toEqual('Erased: 3 weeks ago');
    });

    it('should render finished date', () => {
      expect(
        trimWhitespace(vm.$el.querySelector('.js-job-finished')),
      ).toEqual('Finished: 3 weeks ago');
    });

    it('should render queued date', () => {
      expect(
        trimWhitespace(vm.$el.querySelector('.js-job-queued')),
      ).toEqual('Queued: 9 seconds');
    });

    it('should render runner ID', () => {
      expect(
        trimWhitespace(vm.$el.querySelector('.js-job-runner')),
      ).toEqual('Runner: #1');
    });

    it('should render coverage', () => {
      expect(
        trimWhitespace(vm.$el.querySelector('.js-job-coverage')),
      ).toEqual('Coverage: 20%');
    });

    it('should render tags', () => {
      expect(
        trimWhitespace(vm.$el.querySelector('.js-job-tags')),
      ).toEqual('Tags: tag');
    });
  });
});