Commit 83f5ba73 authored by Scott Hampton's avatar Scott Hampton

Refactor injected props

Refactor provide/inject data to not use
"type" property. Also switched the help
page data to using to the help page helper.

Also updated tests to be more clear.
parent 6dd5f240
<script> <script>
import { GlEmptyState } from '@gitlab/ui'; import { GlEmptyState } from '@gitlab/ui';
import { helpPagePath } from '~/helpers/help_page_helper';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
export const i18n = { export const i18n = {
...@@ -20,17 +21,11 @@ export default { ...@@ -20,17 +21,11 @@ export default {
}, },
inject: { inject: {
emptyStateImagePath: { emptyStateImagePath: {
type: String,
default: '', default: '',
}, },
hasTestReport: { hasTestReport: {
type: Boolean,
default: false, default: false,
}, },
testReportDocPath: {
type: String,
default: '',
},
}, },
computed: { computed: {
emptyStateText() { emptyStateText() {
...@@ -47,6 +42,9 @@ export default { ...@@ -47,6 +42,9 @@ export default {
title: this.$options.i18n.noReportsTitle, title: this.$options.i18n.noReportsTitle,
}; };
}, },
testReportDocPath() {
return helpPagePath('ci/unit_test_reports');
},
}, },
}; };
</script> </script>
......
...@@ -17,7 +17,6 @@ export default { ...@@ -17,7 +17,6 @@ export default {
}, },
inject: { inject: {
hasTestReport: { hasTestReport: {
type: Boolean,
default: false, default: false,
}, },
}, },
......
import Vue from 'vue'; import Vue from 'vue';
import { deprecatedCreateFlash as Flash } from '~/flash'; import { deprecatedCreateFlash as Flash } from '~/flash';
import { parseBoolean } from '~/lib/utils/common_utils';
import { __ } from '~/locale'; import { __ } from '~/locale';
import Translate from '~/vue_shared/translate'; import Translate from '~/vue_shared/translate';
import PipelineGraphLegacy from './components/graph/graph_component_legacy.vue'; import PipelineGraphLegacy from './components/graph/graph_component_legacy.vue';
...@@ -63,14 +64,8 @@ const createLegacyPipelinesDetailApp = (mediator) => { ...@@ -63,14 +64,8 @@ const createLegacyPipelinesDetailApp = (mediator) => {
const createTestDetails = () => { const createTestDetails = () => {
const el = document.querySelector(SELECTORS.PIPELINE_TESTS); const el = document.querySelector(SELECTORS.PIPELINE_TESTS);
const { const { blobPath, emptyStateImagePath, hasTestReport, summaryEndpoint, suiteEndpoint } =
blobPath, el?.dataset || {};
emptyStateImagePath,
hasTestReport,
summaryEndpoint,
suiteEndpoint,
testReportDocPath,
} = el?.dataset || {};
const testReportsStore = createTestReportsStore({ const testReportsStore = createTestReportsStore({
blobPath, blobPath,
summaryEndpoint, summaryEndpoint,
...@@ -85,8 +80,7 @@ const createTestDetails = () => { ...@@ -85,8 +80,7 @@ const createTestDetails = () => {
}, },
provide: { provide: {
emptyStateImagePath, emptyStateImagePath,
hasTestReport: hasTestReport !== undefined, // if hasTestReport is false that means the attribute isn't included hasTestReport: parseBoolean(hasTestReport),
testReportDocPath,
}, },
store: testReportsStore, store: testReportsStore,
render(createElement) { render(createElement) {
......
...@@ -84,7 +84,6 @@ ...@@ -84,7 +84,6 @@
#js-pipeline-tests-detail{ data: { summary_endpoint: summary_project_pipeline_tests_path(@project, @pipeline, format: :json), #js-pipeline-tests-detail{ data: { summary_endpoint: summary_project_pipeline_tests_path(@project, @pipeline, format: :json),
suite_endpoint: project_pipeline_test_path(@project, @pipeline, suite_name: 'suite', format: :json), suite_endpoint: project_pipeline_test_path(@project, @pipeline, suite_name: 'suite', format: :json),
blob_path: project_blob_path(@project, @pipeline.sha), blob_path: project_blob_path(@project, @pipeline.sha),
has_test_report: @pipeline.has_reports?(Ci::JobArtifact.test_reports), has_test_report: @pipeline.has_reports?(Ci::JobArtifact.test_reports).to_s,
test_report_doc_path: help_page_path('ci/unit_test_reports'),
empty_state_image_path: image_path('illustrations/empty-state/empty-test-cases-lg.svg') } } empty_state_image_path: image_path('illustrations/empty-state/empty-test-cases-lg.svg') } }
= render_if_exists "projects/pipelines/tabs_content", pipeline: @pipeline, project: @project = render_if_exists "projects/pipelines/tabs_content", pipeline: @pipeline, project: @project
...@@ -7,12 +7,11 @@ describe('Test report empty state', () => { ...@@ -7,12 +7,11 @@ describe('Test report empty state', () => {
const findEmptyState = () => wrapper.findComponent(GlEmptyState); const findEmptyState = () => wrapper.findComponent(GlEmptyState);
const createComponent = (hasTestReport = true) => { const createComponent = ({ hasTestReport = true } = {}) => {
wrapper = shallowMount(EmptyState, { wrapper = shallowMount(EmptyState, {
provide: { provide: {
emptyStateImagePath: '/image/path', emptyStateImagePath: '/image/path',
hasTestReport, hasTestReport,
testReportDocPath: '/docs/path',
}, },
stubs: { stubs: {
GlEmptyState, GlEmptyState,
...@@ -34,7 +33,7 @@ describe('Test report empty state', () => { ...@@ -34,7 +33,7 @@ describe('Test report empty state', () => {
describe('when pipeline does not have a test report', () => { describe('when pipeline does not have a test report', () => {
it('should render no test report message', () => { it('should render no test report message', () => {
createComponent(false); createComponent({ hasTestReport: false });
expect(findEmptyState().props()).toMatchObject({ expect(findEmptyState().props()).toMatchObject({
primaryButtonText: i18n.noReportsButton, primaryButtonText: i18n.noReportsButton,
......
...@@ -31,7 +31,7 @@ describe('Test reports app', () => { ...@@ -31,7 +31,7 @@ describe('Test reports app', () => {
removeSelectedSuiteIndex: jest.fn(), removeSelectedSuiteIndex: jest.fn(),
}; };
const createComponent = (state = {}, hasTestReport = true) => { const createComponent = ({ state = {}, hasTestReport = true } = {}) => {
store = new Vuex.Store({ store = new Vuex.Store({
state: { state: {
isLoading: false, isLoading: false,
...@@ -66,14 +66,14 @@ describe('Test reports app', () => { ...@@ -66,14 +66,14 @@ describe('Test reports app', () => {
}); });
it('should not call fetchSummary when pipeline does not have test report', () => { it('should not call fetchSummary when pipeline does not have test report', () => {
createComponent({}, false); createComponent({ state: {}, hasTestReport: false });
expect(actionSpies.fetchSummary).not.toHaveBeenCalled(); expect(actionSpies.fetchSummary).not.toHaveBeenCalled();
}); });
}); });
describe('when loading', () => { describe('when loading', () => {
beforeEach(() => createComponent({ isLoading: true })); beforeEach(() => createComponent({ state: { isLoading: true } }));
it('shows the loading spinner', () => { it('shows the loading spinner', () => {
expect(emptyState().exists()).toBe(false); expect(emptyState().exists()).toBe(false);
...@@ -84,7 +84,7 @@ describe('Test reports app', () => { ...@@ -84,7 +84,7 @@ describe('Test reports app', () => {
describe('when the api returns no data', () => { describe('when the api returns no data', () => {
it('displays empty state component', () => { it('displays empty state component', () => {
createComponent({ testReports: {} }); createComponent({ state: { testReports: {} } });
expect(emptyState().exists()).toBe(true); expect(emptyState().exists()).toBe(true);
}); });
...@@ -105,7 +105,7 @@ describe('Test reports app', () => { ...@@ -105,7 +105,7 @@ describe('Test reports app', () => {
describe('when a suite is clicked', () => { describe('when a suite is clicked', () => {
beforeEach(() => { beforeEach(() => {
createComponent({ hasFullReport: true }); createComponent({ state: { hasFullReport: true } });
testSummaryTable().vm.$emit('row-click', 0); testSummaryTable().vm.$emit('row-click', 0);
}); });
...@@ -117,7 +117,7 @@ describe('Test reports app', () => { ...@@ -117,7 +117,7 @@ describe('Test reports app', () => {
describe('when clicking back to summary', () => { describe('when clicking back to summary', () => {
beforeEach(() => { beforeEach(() => {
createComponent({ selectedSuiteIndex: 0 }); createComponent({ state: { selectedSuiteIndex: 0 } });
testSummary().vm.$emit('on-back-click'); testSummary().vm.$emit('on-back-click');
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment