Commit b532a9fa authored by Thomas Randolph's avatar Thomas Randolph

Show bytes diff for stats on non-diffable files, if provided

parent c196941b
...@@ -2,10 +2,16 @@ ...@@ -2,10 +2,16 @@
import { GlIcon } from '@gitlab/ui'; import { GlIcon } from '@gitlab/ui';
import { isNumber } from 'lodash'; import { isNumber } from 'lodash';
import { n__ } from '~/locale'; import { n__ } from '~/locale';
import { isNotDiffable, stats } from '../utils/diff_file';
export default { export default {
components: { GlIcon }, components: { GlIcon },
props: { props: {
diffFile: {
type: Object,
required: false,
default: () => null,
},
addedLines: { addedLines: {
type: Number, type: Number,
required: true, required: true,
...@@ -33,6 +39,12 @@ export default { ...@@ -33,6 +39,12 @@ export default {
hasDiffFiles() { hasDiffFiles() {
return isNumber(this.diffFilesLength) && this.diffFilesLength >= 0; return isNumber(this.diffFilesLength) && this.diffFilesLength >= 0;
}, },
notDiffable() {
return isNotDiffable(this.diffFile);
},
fileStats() {
return stats(this.diffFile);
},
}, },
}; };
</script> </script>
...@@ -45,6 +57,10 @@ export default { ...@@ -45,6 +57,10 @@ export default {
'd-none d-sm-inline-flex': !isCompareVersionsHeader, 'd-none d-sm-inline-flex': !isCompareVersionsHeader,
}" }"
> >
<div v-if="notDiffable" :class="fileStats.classes">
{{ fileStats.text }}
</div>
<div v-else class="diff-stats-contents">
<div v-if="hasDiffFiles" class="diff-stats-group"> <div v-if="hasDiffFiles" class="diff-stats-group">
<gl-icon name="doc-code" class="diff-stats-icon text-secondary" /> <gl-icon name="doc-code" class="diff-stats-icon text-secondary" />
<span class="text-secondary bold">{{ diffFilesCountText }} {{ filesText }}</span> <span class="text-secondary bold">{{ diffFilesCountText }} {{ filesText }}</span>
...@@ -64,4 +80,5 @@ export default { ...@@ -64,4 +80,5 @@ export default {
<span class="js-file-deletion-line">{{ removedLines }}</span> <span class="js-file-deletion-line">{{ removedLines }}</span>
</div> </div>
</div> </div>
</div>
</template> </template>
...@@ -646,6 +646,10 @@ table.code { ...@@ -646,6 +646,10 @@ table.code {
align-items: center; align-items: center;
padding: 0 1rem; padding: 0 1rem;
.diff-stats-contents {
display: contents;
}
.diff-stats-group { .diff-stats-group {
padding: 0 0.25rem; padding: 0 0.25rem;
} }
......
import { GlIcon } from '@gitlab/ui'; import { GlIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import DiffStats from '~/diffs/components/diff_stats.vue'; import DiffStats from '~/diffs/components/diff_stats.vue';
import mockDiffFile from '../mock_data/diff_file';
const TEST_ADDED_LINES = 100; const TEST_ADDED_LINES = 100;
const TEST_REMOVED_LINES = 200; const TEST_REMOVED_LINES = 200;
...@@ -38,9 +39,37 @@ describe('diff_stats', () => { ...@@ -38,9 +39,37 @@ describe('diff_stats', () => {
}); });
}); });
describe('bytes changes', () => {
let file;
const getBytesContainer = () => wrapper.find('.diff-stats > div:first-child');
beforeEach(() => {
file = {
...mockDiffFile,
viewer: {
...mockDiffFile.viewer,
name: 'not_diffable',
},
};
createComponent({ diffFile: file });
});
it("renders the bytes changes instead of line changes when the file isn't diffable", () => {
const content = getBytesContainer();
expect(content.classes('cgreen')).toBe(true);
expect(content.text()).toBe('+1.00 KiB (+100%)');
});
});
describe('line changes', () => { describe('line changes', () => {
const findFileLine = (name) => wrapper.find(name); const findFileLine = (name) => wrapper.find(name);
beforeEach(() => {
createComponent();
});
it('shows the amount of lines added', () => { it('shows the amount of lines added', () => {
expect(findFileLine('.js-file-addition-line').text()).toBe(TEST_ADDED_LINES.toString()); expect(findFileLine('.js-file-addition-line').text()).toBe(TEST_ADDED_LINES.toString());
}); });
......
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