Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test_issue_body_spec.js « components « grouped_test_report « reports « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8a854a92ad74313c3712766d4a7659ff8ab81954 (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
import { GlBadge, GlButton } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import Vue from 'vue';
import Vuex from 'vuex';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import IssueStatusIcon from '~/reports/components/issue_status_icon.vue';
import TestIssueBody from '~/reports/grouped_test_report/components/test_issue_body.vue';
import { failedIssue, successIssue } from '../../mock_data/mock_data';

Vue.use(Vuex);

describe('Test issue body', () => {
  let wrapper;
  let store;

  const findDescription = () => wrapper.findByTestId('test-issue-body-description');
  const findStatusIcon = () => wrapper.findComponent(IssueStatusIcon);
  const findBadge = () => wrapper.findComponent(GlBadge);

  const actionSpies = {
    openModal: jest.fn(),
  };

  const createComponent = ({ issue = failedIssue } = {}) => {
    store = new Vuex.Store({
      actions: actionSpies,
    });

    wrapper = extendedWrapper(
      shallowMount(TestIssueBody, {
        store,
        propsData: {
          issue,
        },
        stubs: {
          GlBadge,
          GlButton,
          IssueStatusIcon,
        },
      }),
    );
  };

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

  describe('when issue has failed status', () => {
    beforeEach(() => {
      createComponent();
    });

    it('renders issue name', () => {
      expect(findDescription().text()).toContain(failedIssue.name);
    });

    it('renders failed status icon', () => {
      expect(findStatusIcon().props('status')).toBe('failed');
    });

    describe('when issue has recent failures', () => {
      it('renders recent failures badge', () => {
        expect(findBadge().exists()).toBe(true);
      });
    });
  });

  describe('when issue has success status', () => {
    beforeEach(() => {
      createComponent({ issue: successIssue });
    });

    it('does not render recent failures', () => {
      expect(findBadge().exists()).toBe(false);
    });

    it('renders issue name', () => {
      expect(findDescription().text()).toBe(successIssue.name);
    });

    it('renders success status icon', () => {
      expect(findStatusIcon().props('status')).toBe('success');
    });
  });

  describe('when clicking on an issue', () => {
    it('calls openModal action', () => {
      createComponent();
      wrapper.findComponent(GlButton).trigger('click');

      expect(actionSpies.openModal).toHaveBeenCalledWith(expect.any(Object), {
        issue: failedIssue,
      });
    });
  });
});