issue_warning_spec.js 1.78 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
import Vue from 'vue';
import issueWarning from '~/vue_shared/components/issue/issue_warning.vue';
import mountComponent from '../../../helpers/vue_mount_component_helper';

const IssueWarning = Vue.extend(issueWarning);

function formatWarning(string) {
  // Replace newlines with a space then replace multiple spaces with one space
  return string.trim().replace(/\n/g, ' ').replace(/\s\s+/g, ' ');
}

describe('Issue Warning Component', () => {
  describe('isLocked', () => {
    it('should render locked issue warning information', () => {
      const vm = mountComponent(IssueWarning, {
        isLocked: true,
      });

      expect(vm.$el.querySelector('i').className).toEqual('fa fa-lock');
      expect(formatWarning(vm.$el.querySelector('span').textContent)).toEqual('This issue is locked. Only project members can comment.');
    });
  });

  describe('isConfidential', () => {
    it('should render confidential issue warning information', () => {
      const vm = mountComponent(IssueWarning, {
        isConfidential: true,
      });

      expect(vm.$el.querySelector('i').className).toEqual('fa fa-eye-slash');
      expect(formatWarning(vm.$el.querySelector('span').textContent)).toEqual('This is a confidential issue. Your comment will not be visible to the public.');
    });
  });

  describe('isLocked and isConfidential', () => {
    it('should render locked and confidential issue warning information', () => {
      const vm = mountComponent(IssueWarning, {
        isLocked: true,
        isConfidential: true,
      });

      expect(vm.$el.querySelector('i')).toBeFalsy();
      expect(formatWarning(vm.$el.querySelector('span').textContent)).toEqual('This issue is confidential and locked. People without permission will never get a notification and not be able to comment.');
    });
  });
});