Commit bd98909c authored by Martin Wortschack's avatar Martin Wortschack 🐻 Committed by Filipa Lacerda

Properly set the path for milestones and labels

- Move to utils and add spec
parent b2c666ff
import Vue from 'vue';
import Api from '~/api';
import store from './store';
import FilterDropdowns from './components/filter_dropdowns.vue';
import TimeFrameDropdown from './components/timeframe_dropdown.vue';
import ProductivityAnalyticsApp from './components/app.vue';
import FilteredSearchProductivityAnalytics from './filtered_search_productivity_analytics';
import { getLabelsEndpoint, getMilestonesEndpoint } from './utils';
export default () => {
const container = document.getElementById('js-productivity-analytics');
......@@ -41,8 +41,8 @@ export default () => {
searchBarContainer.classList.remove('hide');
const filteredSearchInput = searchBarContainer.querySelector('.filtered-search');
const labelsEndpoint = this.getLabelsEndpoint(groupNamespace, projectNamespace);
const milestonesEndpoint = this.getMilestonesEndpoint(groupNamespace, projectNamespace);
const labelsEndpoint = getLabelsEndpoint(groupNamespace, projectNamespace);
const milestonesEndpoint = getMilestonesEndpoint(groupNamespace, projectNamespace);
filteredSearchInput.setAttribute('data-group-id', groupId);
......@@ -55,22 +55,6 @@ export default () => {
filterManager = new FilteredSearchProductivityAnalytics({ isGroup: false });
filterManager.setup();
},
getLabelsEndpoint(namespacePath, projectPath) {
if (projectPath) {
return Api.buildUrl(Api.projectLabelsPath)
.replace(':namespace_path', namespacePath)
.replace(':project_path', projectPath);
}
return Api.buildUrl(Api.groupLabelsPath).replace(':namespace_path', namespacePath);
},
getMilestonesEndpoint(namespacePath, projectPath) {
if (projectPath) {
return `/${namespacePath}/${projectPath}/-/milestones`;
}
return `/groups/${namespacePath}/-/milestones`;
},
},
render(h) {
return h(FilterDropdowns, {
......
export const getLabelsEndpoint = (namespacePath, projectPathWithNamespace) => {
if (projectPathWithNamespace) {
return `/${projectPathWithNamespace}/-/labels`;
}
return `/groups/${namespacePath}/-/labels`;
};
export const getMilestonesEndpoint = (namespacePath, projectPathWithNamespace) => {
if (projectPathWithNamespace) {
return `/${projectPathWithNamespace}/-/milestones`;
}
return `/groups/${namespacePath}/-/milestones`;
};
import {
getLabelsEndpoint,
getMilestonesEndpoint,
} from 'ee/analytics/productivity_analytics/utils';
describe('Productivity Analytics utils', () => {
const namespacePath = 'gitlab-org';
const projectWithNamespace = 'gitlab-org/gitlab-test';
describe('getLabelsEndpoint', () => {
it('returns the group labels path when no project is given', () => {
expect(getLabelsEndpoint(namespacePath)).toBe('/groups/gitlab-org/-/labels');
});
it('returns the project labels path when a project is given', () => {
expect(getLabelsEndpoint(namespacePath, projectWithNamespace)).toBe(
'/gitlab-org/gitlab-test/-/labels',
);
});
});
describe('getMilestonesEndpoint', () => {
it('returns the group milestone path when no project is given', () => {
expect(getMilestonesEndpoint(namespacePath)).toBe('/groups/gitlab-org/-/milestones');
});
it('returns the project milestone path when a project is given', () => {
expect(getMilestonesEndpoint(namespacePath, projectWithNamespace)).toBe(
'/gitlab-org/gitlab-test/-/milestones',
);
});
});
});
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