summaryrefslogtreecommitdiff
path: root/spec/frontend/reports/accessibility_report/grouped_accessibility_reports_app_spec.js
blob: 34b1cdd92bc846b765d0c73a07880f44ae3a78f5 (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { mount } from '@vue/test-utils';
import Vue from 'vue';
import Vuex from 'vuex';
import AccessibilityIssueBody from '~/reports/accessibility_report/components/accessibility_issue_body.vue';
import GroupedAccessibilityReportsApp from '~/reports/accessibility_report/grouped_accessibility_reports_app.vue';
import { getStoreConfig } from '~/reports/accessibility_report/store';
import { mockReport } from './mock_data';

Vue.use(Vuex);

describe('Grouped accessibility reports app', () => {
  let wrapper;
  let mockStore;

  const mountComponent = () => {
    wrapper = mount(GroupedAccessibilityReportsApp, {
      store: mockStore,
      propsData: {
        endpoint: 'endpoint.json',
      },
    });
  };

  const findHeader = () => wrapper.find('[data-testid="report-section-code-text"]');

  beforeEach(() => {
    mockStore = new Vuex.Store({
      ...getStoreConfig(),
      actions: { fetchReport: () => {}, setEndpoint: () => {} },
    });

    mountComponent();
  });

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

  describe('while loading', () => {
    beforeEach(() => {
      mockStore.state.isLoading = true;
      mountComponent();
    });

    it('renders loading state', () => {
      expect(findHeader().text()).toEqual('Accessibility scanning results are being parsed');
    });
  });

  describe('with error', () => {
    beforeEach(() => {
      mockStore.state.isLoading = false;
      mockStore.state.hasError = true;
      mountComponent();
    });

    it('renders error state', () => {
      expect(findHeader().text()).toEqual('Accessibility scanning failed loading results');
    });
  });

  describe('with a report', () => {
    describe('with no issues', () => {
      beforeEach(() => {
        mockStore.state.report = {
          summary: {
            errored: 0,
          },
        };
      });

      it('renders no issues header', () => {
        expect(findHeader().text()).toContain(
          'Accessibility scanning detected no issues for the source branch only',
        );
      });
    });

    describe('with one issue', () => {
      beforeEach(() => {
        mockStore.state.report = {
          summary: {
            errored: 1,
          },
        };
      });

      it('renders one issue header', () => {
        expect(findHeader().text()).toContain(
          'Accessibility scanning detected 1 issue for the source branch only',
        );
      });
    });

    describe('with multiple issues', () => {
      beforeEach(() => {
        mockStore.state.report = {
          summary: {
            errored: 2,
          },
        };
      });

      it('renders multiple issues header', () => {
        expect(findHeader().text()).toContain(
          'Accessibility scanning detected 2 issues for the source branch only',
        );
      });
    });

    describe('with issues to show', () => {
      beforeEach(() => {
        mockStore.state.report = mockReport;
      });

      it('renders custom accessibility issue body', () => {
        const issueBody = wrapper.find(AccessibilityIssueBody);

        expect(issueBody.props('issue').code).toBe(mockReport.new_errors[0].code);
        expect(issueBody.props('issue').message).toBe(mockReport.new_errors[0].message);
        expect(issueBody.props('isNew')).toBe(true);
      });
    });
  });
});