2020-03-13 15:44:24 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import DiffFileRow from '~/diffs/components/diff_file_row.vue';
|
|
|
|
import FileRowStats from '~/diffs/components/file_row_stats.vue';
|
|
|
|
import ChangedFileIcon from '~/vue_shared/components/changed_file_icon.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import FileRow from '~/vue_shared/components/file_row.vue';
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
describe('Diff File Row component', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
const createComponent = (props = {}) => {
|
2020-03-13 15:44:24 +05:30
|
|
|
wrapper = shallowMount(DiffFileRow, {
|
|
|
|
propsData: { ...props },
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders file row component', () => {
|
|
|
|
const sharedProps = {
|
|
|
|
level: 4,
|
|
|
|
file: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
const diffFileRowProps = {
|
|
|
|
hideFileStats: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
createComponent({
|
|
|
|
...sharedProps,
|
|
|
|
...diffFileRowProps,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.find(FileRow).props()).toEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
...sharedProps,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders ChangedFileIcon component', () => {
|
|
|
|
createComponent({
|
|
|
|
level: 4,
|
|
|
|
file: {},
|
|
|
|
hideFileStats: false,
|
2020-04-08 14:13:33 +05:30
|
|
|
showTooltip: true,
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.find(ChangedFileIcon).props()).toEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
file: {},
|
|
|
|
size: 16,
|
2020-04-08 14:13:33 +05:30
|
|
|
showTooltip: true,
|
2020-03-13 15:44:24 +05:30
|
|
|
}),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
it.each`
|
2021-02-22 17:27:13 +05:30
|
|
|
fileType | isViewed | expected
|
|
|
|
${'blob'} | ${false} | ${'gl-font-weight-bold'}
|
|
|
|
${'blob'} | ${true} | ${''}
|
|
|
|
${'tree'} | ${false} | ${''}
|
|
|
|
${'tree'} | ${true} | ${''}
|
2020-11-24 15:15:51 +05:30
|
|
|
`(
|
2021-02-22 17:27:13 +05:30
|
|
|
'with (fileType="$fileType", isViewed=$isViewed), sets fileClasses="$expected"',
|
|
|
|
({ fileType, isViewed, expected }) => {
|
|
|
|
createComponent({
|
|
|
|
file: {
|
|
|
|
type: fileType,
|
|
|
|
fileHash: '#123456789',
|
2020-11-24 15:15:51 +05:30
|
|
|
},
|
2021-02-22 17:27:13 +05:30
|
|
|
level: 0,
|
|
|
|
hideFileStats: false,
|
|
|
|
viewedFiles: isViewed ? { '#123456789': true } : {},
|
|
|
|
});
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(wrapper.find(FileRow).props('fileClasses')).toBe(expected);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
describe('FileRowStats components', () => {
|
|
|
|
it.each`
|
|
|
|
type | hideFileStats | value | desc
|
|
|
|
${'blob'} | ${false} | ${true} | ${'is shown if file type is blob'}
|
|
|
|
${'tree'} | ${false} | ${false} | ${'is hidden if file is not blob'}
|
|
|
|
${'blob'} | ${true} | ${false} | ${'is hidden if hideFileStats is true'}
|
|
|
|
`('$desc', ({ type, value, hideFileStats }) => {
|
|
|
|
createComponent({
|
|
|
|
level: 4,
|
|
|
|
file: {
|
|
|
|
type,
|
|
|
|
},
|
|
|
|
hideFileStats,
|
|
|
|
});
|
|
|
|
expect(wrapper.find(FileRowStats).exists()).toEqual(value);
|
|
|
|
});
|
|
|
|
});
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
it('adds is-active class when currentDiffFileId matches file_hash', () => {
|
|
|
|
createComponent({
|
|
|
|
level: 0,
|
|
|
|
currentDiffFileId: '123',
|
|
|
|
file: { fileHash: '123' },
|
|
|
|
hideFileStats: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.classes('is-active')).toBe(true);
|
|
|
|
});
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|