diff options
Diffstat (limited to 'spec/frontend/reports/grouped_test_report')
6 files changed, 0 insertions, 1104 deletions
diff --git a/spec/frontend/reports/grouped_test_report/components/modal_spec.js b/spec/frontend/reports/grouped_test_report/components/modal_spec.js deleted file mode 100644 index e8564d2428d..00000000000 --- a/spec/frontend/reports/grouped_test_report/components/modal_spec.js +++ /dev/null @@ -1,68 +0,0 @@ -import { GlLink, GlSprintf } from '@gitlab/ui'; -import { shallowMount } from '@vue/test-utils'; -import { extendedWrapper } from 'helpers/vue_test_utils_helper'; - -import ReportsModal from '~/reports/grouped_test_report/components/modal.vue'; -import state from '~/reports/grouped_test_report/store/state'; -import CodeBlock from '~/vue_shared/components/code_block.vue'; - -const StubbedGlModal = { template: '<div><slot></slot></div>', name: 'GlModal', props: ['title'] }; - -describe('Grouped Test Reports Modal', () => { - const modalDataStructure = state().modal.data; - const title = 'Test#sum when a is 1 and b is 2 returns summary'; - - // populate data - modalDataStructure.execution_time.value = 0.009411; - modalDataStructure.system_output.value = 'Failure/Error: is_expected.to eq(3)\n\n'; - modalDataStructure.filename.value = { - text: 'link', - path: '/file/path', - }; - - let wrapper; - - beforeEach(() => { - wrapper = extendedWrapper( - shallowMount(ReportsModal, { - propsData: { - title, - modalData: modalDataStructure, - visible: true, - }, - stubs: { GlModal: StubbedGlModal, GlSprintf }, - }), - ); - }); - - afterEach(() => { - wrapper.destroy(); - }); - - it('renders code block', () => { - expect(wrapper.findComponent(CodeBlock).props().code).toEqual( - modalDataStructure.system_output.value, - ); - }); - - it('renders link', () => { - const link = wrapper.findComponent(GlLink); - - expect(link.attributes().href).toEqual(modalDataStructure.filename.value.path); - - expect(link.text()).toEqual(modalDataStructure.filename.value.text); - }); - - it('renders seconds', () => { - expect(wrapper.text()).toContain(`${modalDataStructure.execution_time.value} s`); - }); - - it('render title', () => { - expect(wrapper.findComponent(StubbedGlModal).props().title).toEqual(title); - }); - - it('re-emits hide event', () => { - wrapper.findComponent(StubbedGlModal).vm.$emit('hide'); - expect(wrapper.emitted().hide).toEqual([[]]); - }); -}); diff --git a/spec/frontend/reports/grouped_test_report/components/test_issue_body_spec.js b/spec/frontend/reports/grouped_test_report/components/test_issue_body_spec.js deleted file mode 100644 index 8a854a92ad7..00000000000 --- a/spec/frontend/reports/grouped_test_report/components/test_issue_body_spec.js +++ /dev/null @@ -1,96 +0,0 @@ -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, - }); - }); - }); -}); diff --git a/spec/frontend/reports/grouped_test_report/grouped_test_reports_app_spec.js b/spec/frontend/reports/grouped_test_report/grouped_test_reports_app_spec.js deleted file mode 100644 index 90edb27d1d6..00000000000 --- a/spec/frontend/reports/grouped_test_report/grouped_test_reports_app_spec.js +++ /dev/null @@ -1,355 +0,0 @@ -import { mount } from '@vue/test-utils'; -import Vue from 'vue'; -import Vuex from 'vuex'; -import Api from '~/api'; -import GroupedTestReportsApp from '~/reports/grouped_test_report/grouped_test_reports_app.vue'; -import { getStoreConfig } from '~/reports/grouped_test_report/store'; - -import { failedReport } from '../mock_data/mock_data'; -import mixedResultsTestReports from '../mock_data/new_and_fixed_failures_report.json'; -import newErrorsTestReports from '../mock_data/new_errors_report.json'; -import newFailedTestReports from '../mock_data/new_failures_report.json'; -import successTestReports from '../mock_data/no_failures_report.json'; -import recentFailuresTestReports from '../mock_data/recent_failures_report.json'; -import resolvedFailures from '../mock_data/resolved_failures.json'; - -jest.mock('~/api.js'); - -Vue.use(Vuex); - -describe('Grouped test reports app', () => { - const endpoint = 'endpoint.json'; - const headBlobPath = '/blob/path'; - const pipelinePath = '/path/to/pipeline'; - let wrapper; - let mockStore; - - const mountComponent = ({ props = { pipelinePath } } = {}) => { - wrapper = mount(GroupedTestReportsApp, { - store: mockStore, - propsData: { - endpoint, - headBlobPath, - pipelinePath, - ...props, - }, - }); - }; - - const setReports = (reports) => { - mockStore.state.status = reports.status; - mockStore.state.summary = reports.summary; - mockStore.state.reports = reports.suites; - }; - - const findHeader = () => wrapper.find('[data-testid="report-section-code-text"]'); - const findExpandButton = () => wrapper.find('[data-testid="report-section-expand-button"]'); - const findFullTestReportLink = () => wrapper.find('[data-testid="group-test-reports-full-link"]'); - const findSummaryDescription = () => wrapper.find('[data-testid="summary-row-description"]'); - const findIssueListUnresolvedHeading = () => wrapper.find('[data-testid="unresolvedHeading"]'); - const findIssueListResolvedHeading = () => wrapper.find('[data-testid="resolvedHeading"]'); - const findIssueDescription = () => wrapper.find('[data-testid="test-issue-body-description"]'); - const findIssueRecentFailures = () => - wrapper.find('[data-testid="test-issue-body-recent-failures"]'); - const findAllIssueDescriptions = () => - wrapper.findAll('[data-testid="test-issue-body-description"]'); - - beforeEach(() => { - mockStore = new Vuex.Store({ - ...getStoreConfig(), - actions: { - fetchReports: () => {}, - setPaths: () => {}, - }, - }); - mountComponent(); - }); - - afterEach(() => { - wrapper.destroy(); - wrapper = null; - }); - - describe('with success result', () => { - beforeEach(() => { - setReports(successTestReports); - mountComponent(); - }); - - it('renders success summary text', () => { - expect(findHeader().text()).toBe( - 'Test summary contained no changed test results out of 11 total tests', - ); - }); - }); - - describe('`View full report` button', () => { - it('should render the full test report link', () => { - const fullTestReportLink = findFullTestReportLink(); - - expect(fullTestReportLink.exists()).toBe(true); - expect(pipelinePath).not.toBe(''); - expect(fullTestReportLink.attributes('href')).toBe(`${pipelinePath}/test_report`); - }); - - describe('Without a pipelinePath', () => { - beforeEach(() => { - mountComponent({ - props: { pipelinePath: '' }, - }); - }); - - it('should not render the full test report link', () => { - expect(findFullTestReportLink().exists()).toBe(false); - }); - }); - }); - - describe('`Expand` button', () => { - beforeEach(() => { - setReports(newFailedTestReports); - }); - - it('tracks service ping metric', () => { - mountComponent(); - findExpandButton().trigger('click'); - - expect(Api.trackRedisHllUserEvent).toHaveBeenCalledTimes(1); - expect(Api.trackRedisHllUserEvent).toHaveBeenCalledWith(wrapper.vm.$options.expandEvent); - }); - - it('only tracks the first expansion', () => { - mountComponent(); - const expandButton = findExpandButton(); - expandButton.trigger('click'); - expandButton.trigger('click'); - expandButton.trigger('click'); - - expect(Api.trackRedisHllUserEvent).toHaveBeenCalledTimes(1); - }); - }); - - describe('with new failed result', () => { - beforeEach(() => { - setReports(newFailedTestReports); - mountComponent(); - }); - - it('renders New heading', () => { - expect(findIssueListUnresolvedHeading().text()).toBe('New'); - }); - - it('renders failed summary text', () => { - expect(findHeader().text()).toBe('Test summary contained 2 failed out of 11 total tests'); - }); - - it('renders failed test suite', () => { - expect(findSummaryDescription().text()).toContain( - 'rspec:pg found 2 failed out of 8 total tests', - ); - }); - - it('renders failed issue in list', () => { - expect(findIssueDescription().text()).toContain( - 'Test#sum when a is 1 and b is 2 returns summary', - ); - }); - }); - - describe('with new error result', () => { - beforeEach(() => { - setReports(newErrorsTestReports); - mountComponent(); - }); - - it('renders New heading', () => { - expect(findIssueListUnresolvedHeading().text()).toBe('New'); - }); - - it('renders error summary text', () => { - expect(findHeader().text()).toBe('Test summary contained 2 errors out of 11 total tests'); - }); - - it('renders error test suite', () => { - expect(findSummaryDescription().text()).toContain( - 'karma found 2 errors out of 3 total tests', - ); - }); - - it('renders error issue in list', () => { - expect(findIssueDescription().text()).toContain( - 'Test#sum when a is 1 and b is 2 returns summary', - ); - }); - }); - - describe('with mixed results', () => { - beforeEach(() => { - setReports(mixedResultsTestReports); - mountComponent(); - }); - - it('renders New and Fixed headings', () => { - expect(findIssueListUnresolvedHeading().text()).toBe('New'); - expect(findIssueListResolvedHeading().text()).toBe('Fixed'); - }); - - it('renders summary text', () => { - expect(findHeader().text()).toBe( - 'Test summary contained 2 failed and 2 fixed test results out of 11 total tests', - ); - }); - - it('renders failed test suite', () => { - expect(findSummaryDescription().text()).toContain( - 'rspec:pg found 1 failed and 2 fixed test results out of 8 total tests', - ); - }); - - it('renders failed issue in list', () => { - expect(findIssueDescription().text()).toContain( - 'Test#subtract when a is 2 and b is 1 returns correct result', - ); - }); - }); - - describe('with resolved failures and resolved errors', () => { - beforeEach(() => { - setReports(resolvedFailures); - mountComponent(); - }); - - it('renders Fixed heading', () => { - expect(findIssueListResolvedHeading().text()).toBe('Fixed'); - }); - - it('renders summary text', () => { - expect(findHeader().text()).toBe( - 'Test summary contained 4 fixed test results out of 11 total tests', - ); - }); - - it('renders resolved test suite', () => { - expect(findSummaryDescription().text()).toContain( - 'rspec:pg found 4 fixed test results out of 8 total tests', - ); - }); - - it('renders resolved failures', () => { - expect(findIssueDescription().text()).toContain( - resolvedFailures.suites[0].resolved_failures[0].name, - ); - }); - - it('renders resolved errors', () => { - expect(findAllIssueDescriptions().at(2).text()).toContain( - resolvedFailures.suites[0].resolved_errors[0].name, - ); - }); - }); - - describe('recent failures counts', () => { - describe('with recent failures counts', () => { - beforeEach(() => { - setReports(recentFailuresTestReports); - mountComponent(); - }); - - it('renders the recently failed tests summary', () => { - expect(findHeader().text()).toContain( - '2 out of 3 failed tests have failed more than once in the last 14 days', - ); - }); - - it('renders the recently failed count on the test suite', () => { - expect(findSummaryDescription().text()).toContain( - '1 out of 2 failed tests has failed more than once in the last 14 days', - ); - }); - - it('renders the recent failures count on the test case', () => { - expect(findIssueRecentFailures().text()).toBe('Failed 8 times in main in the last 14 days'); - }); - }); - - describe('without recent failures counts', () => { - beforeEach(() => { - setReports(mixedResultsTestReports); - mountComponent(); - }); - - it('does not render the recently failed tests summary', () => { - expect(findHeader().text()).not.toContain('failed more than once in the last 14 days'); - }); - - it('does not render the recently failed count on the test suite', () => { - expect(findSummaryDescription().text()).not.toContain( - 'failed more than once in the last 14 days', - ); - }); - - it('does not render the recent failures count on the test case', () => { - expect(findIssueDescription().text()).not.toContain('in the last 14 days'); - }); - }); - }); - - describe('with a report that failed to load', () => { - beforeEach(() => { - setReports(failedReport); - mountComponent(); - }); - - it('renders an error status for the report', () => { - const { name } = failedReport.suites[0]; - - expect(findSummaryDescription().text()).toContain( - `An error occurred while loading ${name} result`, - ); - }); - }); - - describe('with a report parsing errors', () => { - beforeEach(() => { - const reports = failedReport; - reports.suites[0].suite_errors = { - head: 'JUnit XML parsing failed: 2:24: FATAL: attributes construct error', - base: 'JUnit data parsing failed: string not matched', - }; - setReports(reports); - mountComponent(); - }); - - it('renders the error messages', () => { - expect(findSummaryDescription().text()).toContain( - 'JUnit XML parsing failed: 2:24: FATAL: attributes construct error', - ); - expect(findSummaryDescription().text()).toContain( - 'JUnit data parsing failed: string not matched', - ); - }); - }); - - describe('with error', () => { - beforeEach(() => { - mockStore.state.isLoading = false; - mockStore.state.hasError = true; - mountComponent(); - }); - - it('renders loading state', () => { - expect(findHeader().text()).toBe('Test summary failed loading results'); - }); - }); - - describe('while loading', () => { - beforeEach(() => { - mockStore.state.isLoading = true; - mountComponent(); - }); - - it('renders loading state', () => { - expect(findHeader().text()).toBe('Test summary results are being parsed'); - }); - }); -}); diff --git a/spec/frontend/reports/grouped_test_report/store/actions_spec.js b/spec/frontend/reports/grouped_test_report/store/actions_spec.js deleted file mode 100644 index 7469c31cf84..00000000000 --- a/spec/frontend/reports/grouped_test_report/store/actions_spec.js +++ /dev/null @@ -1,168 +0,0 @@ -import MockAdapter from 'axios-mock-adapter'; -import { TEST_HOST } from 'helpers/test_constants'; -import testAction from 'helpers/vuex_action_helper'; -import axios from '~/lib/utils/axios_utils'; -import { - setPaths, - requestReports, - fetchReports, - stopPolling, - clearEtagPoll, - receiveReportsSuccess, - receiveReportsError, - openModal, - closeModal, -} from '~/reports/grouped_test_report/store/actions'; -import * as types from '~/reports/grouped_test_report/store/mutation_types'; -import state from '~/reports/grouped_test_report/store/state'; - -describe('Reports Store Actions', () => { - let mockedState; - - beforeEach(() => { - mockedState = state(); - }); - - describe('setPaths', () => { - it('should commit SET_PATHS mutation', () => { - return testAction( - setPaths, - { endpoint: 'endpoint.json', headBlobPath: '/blob/path' }, - mockedState, - [ - { - type: types.SET_PATHS, - payload: { endpoint: 'endpoint.json', headBlobPath: '/blob/path' }, - }, - ], - [], - ); - }); - }); - - describe('requestReports', () => { - it('should commit REQUEST_REPORTS mutation', () => { - return testAction(requestReports, null, mockedState, [{ type: types.REQUEST_REPORTS }], []); - }); - }); - - describe('fetchReports', () => { - let mock; - - beforeEach(() => { - mockedState.endpoint = `${TEST_HOST}/endpoint.json`; - mock = new MockAdapter(axios); - }); - - afterEach(() => { - mock.restore(); - stopPolling(); - clearEtagPoll(); - }); - - describe('success', () => { - it('dispatches requestReports and receiveReportsSuccess', () => { - mock - .onGet(`${TEST_HOST}/endpoint.json`) - .replyOnce(200, { summary: {}, suites: [{ name: 'rspec' }] }); - - return testAction( - fetchReports, - null, - mockedState, - [], - [ - { - type: 'requestReports', - }, - { - payload: { data: { summary: {}, suites: [{ name: 'rspec' }] }, status: 200 }, - type: 'receiveReportsSuccess', - }, - ], - ); - }); - }); - - describe('error', () => { - beforeEach(() => { - mock.onGet(`${TEST_HOST}/endpoint.json`).reply(500); - }); - - it('dispatches requestReports and receiveReportsError', () => { - return testAction( - fetchReports, - null, - mockedState, - [], - [ - { - type: 'requestReports', - }, - { - type: 'receiveReportsError', - }, - ], - ); - }); - }); - }); - - describe('receiveReportsSuccess', () => { - it('should commit RECEIVE_REPORTS_SUCCESS mutation with 200', () => { - return testAction( - receiveReportsSuccess, - { data: { summary: {} }, status: 200 }, - mockedState, - [{ type: types.RECEIVE_REPORTS_SUCCESS, payload: { summary: {} } }], - [], - ); - }); - - it('should not commit RECEIVE_REPORTS_SUCCESS mutation with 204', () => { - return testAction( - receiveReportsSuccess, - { data: { summary: {} }, status: 204 }, - mockedState, - [], - [], - ); - }); - }); - - describe('receiveReportsError', () => { - it('should commit RECEIVE_REPORTS_ERROR mutation', () => { - return testAction( - receiveReportsError, - null, - mockedState, - [{ type: types.RECEIVE_REPORTS_ERROR }], - [], - ); - }); - }); - - describe('openModal', () => { - it('should commit SET_ISSUE_MODAL_DATA', () => { - return testAction( - openModal, - { name: 'foo' }, - mockedState, - [{ type: types.SET_ISSUE_MODAL_DATA, payload: { name: 'foo' } }], - [], - ); - }); - }); - - describe('closeModal', () => { - it('should commit RESET_ISSUE_MODAL_DATA', () => { - return testAction( - closeModal, - {}, - mockedState, - [{ type: types.RESET_ISSUE_MODAL_DATA, payload: {} }], - [], - ); - }); - }); -}); diff --git a/spec/frontend/reports/grouped_test_report/store/mutations_spec.js b/spec/frontend/reports/grouped_test_report/store/mutations_spec.js deleted file mode 100644 index b2890d7285f..00000000000 --- a/spec/frontend/reports/grouped_test_report/store/mutations_spec.js +++ /dev/null @@ -1,162 +0,0 @@ -import * as types from '~/reports/grouped_test_report/store/mutation_types'; -import mutations from '~/reports/grouped_test_report/store/mutations'; -import state from '~/reports/grouped_test_report/store/state'; -import { failedIssue } from '../../mock_data/mock_data'; - -describe('Reports Store Mutations', () => { - let stateCopy; - - beforeEach(() => { - stateCopy = state(); - }); - - describe('SET_PATHS', () => { - it('should set endpoint', () => { - mutations[types.SET_PATHS](stateCopy, { - endpoint: 'endpoint.json', - headBlobPath: '/blob/path', - }); - - expect(stateCopy.endpoint).toEqual('endpoint.json'); - expect(stateCopy.headBlobPath).toEqual('/blob/path'); - }); - }); - - describe('REQUEST_REPORTS', () => { - it('should set isLoading to true', () => { - mutations[types.REQUEST_REPORTS](stateCopy); - - expect(stateCopy.isLoading).toEqual(true); - }); - }); - - describe('RECEIVE_REPORTS_SUCCESS', () => { - const mockedResponse = { - summary: { - total: 14, - resolved: 0, - failed: 7, - }, - suites: [ - { - name: 'build:linux', - summary: { - total: 2, - resolved: 0, - failed: 1, - }, - new_failures: [ - { - name: 'StringHelper#concatenate when a is git and b is lab returns summary', - execution_time: 0.0092435, - system_output: "Failure/Error: is_expected.to eq('gitlab')", - recent_failures: { - count: 4, - base_branch: 'main', - }, - }, - ], - resolved_failures: [ - { - name: 'StringHelper#concatenate when a is git and b is lab returns summary', - execution_time: 0.009235, - system_output: "Failure/Error: is_expected.to eq('gitlab')", - }, - ], - existing_failures: [ - { - name: 'StringHelper#concatenate when a is git and b is lab returns summary', - execution_time: 1232.08, - system_output: "Failure/Error: is_expected.to eq('gitlab')", - }, - ], - }, - ], - }; - - beforeEach(() => { - mutations[types.RECEIVE_REPORTS_SUCCESS](stateCopy, mockedResponse); - }); - - it('should reset isLoading', () => { - expect(stateCopy.isLoading).toEqual(false); - }); - - it('should reset hasError', () => { - expect(stateCopy.hasError).toEqual(false); - }); - - it('should set summary counts', () => { - expect(stateCopy.summary.total).toEqual(mockedResponse.summary.total); - expect(stateCopy.summary.resolved).toEqual(mockedResponse.summary.resolved); - expect(stateCopy.summary.failed).toEqual(mockedResponse.summary.failed); - expect(stateCopy.summary.recentlyFailed).toEqual(1); - }); - - it('should set reports', () => { - expect(stateCopy.reports).toEqual(mockedResponse.suites); - }); - }); - - describe('RECEIVE_REPORTS_ERROR', () => { - beforeEach(() => { - mutations[types.RECEIVE_REPORTS_ERROR](stateCopy); - }); - - it('should reset isLoading', () => { - expect(stateCopy.isLoading).toEqual(false); - }); - - it('should set hasError to true', () => { - expect(stateCopy.hasError).toEqual(true); - }); - - it('should reset reports', () => { - expect(stateCopy.reports).toEqual([]); - }); - }); - - describe('SET_ISSUE_MODAL_DATA', () => { - beforeEach(() => { - mutations[types.SET_ISSUE_MODAL_DATA](stateCopy, { - issue: failedIssue, - }); - }); - - it('should set modal title', () => { - expect(stateCopy.modal.title).toEqual(failedIssue.name); - }); - - it('should set modal data', () => { - expect(stateCopy.modal.data.execution_time.value).toEqual(failedIssue.execution_time); - expect(stateCopy.modal.data.system_output.value).toEqual(failedIssue.system_output); - }); - - it('should open modal', () => { - expect(stateCopy.modal.open).toEqual(true); - }); - }); - - describe('RESET_ISSUE_MODAL_DATA', () => { - beforeEach(() => { - mutations[types.SET_ISSUE_MODAL_DATA](stateCopy, { - issue: failedIssue, - }); - - mutations[types.RESET_ISSUE_MODAL_DATA](stateCopy); - }); - - it('should reset modal title', () => { - expect(stateCopy.modal.title).toEqual(null); - }); - - it('should reset modal data', () => { - expect(stateCopy.modal.data.execution_time.value).toEqual(null); - expect(stateCopy.modal.data.system_output.value).toEqual(null); - }); - - it('should close modal', () => { - expect(stateCopy.modal.open).toEqual(false); - }); - }); -}); diff --git a/spec/frontend/reports/grouped_test_report/store/utils_spec.js b/spec/frontend/reports/grouped_test_report/store/utils_spec.js deleted file mode 100644 index 760afe1c11a..00000000000 --- a/spec/frontend/reports/grouped_test_report/store/utils_spec.js +++ /dev/null @@ -1,255 +0,0 @@ -import { - STATUS_FAILED, - STATUS_SUCCESS, - ICON_WARNING, - ICON_SUCCESS, - ICON_NOTFOUND, -} from '~/reports/constants'; -import * as utils from '~/reports/grouped_test_report/store/utils'; - -describe('Reports store utils', () => { - describe('summaryTextbuilder', () => { - it('should render text for no changed results in multiple tests', () => { - const name = 'Test summary'; - const data = { total: 10 }; - const result = utils.summaryTextBuilder(name, data); - - expect(result).toBe('Test summary contained no changed test results out of 10 total tests'); - }); - - it('should render text for no changed results in one test', () => { - const name = 'Test summary'; - const data = { total: 1 }; - const result = utils.summaryTextBuilder(name, data); - - expect(result).toBe('Test summary contained no changed test results out of 1 total test'); - }); - - it('should render text for multiple failed results', () => { - const name = 'Test summary'; - const data = { failed: 3, total: 10 }; - const result = utils.summaryTextBuilder(name, data); - - expect(result).toBe('Test summary contained 3 failed out of 10 total tests'); - }); - - it('should render text for multiple errored results', () => { - const name = 'Test summary'; - const data = { errored: 7, total: 10 }; - const result = utils.summaryTextBuilder(name, data); - - expect(result).toBe('Test summary contained 7 errors out of 10 total tests'); - }); - - it('should render text for multiple fixed results', () => { - const name = 'Test summary'; - const data = { resolved: 4, total: 10 }; - const result = utils.summaryTextBuilder(name, data); - - expect(result).toBe('Test summary contained 4 fixed test results out of 10 total tests'); - }); - - it('should render text for multiple fixed, and multiple failed results', () => { - const name = 'Test summary'; - const data = { failed: 3, resolved: 4, total: 10 }; - const result = utils.summaryTextBuilder(name, data); - - expect(result).toBe( - 'Test summary contained 3 failed and 4 fixed test results out of 10 total tests', - ); - }); - - it('should render text for a singular fixed, and a singular failed result', () => { - const name = 'Test summary'; - const data = { failed: 1, resolved: 1, total: 10 }; - const result = utils.summaryTextBuilder(name, data); - - expect(result).toBe( - 'Test summary contained 1 failed and 1 fixed test result out of 10 total tests', - ); - }); - - it('should render text for singular failed, errored, and fixed results', () => { - const name = 'Test summary'; - const data = { failed: 1, errored: 1, resolved: 1, total: 10 }; - const result = utils.summaryTextBuilder(name, data); - - expect(result).toBe( - 'Test summary contained 1 failed, 1 error and 1 fixed test result out of 10 total tests', - ); - }); - - it('should render text for multiple failed, errored, and fixed results', () => { - const name = 'Test summary'; - const data = { failed: 2, errored: 3, resolved: 4, total: 10 }; - const result = utils.summaryTextBuilder(name, data); - - expect(result).toBe( - 'Test summary contained 2 failed, 3 errors and 4 fixed test results out of 10 total tests', - ); - }); - }); - - describe('reportTextBuilder', () => { - it('should render text for no changed results in multiple tests', () => { - const name = 'Rspec'; - const data = { total: 10 }; - const result = utils.reportTextBuilder(name, data); - - expect(result).toBe('Rspec found no changed test results out of 10 total tests'); - }); - - it('should render text for no changed results in one test', () => { - const name = 'Rspec'; - const data = { total: 1 }; - const result = utils.reportTextBuilder(name, data); - - expect(result).toBe('Rspec found no changed test results out of 1 total test'); - }); - - it('should render text for multiple failed results', () => { - const name = 'Rspec'; - const data = { failed: 3, total: 10 }; - const result = utils.reportTextBuilder(name, data); - - expect(result).toBe('Rspec found 3 failed out of 10 total tests'); - }); - - it('should render text for multiple errored results', () => { - const name = 'Rspec'; - const data = { errored: 7, total: 10 }; - const result = utils.reportTextBuilder(name, data); - - expect(result).toBe('Rspec found 7 errors out of 10 total tests'); - }); - - it('should render text for multiple fixed results', () => { - const name = 'Rspec'; - const data = { resolved: 4, total: 10 }; - const result = utils.reportTextBuilder(name, data); - - expect(result).toBe('Rspec found 4 fixed test results out of 10 total tests'); - }); - - it('should render text for multiple fixed, and multiple failed results', () => { - const name = 'Rspec'; - const data = { failed: 3, resolved: 4, total: 10 }; - const result = utils.reportTextBuilder(name, data); - - expect(result).toBe('Rspec found 3 failed and 4 fixed test results out of 10 total tests'); - }); - - it('should render text for a singular fixed, and a singular failed result', () => { - const name = 'Rspec'; - const data = { failed: 1, resolved: 1, total: 10 }; - const result = utils.reportTextBuilder(name, data); - - expect(result).toBe('Rspec found 1 failed and 1 fixed test result out of 10 total tests'); - }); - - it('should render text for singular failed, errored, and fixed results', () => { - const name = 'Rspec'; - const data = { failed: 1, errored: 1, resolved: 1, total: 10 }; - const result = utils.reportTextBuilder(name, data); - - expect(result).toBe( - 'Rspec found 1 failed, 1 error and 1 fixed test result out of 10 total tests', - ); - }); - - it('should render text for multiple failed, errored, and fixed results', () => { - const name = 'Rspec'; - const data = { failed: 2, errored: 3, resolved: 4, total: 10 }; - const result = utils.reportTextBuilder(name, data); - - expect(result).toBe( - 'Rspec found 2 failed, 3 errors and 4 fixed test results out of 10 total tests', - ); - }); - }); - - describe('recentFailuresTextBuilder', () => { - it.each` - recentlyFailed | failed | expected - ${0} | ${1} | ${''} - ${1} | ${1} | ${'1 out of 1 failed test has failed more than once in the last 14 days'} - ${1} | ${2} | ${'1 out of 2 failed tests has failed more than once in the last 14 days'} - ${2} | ${3} | ${'2 out of 3 failed tests have failed more than once in the last 14 days'} - `( - 'should render summary for $recentlyFailed out of $failed failures', - ({ recentlyFailed, failed, expected }) => { - const result = utils.recentFailuresTextBuilder({ recentlyFailed, failed }); - - expect(result).toBe(expected); - }, - ); - }); - - describe('countRecentlyFailedTests', () => { - it('counts tests with more than one recent failure in a report', () => { - const report = { - new_failures: [{ recent_failures: { count: 2 } }], - existing_failures: [{ recent_failures: { count: 1 } }], - resolved_failures: [{ recent_failures: { count: 20 } }, { recent_failures: { count: 5 } }], - }; - const result = utils.countRecentlyFailedTests(report); - - expect(result).toBe(3); - }); - - it('counts tests with more than one recent failure in an array of reports', () => { - const reports = [ - { - new_failures: [{ recent_failures: { count: 2 } }], - existing_failures: [ - { recent_failures: { count: 20 } }, - { recent_failures: { count: 5 } }, - ], - resolved_failures: [{ recent_failures: { count: 2 } }], - }, - { - new_failures: [{ recent_failures: { count: 8 } }, { recent_failures: { count: 14 } }], - existing_failures: [{ recent_failures: { count: 1 } }], - resolved_failures: [{ recent_failures: { count: 7 } }, { recent_failures: { count: 5 } }], - }, - ]; - const result = utils.countRecentlyFailedTests(reports); - - expect(result).toBe(8); - }); - }); - - describe('statusIcon', () => { - describe('with failed status', () => { - it('returns ICON_WARNING', () => { - expect(utils.statusIcon(STATUS_FAILED)).toEqual(ICON_WARNING); - }); - }); - - describe('with success status', () => { - it('returns ICON_SUCCESS', () => { - expect(utils.statusIcon(STATUS_SUCCESS)).toEqual(ICON_SUCCESS); - }); - }); - - describe('without a status', () => { - it('returns ICON_NOTFOUND', () => { - expect(utils.statusIcon()).toEqual(ICON_NOTFOUND); - }); - }); - }); - - describe('formatFilePath', () => { - it.each` - file | expected - ${'./test.js'} | ${'test.js'} - ${'/test.js'} | ${'test.js'} - ${'.//////////////test.js'} | ${'test.js'} - ${'test.js'} | ${'test.js'} - ${'mock/path./test.js'} | ${'mock/path./test.js'} - ${'./mock/path./test.js'} | ${'mock/path./test.js'} - `('should format $file to be $expected', ({ file, expected }) => { - expect(utils.formatFilePath(file)).toBe(expected); - }); - }); -}); |