summaryrefslogtreecommitdiff
path: root/spec/javascripts/vue_mr_widget/components/mr_widget_alert_message_spec.js
blob: f115cb457e5fc4732a15c9dbae75d1a4571a2471 (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
import { shallowMount, createLocalVue } from '@vue/test-utils';
import MrWidgetAlertMessage from '~/vue_merge_request_widget/components/mr_widget_alert_message.vue';
import { GlLink } from '@gitlab/ui';

describe('MrWidgetAlertMessage', () => {
  let wrapper;

  beforeEach(() => {
    const localVue = createLocalVue();

    wrapper = shallowMount(localVue.extend(MrWidgetAlertMessage), {
      propsData: {},
      localVue,
    });
  });

  afterEach(() => {
    wrapper.destroy();
  });

  describe('when type is not provided', () => {
    it('should render a red message', () => {
      expect(wrapper.classes()).toContain('danger_message');
      expect(wrapper.classes()).not.toContain('warning_message');
    });
  });

  describe('when type === "danger"', () => {
    it('should render a red message', () => {
      wrapper.setProps({ type: 'danger' });

      expect(wrapper.classes()).toContain('danger_message');
      expect(wrapper.classes()).not.toContain('warning_message');
    });
  });

  describe('when type === "warning"', () => {
    it('should render a red message', () => {
      wrapper.setProps({ type: 'warning' });

      expect(wrapper.classes()).toContain('warning_message');
      expect(wrapper.classes()).not.toContain('danger_message');
    });
  });

  describe('when helpPath is not provided', () => {
    it('should not render a help icon/link', () => {
      const link = wrapper.find(GlLink);

      expect(link.exists()).toBe(false);
    });
  });

  describe('when helpPath is provided', () => {
    it('should render a help icon/link', () => {
      wrapper.setProps({ helpPath: '/path/to/help/docs' });
      const link = wrapper.find(GlLink);

      expect(link.exists()).toBe(true);
      expect(link.attributes().href).toBe('/path/to/help/docs');
    });
  });
});