Commit cfeaf97a authored by Samantha Ming's avatar Samantha Ming

Apply patch & modify tests

- Remove tooltip specs from components & revert back to original
- Add delete scenario in changed_file_icon_spec
parent 3b29870e
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
import FileRow from '~/vue_shared/components/file_row.vue'; import FileRow from '~/vue_shared/components/file_row.vue';
import FileRowStats from './file_row_stats.vue'; import FileRowStats from './file_row_stats.vue';
import ChangedFileIcon from '~/vue_shared/components/changed_file_icon.vue'; import ChangedFileIcon from '~/vue_shared/components/changed_file_icon.vue';
import { __ } from '~/locale';
export default { export default {
name: 'DiffFileRow', name: 'DiffFileRow',
...@@ -29,19 +28,6 @@ export default { ...@@ -29,19 +28,6 @@ export default {
showFileRowStats() { showFileRowStats() {
return !this.hideFileStats && this.file.type === 'blob'; return !this.hideFileStats && this.file.type === 'blob';
}, },
tooltipTitle() {
if (!this.file.changed) return undefined;
if (this.file.deleted) {
return __('Deleted');
}
if (this.file.tempFile) {
return __('Added');
}
return __('Modified');
},
}, },
}; };
</script> </script>
...@@ -49,6 +35,6 @@ export default { ...@@ -49,6 +35,6 @@ export default {
<template> <template>
<file-row :file="file" v-bind="$attrs" v-on="$listeners"> <file-row :file="file" v-bind="$attrs" v-on="$listeners">
<file-row-stats v-if="showFileRowStats" :file="file" class="mr-1" /> <file-row-stats v-if="showFileRowStats" :file="file" class="mr-1" />
<changed-file-icon :file="file" :size="16" :show-tooltip="true" :tooltip-title="tooltipTitle" /> <changed-file-icon :file="file" :size="16" :show-tooltip="true" />
</file-row> </file-row>
</template> </template>
<script> <script>
import { mapGetters } from 'vuex'; import { mapGetters } from 'vuex';
import { n__, __ } from '~/locale'; import { n__ } from '~/locale';
import tooltip from '~/vue_shared/directives/tooltip'; import tooltip from '~/vue_shared/directives/tooltip';
import Icon from '~/vue_shared/components/icon.vue'; import Icon from '~/vue_shared/components/icon.vue';
import ChangedFileIcon from '~/vue_shared/components/changed_file_icon.vue'; import ChangedFileIcon from '~/vue_shared/components/changed_file_icon.vue';
...@@ -60,11 +60,6 @@ export default { ...@@ -60,11 +60,6 @@ export default {
showChangedFileIcon() { showChangedFileIcon() {
return !this.isTree && this.isModified; return !this.isTree && this.isModified;
}, },
tooltipTitle() {
if (!this.file.changed) return undefined;
return this.file.tempFile ? __('Added') : __('Modified');
},
}, },
}; };
</script> </script>
...@@ -89,7 +84,6 @@ export default { ...@@ -89,7 +84,6 @@ export default {
:file="file" :file="file"
:show-tooltip="true" :show-tooltip="true"
:show-staged-icon="false" :show-staged-icon="false"
:tooltip-title="tooltipTitle"
/> />
<new-dropdown <new-dropdown
:type="file.type" :type="file.type"
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import { GlTooltipDirective } from '@gitlab/ui'; import { GlTooltipDirective } from '@gitlab/ui';
import Icon from '~/vue_shared/components/icon.vue'; import Icon from '~/vue_shared/components/icon.vue';
import { getCommitIconMap } from '~/ide/utils'; import { getCommitIconMap } from '~/ide/utils';
import { __ } from '~/locale';
export default { export default {
components: { components: {
...@@ -35,11 +36,6 @@ export default { ...@@ -35,11 +36,6 @@ export default {
required: false, required: false,
default: true, default: true,
}, },
tooltipTitle: {
type: String,
required: false,
default: null,
},
}, },
computed: { computed: {
changedIcon() { changedIcon() {
...@@ -52,10 +48,18 @@ export default { ...@@ -52,10 +48,18 @@ export default {
changedIconClass() { changedIconClass() {
return `${this.changedIcon} float-left d-block`; return `${this.changedIcon} float-left d-block`;
}, },
changedTooltipTitle() { tooltipTitle() {
if (!this.showTooltip) return undefined; if (!this.showTooltip) {
return undefined;
} else if (this.file.deleted) {
return __('Deleted');
} else if (this.file.tempFile) {
return __('Added');
} else if (this.file.changed) {
return __('Modified');
}
return this.tooltipTitle; return undefined;
}, },
showIcon() { showIcon() {
return ( return (
...@@ -73,7 +77,7 @@ export default { ...@@ -73,7 +77,7 @@ export default {
<template> <template>
<span <span
v-gl-tooltip.right v-gl-tooltip.right
:title="changedTooltipTitle" :title="tooltipTitle"
:class="{ 'ml-auto': isCentered }" :class="{ 'ml-auto': isCentered }"
class="file-changed-icon d-inline-block" class="file-changed-icon d-inline-block"
> >
......
...@@ -39,54 +39,21 @@ describe('Diff File Row component', () => { ...@@ -39,54 +39,21 @@ describe('Diff File Row component', () => {
); );
}); });
describe('ChangedFileIcon component', () => { it('renders ChangedFileIcon component', () => {
const fileObject = (file = {}) => { createComponent({
return { level: 4,
changed: true, file: {},
...file, hideFileStats: false,
}; showTooltip: true,
};
const componentProps = file => {
return {
level: 4,
file,
hideFileStats: false,
};
};
it('renders component with showTooltip', () => {
const file = fileObject();
createComponent(componentProps(file));
expect(wrapper.find(ChangedFileIcon).props()).toEqual(
expect.objectContaining({
file,
size: 16,
showTooltip: true,
}),
);
});
it.each`
message | file | desc
${'Deleted'} | ${'deleted'} | ${'shows "Deleted" tooltip if file has been deleted'}
${'Added'} | ${'tempFile'} | ${'shows "Added" tooltip if file has been added'}
`('$desc', ({ message, file }) => {
createComponent(
componentProps(
fileObject({
[file]: true,
}),
),
);
expect(wrapper.find(ChangedFileIcon).props('tooltipTitle')).toBe(message);
}); });
it('shows "Modified" tooltip if file has been modified', () => { expect(wrapper.find(ChangedFileIcon).props()).toEqual(
const file = fileObject({ deleted: false, tempFile: false }); expect.objectContaining({
file: {},
createComponent(componentProps(file)); size: 16,
expect(wrapper.find(ChangedFileIcon).props('tooltipTitle')).toBe('Modified'); showTooltip: true,
}); }),
);
}); });
describe('FileRowStats components', () => { describe('FileRowStats components', () => {
......
...@@ -73,6 +73,16 @@ describe('Changed file icon', () => { ...@@ -73,6 +73,16 @@ describe('Changed file icon', () => {
}); });
}); });
it('shows "Deleted" tooltip if file has been deleted', () => {
factory({
file: {
deleted: true,
},
});
expect(findTooltipText()).toBe('Deleted');
});
describe('with file unchanged', () => { describe('with file unchanged', () => {
beforeEach(() => { beforeEach(() => {
factory({ factory({
......
...@@ -150,27 +150,6 @@ describe('IDE extra file row component', () => { ...@@ -150,27 +150,6 @@ describe('IDE extra file row component', () => {
done(); done();
}); });
}); });
it('shows "Added" tooltip if file has been added', done => {
vm.file.changed = true;
vm.file.tempFile = true;
vm.$nextTick(() => {
expect(vm.$el.querySelector('.file-changed-icon').getAttribute('title')).toBe('Added');
done();
});
});
it('shows "Modified" tooltip if file has been modified', done => {
vm.file.changed = true;
vm.$nextTick(() => {
expect(vm.$el.querySelector('.file-changed-icon').getAttribute('title')).toBe('Modified');
done();
});
});
}); });
describe('merge request icon', () => { describe('merge request icon', () => {
......
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