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

99 lines
2.8 KiB
JavaScript
Raw Normal View History

2020-11-24 15:15:51 +05:30
import { GlIcon } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { shallowMount } from '@vue/test-utils';
2019-03-02 22:35:43 +05:30
import DiffStats from '~/diffs/components/diff_stats.vue';
2020-10-24 23:57:45 +05:30
const TEST_ADDED_LINES = 100;
const TEST_REMOVED_LINES = 200;
const DIFF_FILES_COUNT = '300';
const DIFF_FILES_COUNT_TRUNCATED = '300+';
2019-03-02 22:35:43 +05:30
describe('diff_stats', () => {
2020-10-24 23:57:45 +05:30
let wrapper;
const createComponent = (props = {}) => {
wrapper = shallowMount(DiffStats, {
2019-03-02 22:35:43 +05:30
propsData: {
2020-10-24 23:57:45 +05:30
addedLines: TEST_ADDED_LINES,
removedLines: TEST_REMOVED_LINES,
...props,
2019-03-02 22:35:43 +05:30
},
});
2020-10-24 23:57:45 +05:30
};
2019-03-02 22:35:43 +05:30
2020-10-24 23:57:45 +05:30
describe('diff stats group', () => {
const findDiffStatsGroup = () => wrapper.findAll('.diff-stats-group');
2019-03-02 22:35:43 +05:30
2020-10-24 23:57:45 +05:30
it('is not rendered if diffFilesCountText is empty', () => {
createComponent();
expect(findDiffStatsGroup().length).toBe(2);
2020-03-13 15:44:24 +05:30
});
2020-10-24 23:57:45 +05:30
it('is not rendered if diffFilesCountText is not a number', () => {
createComponent({
diffFilesCountText: null,
});
2020-03-13 15:44:24 +05:30
2020-10-24 23:57:45 +05:30
expect(findDiffStatsGroup().length).toBe(2);
2019-03-02 22:35:43 +05:30
});
2020-10-24 23:57:45 +05:30
});
2019-03-02 22:35:43 +05:30
2020-10-24 23:57:45 +05:30
describe('line changes', () => {
2021-03-08 18:12:59 +05:30
const findFileLine = (name) => wrapper.find(name);
2020-10-24 23:57:45 +05:30
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());
});
});
describe('files changes', () => {
2021-03-08 18:12:59 +05:30
const findIcon = (name) =>
2020-03-13 15:44:24 +05:30
wrapper
2020-11-24 15:15:51 +05:30
.findAll(GlIcon)
2021-03-08 18:12:59 +05:30
.filter((c) => c.attributes('name') === name)
2020-03-13 15:44:24 +05:30
.at(0).element.parentNode;
2020-10-24 23:57:45 +05:30
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 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,
});
expect(findIcon('doc-code').textContent.trim()).toContain(
`${DIFF_FILES_COUNT_TRUNCATED} files`,
);
});
2019-03-02 22:35:43 +05:30
});
});