Commit 72a4673b authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Merge branch 'refactor-diff-stats-spec' into 'master'

Refactor diff_stats_spec

See merge request gitlab-org/gitlab!37650
parents 8be71768 ed80a171
...@@ -2,39 +2,46 @@ import { shallowMount } from '@vue/test-utils'; ...@@ -2,39 +2,46 @@ import { shallowMount } from '@vue/test-utils';
import DiffStats from '~/diffs/components/diff_stats.vue'; import DiffStats from '~/diffs/components/diff_stats.vue';
import Icon from '~/vue_shared/components/icon.vue'; import Icon from '~/vue_shared/components/icon.vue';
const TEST_ADDED_LINES = 100;
const TEST_REMOVED_LINES = 200;
const DIFF_FILES_LENGTH = 300;
describe('diff_stats', () => { describe('diff_stats', () => {
it('does not render a group if diffFileLengths is empty', () => { let wrapper;
const wrapper = shallowMount(DiffStats, {
const createComponent = (props = {}) => {
wrapper = shallowMount(DiffStats, {
propsData: { propsData: {
addedLines: 1, addedLines: TEST_ADDED_LINES,
removedLines: 2, removedLines: TEST_REMOVED_LINES,
...props,
}, },
}); });
const groups = wrapper.findAll('.diff-stats-group'); };
describe('diff stats group', () => {
const findDiffStatsGroup = () => wrapper.findAll('.diff-stats-group');
it('is not rendered if diffFileLengths is empty', () => {
createComponent();
expect(groups.length).toBe(2); expect(findDiffStatsGroup().length).toBe(2);
}); });
it('does not render a group if diffFileLengths is not a number', () => { it('is not rendered if diffFileLengths is not a number', () => {
const wrapper = shallowMount(DiffStats, { createComponent({
propsData: {
addedLines: 1,
removedLines: 2,
diffFilesLength: Number.NaN, diffFilesLength: Number.NaN,
},
}); });
const groups = wrapper.findAll('.diff-stats-group');
expect(groups.length).toBe(2); expect(findDiffStatsGroup().length).toBe(2);
});
}); });
it('shows amount of files changed, lines added and lines removed when passed all props', () => { describe('amount displayed', () => {
const wrapper = shallowMount(DiffStats, { beforeEach(() => {
propsData: { createComponent({
addedLines: 100, diffFilesLength: DIFF_FILES_LENGTH,
removedLines: 200, });
diffFilesLength: 300,
},
}); });
const findFileLine = name => wrapper.find(name); const findFileLine = name => wrapper.find(name);
...@@ -43,12 +50,17 @@ describe('diff_stats', () => { ...@@ -43,12 +50,17 @@ describe('diff_stats', () => {
.findAll(Icon) .findAll(Icon)
.filter(c => c.attributes('name') === name) .filter(c => c.attributes('name') === name)
.at(0).element.parentNode; .at(0).element.parentNode;
const additions = findFileLine('.js-file-addition-line');
const deletions = findFileLine('.js-file-deletion-line');
const filesChanged = findIcon('doc-code');
expect(additions.text()).toBe('100'); it('shows the amount of lines added', () => {
expect(deletions.text()).toBe('200'); expect(findFileLine('.js-file-addition-line').text()).toBe(TEST_ADDED_LINES.toString());
expect(filesChanged.textContent).toContain('300'); });
it('shows the amount of lines removed', () => {
expect(findFileLine('.js-file-deletion-line').text()).toBe(TEST_REMOVED_LINES.toString());
});
it('shows the amount of files changed', () => {
expect(findIcon('doc-code').textContent).toContain(DIFF_FILES_LENGTH);
});
}); });
}); });
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