2020-03-13 15:44:24 +05:30
|
|
|
import { mount } from '@vue/test-utils';
|
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
|
|
|
|
|
|
|
import mockDiffFile from '../../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();
|
|
|
|
|
|
|
|
wrapper = mount(diffDiscussionHeader, {
|
|
|
|
store,
|
|
|
|
propsData: { discussion: discussionMock },
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render user avatar', () => {
|
|
|
|
const discussion = { ...discussionMock };
|
|
|
|
discussion.diff_file = mockDiffFile;
|
|
|
|
discussion.diff_discussion = true;
|
|
|
|
|
|
|
|
wrapper.setProps({ discussion });
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
|
|
|
expect(wrapper.find('.user-avatar-link').exists()).toBe(true);
|
|
|
|
});
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('action text', () => {
|
|
|
|
const commitId = 'razupaltuff';
|
|
|
|
const truncatedCommitId = commitId.substr(0, 8);
|
|
|
|
let commitElement;
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
beforeEach((done) => {
|
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,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper.vm
|
|
|
|
.$nextTick()
|
|
|
|
.then(() => {
|
|
|
|
commitElement = wrapper.find('.commit-sha');
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('for diff threads without a commit id', () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
it('should show started a thread on the diff text', (done) => {
|
2019-12-26 22:10:19 +05:30
|
|
|
Object.assign(wrapper.vm.discussion, {
|
|
|
|
for_commit: false,
|
|
|
|
commit_id: null,
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper.vm.$nextTick(() => {
|
|
|
|
expect(wrapper.text()).toContain('started a thread on the diff');
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it('should show thread on older version text', (done) => {
|
2019-12-26 22:10:19 +05:30
|
|
|
Object.assign(wrapper.vm.discussion, {
|
|
|
|
for_commit: false,
|
|
|
|
commit_id: null,
|
|
|
|
active: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper.vm.$nextTick(() => {
|
|
|
|
expect(wrapper.text()).toContain('started a thread on an old version of the diff');
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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', () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
it('should display started thread on commit header', (done) => {
|
2019-12-26 22:10:19 +05:30
|
|
|
wrapper.vm.discussion.for_commit = false;
|
|
|
|
|
|
|
|
wrapper.vm.$nextTick(() => {
|
|
|
|
expect(wrapper.text()).toContain(`started a thread on commit ${truncatedCommitId}`);
|
|
|
|
|
|
|
|
expect(commitElement).not.toBe(null);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it('should display outdated change on commit header', (done) => {
|
2019-12-26 22:10:19 +05:30
|
|
|
wrapper.vm.discussion.for_commit = false;
|
|
|
|
wrapper.vm.discussion.active = false;
|
|
|
|
|
|
|
|
wrapper.vm.$nextTick(() => {
|
|
|
|
expect(wrapper.text()).toContain(
|
|
|
|
`started a thread on an outdated change in commit ${truncatedCommitId}`,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(commitElement).not.toBe(null);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|