Commit 3c7604ce authored by Mark Florian's avatar Mark Florian

Use correct endpoint to download Dependency List

This ensures the endpoint receives a request for a JSON formatted
response. Previously, no format was specified, so the endpoint was not
returning the correct response.
parent 0c8f1ccf
<script> <script>
import { mapActions, mapState } from 'vuex'; import { mapActions, mapGetters, mapState } from 'vuex';
import { GlButton, GlDropdown, GlDropdownItem, GlTooltipDirective } from '@gitlab/ui'; import { GlButton, GlDropdown, GlDropdownItem, GlTooltipDirective } from '@gitlab/ui';
import Icon from '~/vue_shared/components/icon.vue'; import Icon from '~/vue_shared/components/icon.vue';
import { SORT_ORDER } from '../store/constants'; import { SORT_ORDER } from '../store/constants';
...@@ -16,7 +16,8 @@ export default { ...@@ -16,7 +16,8 @@ export default {
GlTooltip: GlTooltipDirective, GlTooltip: GlTooltipDirective,
}, },
computed: { computed: {
...mapState(['endpoint', 'sortField', 'sortFields', 'sortOrder']), ...mapState(['sortField', 'sortFields', 'sortOrder']),
...mapGetters(['downloadEndpoint']),
sortFieldName() { sortFieldName() {
return this.sortFields[this.sortField]; return this.sortFields[this.sortField];
}, },
...@@ -59,7 +60,7 @@ export default { ...@@ -59,7 +60,7 @@ export default {
</div> </div>
<gl-button <gl-button
v-gl-tooltip v-gl-tooltip
:href="endpoint" :href="downloadEndpoint"
download="dependencies.json" download="dependencies.json"
:title="s__('Dependencies|Export as JSON')" :title="s__('Dependencies|Export as JSON')"
class="js-download" class="js-download"
......
...@@ -4,3 +4,5 @@ export const isJobNotSetUp = state => state.reportInfo.status === REPORT_STATUS. ...@@ -4,3 +4,5 @@ export const isJobNotSetUp = state => state.reportInfo.status === REPORT_STATUS.
export const isJobFailed = state => export const isJobFailed = state =>
[REPORT_STATUS.jobFailed, REPORT_STATUS.noDependencies].includes(state.reportInfo.status); [REPORT_STATUS.jobFailed, REPORT_STATUS.noDependencies].includes(state.reportInfo.status);
export const isIncomplete = state => state.reportInfo.status === REPORT_STATUS.incomplete; export const isIncomplete = state => state.reportInfo.status === REPORT_STATUS.incomplete;
export const downloadEndpoint = ({ endpoint }) => `${endpoint}.json`;
...@@ -61,7 +61,7 @@ exports[`DependenciesActions component matches the snapshot 1`] = ` ...@@ -61,7 +61,7 @@ exports[`DependenciesActions component matches the snapshot 1`] = `
class="js-download" class="js-download"
data-original-title="Export as JSON" data-original-title="Export as JSON"
download="dependencies.json" download="dependencies.json"
href="" href="http://test.host/dependencies.json"
title="" title=""
> >
<icon-stub <icon-stub
......
...@@ -13,7 +13,7 @@ describe('DependenciesActions component', () => { ...@@ -13,7 +13,7 @@ describe('DependenciesActions component', () => {
const localVue = createLocalVue(); const localVue = createLocalVue();
store = createStore(); store = createStore();
jest.spyOn(store, 'dispatch'); jest.spyOn(store, 'dispatch').mockImplementation();
wrapper = shallowMount(localVue.extend(DependenciesActions), { wrapper = shallowMount(localVue.extend(DependenciesActions), {
localVue, localVue,
...@@ -24,6 +24,8 @@ describe('DependenciesActions component', () => { ...@@ -24,6 +24,8 @@ describe('DependenciesActions component', () => {
beforeEach(() => { beforeEach(() => {
factory(); factory();
store.state.endpoint = `${TEST_HOST}/dependencies`;
return wrapper.vm.$nextTick();
}); });
afterEach(() => { afterEach(() => {
...@@ -54,20 +56,13 @@ describe('DependenciesActions component', () => { ...@@ -54,20 +56,13 @@ describe('DependenciesActions component', () => {
expect(store.dispatch).toHaveBeenCalledWith('toggleSortOrder'); expect(store.dispatch).toHaveBeenCalledWith('toggleSortOrder');
}); });
describe('given an endpoint', () => { it('has a button to export the dependency list', () => {
beforeEach(() => { const download = wrapper.find('.js-download');
store.state.endpoint = `${TEST_HOST}/dependencies`; expect(download.attributes()).toEqual(
return wrapper.vm.$nextTick(); expect.objectContaining({
}); href: store.getters.downloadEndpoint,
download: expect.any(String),
it('has a button to export the dependency list', () => { }),
const download = wrapper.find('.js-download'); );
expect(download.attributes()).toEqual(
expect.objectContaining({
href: store.state.endpoint,
download: expect.any(String),
}),
);
});
}); });
}); });
import { TEST_HOST } from 'helpers/test_constants';
import * as getters from 'ee/dependencies/store/getters'; import * as getters from 'ee/dependencies/store/getters';
import { REPORT_STATUS } from 'ee/dependencies/store/constants'; import { REPORT_STATUS } from 'ee/dependencies/store/constants';
...@@ -22,4 +23,11 @@ describe('Dependencies getters', () => { ...@@ -22,4 +23,11 @@ describe('Dependencies getters', () => {
).toBe(outcome); ).toBe(outcome);
}); });
}); });
describe('downloadEndpoint', () => {
it('should return download endpoint', () => {
const endpoint = `${TEST_HOST}/dependencies`;
expect(getters.downloadEndpoint({ endpoint })).toBe(`${TEST_HOST}/dependencies.json`);
});
});
}); });
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