diff options
Diffstat (limited to 'spec/frontend/reports/store')
-rw-r--r-- | spec/frontend/reports/store/actions_spec.js | 171 | ||||
-rw-r--r-- | spec/frontend/reports/store/mutations_spec.js | 158 | ||||
-rw-r--r-- | spec/frontend/reports/store/utils_spec.js | 241 |
3 files changed, 0 insertions, 570 deletions
diff --git a/spec/frontend/reports/store/actions_spec.js b/spec/frontend/reports/store/actions_spec.js deleted file mode 100644 index 25c3105466f..00000000000 --- a/spec/frontend/reports/store/actions_spec.js +++ /dev/null @@ -1,171 +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 { - setEndpoint, - requestReports, - fetchReports, - stopPolling, - clearEtagPoll, - receiveReportsSuccess, - receiveReportsError, - openModal, - closeModal, -} from '~/reports/store/actions'; -import * as types from '~/reports/store/mutation_types'; -import state from '~/reports/store/state'; - -describe('Reports Store Actions', () => { - let mockedState; - - beforeEach(() => { - mockedState = state(); - }); - - describe('setEndpoint', () => { - it('should commit SET_ENDPOINT mutation', (done) => { - testAction( - setEndpoint, - 'endpoint.json', - mockedState, - [{ type: types.SET_ENDPOINT, payload: 'endpoint.json' }], - [], - done, - ); - }); - }); - - describe('requestReports', () => { - it('should commit REQUEST_REPORTS mutation', (done) => { - testAction(requestReports, null, mockedState, [{ type: types.REQUEST_REPORTS }], [], done); - }); - }); - - 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 ', (done) => { - mock - .onGet(`${TEST_HOST}/endpoint.json`) - .replyOnce(200, { summary: {}, suites: [{ name: 'rspec' }] }); - - testAction( - fetchReports, - null, - mockedState, - [], - [ - { - type: 'requestReports', - }, - { - payload: { data: { summary: {}, suites: [{ name: 'rspec' }] }, status: 200 }, - type: 'receiveReportsSuccess', - }, - ], - done, - ); - }); - }); - - describe('error', () => { - beforeEach(() => { - mock.onGet(`${TEST_HOST}/endpoint.json`).reply(500); - }); - - it('dispatches requestReports and receiveReportsError ', (done) => { - testAction( - fetchReports, - null, - mockedState, - [], - [ - { - type: 'requestReports', - }, - { - type: 'receiveReportsError', - }, - ], - done, - ); - }); - }); - }); - - describe('receiveReportsSuccess', () => { - it('should commit RECEIVE_REPORTS_SUCCESS mutation with 200', (done) => { - testAction( - receiveReportsSuccess, - { data: { summary: {} }, status: 200 }, - mockedState, - [{ type: types.RECEIVE_REPORTS_SUCCESS, payload: { summary: {} } }], - [], - done, - ); - }); - - it('should not commit RECEIVE_REPORTS_SUCCESS mutation with 204', (done) => { - testAction( - receiveReportsSuccess, - { data: { summary: {} }, status: 204 }, - mockedState, - [], - [], - done, - ); - }); - }); - - describe('receiveReportsError', () => { - it('should commit RECEIVE_REPORTS_ERROR mutation', (done) => { - testAction( - receiveReportsError, - null, - mockedState, - [{ type: types.RECEIVE_REPORTS_ERROR }], - [], - done, - ); - }); - }); - - describe('openModal', () => { - it('should commit SET_ISSUE_MODAL_DATA', (done) => { - testAction( - openModal, - { name: 'foo' }, - mockedState, - [{ type: types.SET_ISSUE_MODAL_DATA, payload: { name: 'foo' } }], - [], - done, - ); - }); - }); - - describe('closeModal', () => { - it('should commit RESET_ISSUE_MODAL_DATA', (done) => { - testAction( - closeModal, - {}, - mockedState, - [{ type: types.RESET_ISSUE_MODAL_DATA, payload: {} }], - [], - done, - ); - }); - }); -}); diff --git a/spec/frontend/reports/store/mutations_spec.js b/spec/frontend/reports/store/mutations_spec.js deleted file mode 100644 index 652b3b0ec45..00000000000 --- a/spec/frontend/reports/store/mutations_spec.js +++ /dev/null @@ -1,158 +0,0 @@ -import * as types from '~/reports/store/mutation_types'; -import mutations from '~/reports/store/mutations'; -import state from '~/reports/store/state'; -import { issue } from '../mock_data/mock_data'; - -describe('Reports Store Mutations', () => { - let stateCopy; - - beforeEach(() => { - stateCopy = state(); - }); - - describe('SET_ENDPOINT', () => { - it('should set endpoint', () => { - mutations[types.SET_ENDPOINT](stateCopy, 'endpoint.json'); - - expect(stateCopy.endpoint).toEqual('endpoint.json'); - }); - }); - - 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: 'master', - }, - }, - ], - 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, - }); - }); - - it('should set modal title', () => { - expect(stateCopy.modal.title).toEqual(issue.name); - }); - - it('should set modal data', () => { - expect(stateCopy.modal.data.execution_time.value).toEqual(issue.execution_time); - expect(stateCopy.modal.data.system_output.value).toEqual(issue.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, - }); - - 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/store/utils_spec.js b/spec/frontend/reports/store/utils_spec.js deleted file mode 100644 index cbc87bbb5ec..00000000000 --- a/spec/frontend/reports/store/utils_spec.js +++ /dev/null @@ -1,241 +0,0 @@ -import { - STATUS_FAILED, - STATUS_SUCCESS, - ICON_WARNING, - ICON_SUCCESS, - ICON_NOTFOUND, -} from '~/reports/constants'; -import * as utils from '~/reports/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); - }); - }); - }); -}); |