2022-08-27 11:52:29 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2019-12-26 22:10:19 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
import { nextTick } from 'vue';
|
2022-08-27 11:52:29 +05:30
|
|
|
import { GlAvatar, GlAvatarLink } from '@gitlab/ui';
|
2019-12-26 22:10:19 +05:30
|
|
|
import diffDiscussionHeader from '~/notes/components/diff_discussion_header.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import createStore from '~/notes/stores';
|
2019-12-26 22:10:19 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
import mockDiffFile from 'jest/diffs/mock_data/diff_discussions';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { discussionMock } from '../mock_data';
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
describe('diff_discussion_header component', () => {
|
|
|
|
let store;
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
window.mrTabs = {};
|
|
|
|
store = createStore();
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
wrapper = shallowMount(diffDiscussionHeader, {
|
2019-12-26 22:10:19 +05:30
|
|
|
store,
|
|
|
|
propsData: { discussion: discussionMock },
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
describe('Avatar', () => {
|
|
|
|
const firstNoteAuthor = discussionMock.notes[0].author;
|
|
|
|
const findAvatarLink = () => wrapper.findComponent(GlAvatarLink);
|
|
|
|
const findAvatar = () => wrapper.findComponent(GlAvatar);
|
2019-12-26 22:10:19 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
it('should render user avatar and user avatar link', () => {
|
|
|
|
expect(findAvatar().exists()).toBe(true);
|
|
|
|
expect(findAvatarLink().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders avatar of the first note author', () => {
|
|
|
|
const props = findAvatar().props();
|
2019-12-26 22:10:19 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(props).toMatchObject({
|
|
|
|
src: firstNoteAuthor.avatar_url,
|
|
|
|
alt: firstNoteAuthor.name,
|
2022-11-25 23:54:43 +05:30
|
|
|
size: 32,
|
2022-08-27 11:52:29 +05:30
|
|
|
});
|
|
|
|
});
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('action text', () => {
|
|
|
|
const commitId = 'razupaltuff';
|
|
|
|
const truncatedCommitId = commitId.substr(0, 8);
|
|
|
|
let commitElement;
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
beforeEach(async () => {
|
2019-12-26 22:10:19 +05:30
|
|
|
store.state.diffs = {
|
|
|
|
projectPath: 'something',
|
|
|
|
};
|
|
|
|
|
|
|
|
wrapper.setProps({
|
|
|
|
discussion: {
|
|
|
|
...discussionMock,
|
|
|
|
for_commit: true,
|
|
|
|
commit_id: commitId,
|
|
|
|
diff_discussion: true,
|
|
|
|
diff_file: {
|
|
|
|
...mockDiffFile,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
commitElement = wrapper.find('.commit-sha');
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('for diff threads without a commit id', () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
it('should show started a thread on the diff text', async () => {
|
2019-12-26 22:10:19 +05:30
|
|
|
Object.assign(wrapper.vm.discussion, {
|
|
|
|
for_commit: false,
|
|
|
|
commit_id: null,
|
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
expect(wrapper.text()).toContain('started a thread on the diff');
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('should show thread on older version text', async () => {
|
2019-12-26 22:10:19 +05:30
|
|
|
Object.assign(wrapper.vm.discussion, {
|
|
|
|
for_commit: false,
|
|
|
|
commit_id: null,
|
|
|
|
active: false,
|
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
expect(wrapper.text()).toContain('started a thread on an old version of the diff');
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('for commit threads', () => {
|
|
|
|
it('should display a monospace started a thread on commit', () => {
|
|
|
|
expect(wrapper.text()).toContain(`started a thread on commit ${truncatedCommitId}`);
|
|
|
|
expect(commitElement.exists()).toBe(true);
|
|
|
|
expect(commitElement.text()).toContain(truncatedCommitId);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('for diff thread with a commit id', () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
it('should display started thread on commit header', async () => {
|
2019-12-26 22:10:19 +05:30
|
|
|
wrapper.vm.discussion.for_commit = false;
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
expect(wrapper.text()).toContain(`started a thread on commit ${truncatedCommitId}`);
|
2019-12-26 22:10:19 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(commitElement).not.toBe(null);
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('should display outdated change on commit header', async () => {
|
2019-12-26 22:10:19 +05:30
|
|
|
wrapper.vm.discussion.for_commit = false;
|
|
|
|
wrapper.vm.discussion.active = false;
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
expect(wrapper.text()).toContain(
|
|
|
|
`started a thread on an outdated change in commit ${truncatedCommitId}`,
|
|
|
|
);
|
2019-12-26 22:10:19 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(commitElement).not.toBe(null);
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|