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

test_case_details_spec.js « test_reports « pipelines « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e866586a2c30668e8db3cc3236619fa7198622ab (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
import { GlModal } from '@gitlab/ui';
import { shallowMount, createLocalVue } from '@vue/test-utils';
import TestCaseDetails from '~/pipelines/components/test_reports/test_case_details.vue';
import CodeBlock from '~/vue_shared/components/code_block.vue';

const localVue = createLocalVue();

describe('Test case details', () => {
  let wrapper;
  const defaultTestCase = {
    classname: 'spec.test_spec',
    name: 'Test#something cool',
    formattedTime: '10.04ms',
    recent_failures: {
      count: 2,
      base_branch: 'master',
    },
    system_output: 'Line 42 is broken',
  };

  const findModal = () => wrapper.find(GlModal);
  const findName = () => wrapper.find('[data-testid="test-case-name"]');
  const findDuration = () => wrapper.find('[data-testid="test-case-duration"]');
  const findRecentFailures = () => wrapper.find('[data-testid="test-case-recent-failures"]');
  const findSystemOutput = () => wrapper.find('[data-testid="test-case-trace"]');

  const createComponent = (testCase = {}) => {
    wrapper = shallowMount(TestCaseDetails, {
      localVue,
      propsData: {
        modalId: 'my-modal',
        testCase: {
          ...defaultTestCase,
          ...testCase,
        },
      },
      stubs: { CodeBlock, GlModal },
    });
  };

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

  describe('required details', () => {
    beforeEach(() => {
      createComponent();
    });

    it('renders the test case classname as modal title', () => {
      expect(findModal().props('title')).toBe(defaultTestCase.classname);
    });

    it('renders the test case name', () => {
      expect(findName().text()).toBe(defaultTestCase.name);
    });

    it('renders the test case duration', () => {
      expect(findDuration().text()).toBe(defaultTestCase.formattedTime);
    });
  });

  describe('when test case has recent failures', () => {
    describe('has only 1 recent failure', () => {
      it('renders the recent failure', () => {
        createComponent({ recent_failures: { ...defaultTestCase.recent_failures, count: 1 } });

        expect(findRecentFailures().text()).toContain(
          `Failed 1 time in ${defaultTestCase.recent_failures.base_branch} in the last 14 days`,
        );
      });
    });

    describe('has more than 1 recent failure', () => {
      it('renders the recent failures', () => {
        createComponent();

        expect(findRecentFailures().text()).toContain(
          `Failed ${defaultTestCase.recent_failures.count} times in ${defaultTestCase.recent_failures.base_branch} in the last 14 days`,
        );
      });
    });
  });

  describe('when test case does not have recent failures', () => {
    it('does not render the recent failures', () => {
      createComponent({ recent_failures: null });

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

  describe('when test case has system output', () => {
    it('renders the test case system output', () => {
      createComponent();

      expect(findSystemOutput().text()).toContain(defaultTestCase.system_output);
    });
  });

  describe('when test case does not have system output', () => {
    it('does not render the test case system output', () => {
      createComponent({ system_output: null });

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