2020-05-24 23:13:21 +05:30
|
|
|
import { mount, createLocalVue } from '@vue/test-utils';
|
|
|
|
import Vuex from 'vuex';
|
|
|
|
import AccessibilityIssueBody from '~/reports/accessibility_report/components/accessibility_issue_body.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import GroupedAccessibilityReportsApp from '~/reports/accessibility_report/grouped_accessibility_reports_app.vue';
|
2020-11-24 15:15:51 +05:30
|
|
|
import { getStoreConfig } from '~/reports/accessibility_report/store';
|
2020-05-24 23:13:21 +05:30
|
|
|
import { mockReport } from './mock_data';
|
|
|
|
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
localVue.use(Vuex);
|
|
|
|
|
|
|
|
describe('Grouped accessibility reports app', () => {
|
|
|
|
const Component = localVue.extend(GroupedAccessibilityReportsApp);
|
|
|
|
let wrapper;
|
|
|
|
let mockStore;
|
|
|
|
|
|
|
|
const mountComponent = () => {
|
|
|
|
wrapper = mount(Component, {
|
|
|
|
store: mockStore,
|
|
|
|
localVue,
|
|
|
|
propsData: {
|
|
|
|
endpoint: 'endpoint.json',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const findHeader = () => wrapper.find('[data-testid="report-section-code-text"]');
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-11-24 15:15:51 +05:30
|
|
|
mockStore = new Vuex.Store({
|
|
|
|
...getStoreConfig(),
|
|
|
|
actions: { fetchReport: () => {}, setEndpoint: () => {} },
|
|
|
|
});
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|