Commit 630cd0d3 authored by Jacques's avatar Jacques

Fix blob controls bug

Fixed incorrect controls bug in repo refactor
parent 7d3e3a44
...@@ -63,19 +63,25 @@ export default { ...@@ -63,19 +63,25 @@ export default {
}, },
computed: { computed: {
filePath() { filePath() {
const { path } = this.$route.params; return this.$route.params.path;
updateElementsVisibility('.tree-controls', !path); },
return path; showBlobControls() {
return this.filePath && this.$route.name === 'blobPathDecoded';
}, },
blobInfo() { blobInfo() {
return this.project?.repository?.blobs?.nodes[0] || {}; return this.project?.repository?.blobs?.nodes[0] || {};
}, },
}, },
watch: {
showBlobControls(shouldShow) {
updateElementsVisibility('.tree-controls', !shouldShow);
},
},
}; };
</script> </script>
<template> <template>
<div v-if="filePath"> <div v-if="showBlobControls">
<gl-button data-testid="find" :href="blobInfo.findFilePath" :class="$options.buttonClassList"> <gl-button data-testid="find" :href="blobInfo.findFilePath" :class="$options.buttonClassList">
{{ $options.i18n.findFile }} {{ $options.i18n.findFile }}
</gl-button> </gl-button>
......
...@@ -7,8 +7,11 @@ import BlobControls from '~/repository/components/blob_controls.vue'; ...@@ -7,8 +7,11 @@ import BlobControls from '~/repository/components/blob_controls.vue';
import blobControlsQuery from '~/repository/queries/blob_controls.query.graphql'; import blobControlsQuery from '~/repository/queries/blob_controls.query.graphql';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import createRouter from '~/repository/router'; import createRouter from '~/repository/router';
import { updateElementsVisibility } from '~/repository/utils/dom';
import { blobControlsDataMock, refMock } from '../mock_data'; import { blobControlsDataMock, refMock } from '../mock_data';
jest.mock('~/repository/utils/dom');
let router; let router;
let wrapper; let wrapper;
let mockResolver; let mockResolver;
...@@ -64,8 +67,14 @@ describe('Blob controls component', () => { ...@@ -64,8 +67,14 @@ describe('Blob controls component', () => {
expect(findPermalinkButton().attributes('href')).toBe('permalink/file.js'); expect(findPermalinkButton().attributes('href')).toBe('permalink/file.js');
}); });
it('does not render any buttons if no filePath is provided', async () => { it.each`
router.replace({ name: 'blobPath', params: { path: null } }); name | path
${'blobPathDecoded'} | ${null}
${'treePathDecoded'} | ${'myFile.js'}
`(
'does not render any buttons if router name is $name and router path is $path',
async ({ name, path }) => {
router.replace({ name, params: { path } });
await nextTick(); await nextTick();
...@@ -73,5 +82,7 @@ describe('Blob controls component', () => { ...@@ -73,5 +82,7 @@ describe('Blob controls component', () => {
expect(findBlameButton().exists()).toBe(false); expect(findBlameButton().exists()).toBe(false);
expect(findHistoryButton().exists()).toBe(false); expect(findHistoryButton().exists()).toBe(false);
expect(findPermalinkButton().exists()).toBe(false); expect(findPermalinkButton().exists()).toBe(false);
}); expect(updateElementsVisibility).toHaveBeenCalledWith('.tree-controls', true);
},
);
}); });
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