diff options
Diffstat (limited to 'spec/frontend/pipelines/test_reports/stores')
3 files changed, 90 insertions, 6 deletions
diff --git a/spec/frontend/pipelines/test_reports/stores/actions_spec.js b/spec/frontend/pipelines/test_reports/stores/actions_spec.js index f7ff36c0a46..6258b08dfbb 100644 --- a/spec/frontend/pipelines/test_reports/stores/actions_spec.js +++ b/spec/frontend/pipelines/test_reports/stores/actions_spec.js @@ -2,10 +2,10 @@ import MockAdapter from 'axios-mock-adapter'; import { getJSONFixture } from 'helpers/fixtures'; import { TEST_HOST } from 'helpers/test_constants'; import testAction from 'helpers/vuex_action_helper'; +import { deprecatedCreateFlash as createFlash } from '~/flash'; import axios from '~/lib/utils/axios_utils'; import * as actions from '~/pipelines/stores/test_reports/actions'; import * as types from '~/pipelines/stores/test_reports/mutation_types'; -import { deprecatedCreateFlash as createFlash } from '~/flash'; jest.mock('~/flash.js'); @@ -16,7 +16,7 @@ describe('Actions TestReports Store', () => { const testReports = getJSONFixture('pipelines/test_report.json'); const summary = { total_count: 1 }; - const suiteEndpoint = `${TEST_HOST}/tests/:suite_name.json`; + const suiteEndpoint = `${TEST_HOST}/tests/suite.json`; const summaryEndpoint = `${TEST_HOST}/test_reports/summary.json`; const defaultState = { suiteEndpoint, @@ -69,9 +69,8 @@ describe('Actions TestReports Store', () => { beforeEach(() => { const buildIds = [1]; testReports.test_suites[0].build_ids = buildIds; - const endpoint = suiteEndpoint.replace(':suite_name', testReports.test_suites[0].name); mock - .onGet(endpoint, { params: { build_ids: buildIds } }) + .onGet(suiteEndpoint, { params: { build_ids: buildIds } }) .replyOnce(200, testReports.test_suites[0], {}); }); diff --git a/spec/frontend/pipelines/test_reports/stores/getters_spec.js b/spec/frontend/pipelines/test_reports/stores/getters_spec.js index 7382a6beefa..f8298fdaba5 100644 --- a/spec/frontend/pipelines/test_reports/stores/getters_spec.js +++ b/spec/frontend/pipelines/test_reports/stores/getters_spec.js @@ -1,6 +1,10 @@ import { getJSONFixture } from 'helpers/fixtures'; import * as getters from '~/pipelines/stores/test_reports/getters'; -import { iconForTestStatus, formattedTime } from '~/pipelines/stores/test_reports/utils'; +import { + iconForTestStatus, + formatFilePath, + formattedTime, +} from '~/pipelines/stores/test_reports/utils'; describe('Getters TestReports Store', () => { let state; @@ -8,6 +12,7 @@ describe('Getters TestReports Store', () => { const testReports = getJSONFixture('pipelines/test_report.json'); const defaultState = { + blobPath: '/test/blob/path', testReports, selectedSuiteIndex: 0, pageInfo: { @@ -17,6 +22,7 @@ describe('Getters TestReports Store', () => { }; const emptyState = { + blobPath: '', testReports: {}, selectedSuite: null, pageInfo: { @@ -74,6 +80,7 @@ describe('Getters TestReports Store', () => { const expected = testReports.test_suites[0].test_cases .map((x) => ({ ...x, + filePath: `${state.blobPath}/${formatFilePath(x.file)}`, formattedTime: formattedTime(x.execution_time), icon: iconForTestStatus(x.status), })) @@ -87,6 +94,70 @@ describe('Getters TestReports Store', () => { expect(getters.getSuiteTests(state)).toEqual([]); }); + + describe('when a test case classname property is null', () => { + it('should return an empty string value for the classname property', () => { + const testCases = testReports.test_suites[0].test_cases; + setupState({ + ...defaultState, + testReports: { + ...testReports, + test_suites: [ + { + test_cases: testCases.map((testCase) => ({ + ...testCase, + classname: null, + })), + }, + ], + }, + }); + + const expected = testCases + .map((x) => ({ + ...x, + classname: '', + filePath: `${state.blobPath}/${formatFilePath(x.file)}`, + formattedTime: formattedTime(x.execution_time), + icon: iconForTestStatus(x.status), + })) + .slice(0, state.pageInfo.perPage); + + expect(getters.getSuiteTests(state)).toEqual(expected); + }); + }); + + describe('when a test case name property is null', () => { + it('should return an empty string value for the name property', () => { + const testCases = testReports.test_suites[0].test_cases; + setupState({ + ...defaultState, + testReports: { + ...testReports, + test_suites: [ + { + test_cases: testCases.map((testCase) => ({ + ...testCase, + name: null, + })), + }, + ], + }, + }); + + const expected = testCases + .map((x) => ({ + ...x, + name: '', + filePath: `${state.blobPath}/${formatFilePath(x.file)}`, + formattedTime: formattedTime(x.execution_time), + icon: iconForTestStatus(x.status), + })) + .slice(0, state.pageInfo.perPage); + + expect(getters.getSuiteTests(state)).toEqual(expected); + }); + }); }); describe('getSuiteTestCount', () => { diff --git a/spec/frontend/pipelines/test_reports/stores/utils_spec.js b/spec/frontend/pipelines/test_reports/stores/utils_spec.js index 7e632d099fc..703fe69026c 100644 --- a/spec/frontend/pipelines/test_reports/stores/utils_spec.js +++ b/spec/frontend/pipelines/test_reports/stores/utils_spec.js @@ -1,6 +1,20 @@ -import { formattedTime } from '~/pipelines/stores/test_reports/utils'; +import { formatFilePath, formattedTime } from '~/pipelines/stores/test_reports/utils'; describe('Test reports utils', () => { + 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(formatFilePath(file)).toBe(expected); + }); + }); + describe('formattedTime', () => { describe('when time is smaller than a second', () => { it('should return time in milliseconds fixed to 2 decimals', () => { |