diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-28 06:09:53 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-28 06:09:53 +0000 |
commit | c7bdf2532145e8f36a26685ed83fc8e5aaf7f31f (patch) | |
tree | 3923e60abbdc4a76e1d77eb5e747a65fb4f4fd18 /spec/frontend/diffs/components/diff_stats_spec.js | |
parent | 3e71ce5cf05740117061ed998b88450ad009a3ff (diff) | |
download | gitlab-ce-c7bdf2532145e8f36a26685ed83fc8e5aaf7f31f.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/diffs/components/diff_stats_spec.js')
-rw-r--r-- | spec/frontend/diffs/components/diff_stats_spec.js | 64 |
1 files changed, 48 insertions, 16 deletions
diff --git a/spec/frontend/diffs/components/diff_stats_spec.js b/spec/frontend/diffs/components/diff_stats_spec.js index 2bf1dd2f961..7a083fb6bde 100644 --- a/spec/frontend/diffs/components/diff_stats_spec.js +++ b/spec/frontend/diffs/components/diff_stats_spec.js @@ -4,7 +4,8 @@ import Icon from '~/vue_shared/components/icon.vue'; const TEST_ADDED_LINES = 100; const TEST_REMOVED_LINES = 200; -const DIFF_FILES_LENGTH = 300; +const DIFF_FILES_COUNT = '300'; +const DIFF_FILES_COUNT_TRUNCATED = '300+'; describe('diff_stats', () => { let wrapper; @@ -22,45 +23,76 @@ describe('diff_stats', () => { describe('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(); 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({ - diffFilesLength: Number.NaN, + diffFilesCountText: null, }); expect(findDiffStatsGroup().length).toBe(2); }); }); - describe('amount displayed', () => { - beforeEach(() => { - createComponent({ - diffFilesLength: DIFF_FILES_LENGTH, - }); + describe('line changes', () => { + const findFileLine = name => wrapper.find(name); + + it('shows the amount of lines added', () => { + expect(findFileLine('.js-file-addition-line').text()).toBe(TEST_ADDED_LINES.toString()); }); - const findFileLine = name => wrapper.find(name); + it('shows the amount of lines removed', () => { + expect(findFileLine('.js-file-deletion-line').text()).toBe(TEST_REMOVED_LINES.toString()); + }); + }); + + describe('files changes', () => { const findIcon = name => wrapper .findAll(Icon) .filter(c => c.attributes('name') === name) .at(0).element.parentNode; - it('shows the amount of lines added', () => { - expect(findFileLine('.js-file-addition-line').text()).toBe(TEST_ADDED_LINES.toString()); + it('shows amount of file changed with plural "files" when 0 files has changed', () => { + const oneFileChanged = '0'; + + createComponent({ + diffFilesCountText: oneFileChanged, + }); + + expect(findIcon('doc-code').textContent.trim()).toBe(`${oneFileChanged} files`); }); - it('shows the amount of lines removed', () => { - 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 the amount of files changed', () => { - expect(findIcon('doc-code').textContent).toContain(DIFF_FILES_LENGTH); + 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, + }); + + expect(findIcon('doc-code').textContent.trim()).toContain( + `${DIFF_FILES_COUNT_TRUNCATED} files`, + ); }); }); }); |