debian-mirror-gitlab/spec/frontend/diffs/components/diff_stats_spec.js

55 lines
1.6 KiB
JavaScript
Raw Normal View History

2019-03-02 22:35:43 +05:30
import { shallowMount } from '@vue/test-utils';
import DiffStats from '~/diffs/components/diff_stats.vue';
2020-03-13 15:44:24 +05:30
import Icon from '~/vue_shared/components/icon.vue';
2019-03-02 22:35:43 +05:30
describe('diff_stats', () => {
2020-03-13 15:44:24 +05:30
it('does not render a group if diffFileLengths is empty', () => {
2019-03-02 22:35:43 +05:30
const wrapper = shallowMount(DiffStats, {
propsData: {
addedLines: 1,
removedLines: 2,
},
});
const groups = wrapper.findAll('.diff-stats-group');
expect(groups.length).toBe(2);
});
2020-03-13 15:44:24 +05:30
it('does not render a group if diffFileLengths is not a number', () => {
const wrapper = shallowMount(DiffStats, {
propsData: {
addedLines: 1,
removedLines: 2,
diffFilesLength: Number.NaN,
},
});
const groups = wrapper.findAll('.diff-stats-group');
expect(groups.length).toBe(2);
});
2019-03-02 22:35:43 +05:30
it('shows amount of files changed, lines added and lines removed when passed all props', () => {
const wrapper = shallowMount(DiffStats, {
propsData: {
addedLines: 100,
removedLines: 200,
diffFilesLength: 300,
},
});
2020-03-13 15:44:24 +05:30
const findFileLine = name => wrapper.find(name);
const findIcon = name =>
wrapper
.findAll(Icon)
.filter(c => c.attributes('name') === name)
.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');
expect(deletions.text()).toBe('200');
2019-03-02 22:35:43 +05:30
expect(filesChanged.textContent).toContain('300');
});
});