Commit c949a750 authored by Samantha Ming's avatar Samantha Ming

Display files in tab counter same as diff stats

Ensure the number of files displayed in the
 tab counter is the same the diff stats.

Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/33849
parent 996e5c5a
...@@ -405,7 +405,7 @@ export default { ...@@ -405,7 +405,7 @@ export default {
<compare-versions <compare-versions
:merge-request-diffs="mergeRequestDiffs" :merge-request-diffs="mergeRequestDiffs"
:is-limited-container="isLimitedContainer" :is-limited-container="isLimitedContainer"
:diff-files-length="diffFilesLength" :diff-files-count-text="numTotalFiles"
/> />
<hidden-files-warning <hidden-files-warning
......
...@@ -32,9 +32,10 @@ export default { ...@@ -32,9 +32,10 @@ export default {
required: false, required: false,
default: false, default: false,
}, },
diffFilesLength: { diffFilesCountText: {
type: Number, type: String,
required: true, required: false,
default: null,
}, },
}, },
computed: { computed: {
...@@ -119,7 +120,7 @@ export default { ...@@ -119,7 +120,7 @@ export default {
</div> </div>
<div class="inline-parallel-buttons d-none d-md-flex ml-auto"> <div class="inline-parallel-buttons d-none d-md-flex ml-auto">
<diff-stats <diff-stats
:diff-files-length="diffFilesLength" :diff-files-count-text="diffFilesCountText"
:added-lines="addedLines" :added-lines="addedLines"
:removed-lines="removedLines" :removed-lines="removedLines"
/> />
......
...@@ -14,18 +14,21 @@ export default { ...@@ -14,18 +14,21 @@ export default {
type: Number, type: Number,
required: true, required: true,
}, },
diffFilesLength: { diffFilesCountText: {
type: Number, type: String,
required: false, required: false,
default: null, default: null,
}, },
}, },
computed: { computed: {
diffFilesLength() {
return parseInt(this.diffFilesCountText, 10);
},
filesText() { filesText() {
return n__('file', 'files', this.diffFilesLength); return n__('file', 'files', this.diffFilesLength);
}, },
isCompareVersionsHeader() { isCompareVersionsHeader() {
return Boolean(this.diffFilesLength); return Boolean(this.diffFilesCountText);
}, },
hasDiffFiles() { hasDiffFiles() {
return isNumber(this.diffFilesLength) && this.diffFilesLength >= 0; return isNumber(this.diffFilesLength) && this.diffFilesLength >= 0;
...@@ -44,7 +47,7 @@ export default { ...@@ -44,7 +47,7 @@ export default {
> >
<div v-if="hasDiffFiles" class="diff-stats-group"> <div v-if="hasDiffFiles" class="diff-stats-group">
<icon name="doc-code" class="diff-stats-icon text-secondary" /> <icon name="doc-code" class="diff-stats-icon text-secondary" />
<span class="text-secondary bold">{{ diffFilesLength }} {{ filesText }}</span> <span class="text-secondary bold">{{ diffFilesCountText }} {{ filesText }}</span>
</div> </div>
<div <div
class="diff-stats-group cgreen d-flex align-items-center" class="diff-stats-group cgreen d-flex align-items-center"
......
---
title: Display files in tab counter same as diff stats
merge_request: 37390
author:
type: fixed
...@@ -30,7 +30,7 @@ describe('CompareVersions', () => { ...@@ -30,7 +30,7 @@ describe('CompareVersions', () => {
store, store,
propsData: { propsData: {
mergeRequestDiffs: diffsMockData, mergeRequestDiffs: diffsMockData,
diffFilesLength: 0, diffFilesCountText: null,
...props, ...props,
}, },
}); });
......
...@@ -4,7 +4,8 @@ import Icon from '~/vue_shared/components/icon.vue'; ...@@ -4,7 +4,8 @@ import Icon from '~/vue_shared/components/icon.vue';
const TEST_ADDED_LINES = 100; const TEST_ADDED_LINES = 100;
const TEST_REMOVED_LINES = 200; const TEST_REMOVED_LINES = 200;
const DIFF_FILES_LENGTH = 300; const DIFF_FILES_COUNT = '300';
const DIFF_FILES_COUNT_TRUNCATED = '300+';
describe('diff_stats', () => { describe('diff_stats', () => {
let wrapper; let wrapper;
...@@ -22,45 +23,76 @@ describe('diff_stats', () => { ...@@ -22,45 +23,76 @@ describe('diff_stats', () => {
describe('diff stats group', () => { describe('diff stats group', () => {
const findDiffStatsGroup = () => wrapper.findAll('.diff-stats-group'); const findDiffStatsGroup = () => wrapper.findAll('.diff-stats-group');
it('is not rendered if diffFileLengths is empty', () => { it('is not rendered if diffFilesCountText is empty', () => {
createComponent(); createComponent();
expect(findDiffStatsGroup().length).toBe(2); expect(findDiffStatsGroup().length).toBe(2);
}); });
it('is not rendered if diffFileLengths is not a number', () => { it('is not rendered if diffFilesCountText is not a number', () => {
createComponent({ createComponent({
diffFilesLength: Number.NaN, diffFilesCountText: null,
}); });
expect(findDiffStatsGroup().length).toBe(2); expect(findDiffStatsGroup().length).toBe(2);
}); });
}); });
describe('amount displayed', () => { describe('line changes', () => {
beforeEach(() => { const findFileLine = name => wrapper.find(name);
createComponent({
diffFilesLength: DIFF_FILES_LENGTH, it('shows the amount of lines added', () => {
expect(findFileLine('.js-file-addition-line').text()).toBe(TEST_ADDED_LINES.toString());
});
it('shows the amount of lines removed', () => {
expect(findFileLine('.js-file-deletion-line').text()).toBe(TEST_REMOVED_LINES.toString());
}); });
}); });
const findFileLine = name => wrapper.find(name); describe('files changes', () => {
const findIcon = name => const findIcon = name =>
wrapper wrapper
.findAll(Icon) .findAll(Icon)
.filter(c => c.attributes('name') === name) .filter(c => c.attributes('name') === name)
.at(0).element.parentNode; .at(0).element.parentNode;
it('shows the amount of lines added', () => { it('shows amount of file changed with plural "files" when 0 files has changed', () => {
expect(findFileLine('.js-file-addition-line').text()).toBe(TEST_ADDED_LINES.toString()); const oneFileChanged = '0';
createComponent({
diffFilesCountText: oneFileChanged,
}); });
it('shows the amount of lines removed', () => { expect(findIcon('doc-code').textContent.trim()).toBe(`${oneFileChanged} files`);
expect(findFileLine('.js-file-deletion-line').text()).toBe(TEST_REMOVED_LINES.toString()); });
it('shows amount of file changed with singular "file" when 1 file is changed', () => {
const oneFileChanged = '1';
createComponent({
diffFilesCountText: oneFileChanged,
});
expect(findIcon('doc-code').textContent.trim()).toBe(`${oneFileChanged} file`);
});
it('shows amount of files change with plural "files" when multiple files are changed', () => {
createComponent({
diffFilesCountText: DIFF_FILES_COUNT,
});
expect(findIcon('doc-code').textContent.trim()).toContain(`${DIFF_FILES_COUNT} files`);
});
it('shows amount of files change with plural "files" when files changed is truncated', () => {
createComponent({
diffFilesCountText: DIFF_FILES_COUNT_TRUNCATED,
}); });
it('shows the amount of files changed', () => { expect(findIcon('doc-code').textContent.trim()).toContain(
expect(findIcon('doc-code').textContent).toContain(DIFF_FILES_LENGTH); `${DIFF_FILES_COUNT_TRUNCATED} files`,
);
}); });
}); });
}); });
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