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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

115 lines
2.9 KiB
JavaScript
Raw Normal View History

2022-04-04 11:22:00 +05:30
import { shallowMount } from '@vue/test-utils';
2023-03-04 22:38:38 +05:30
import { GlButton } from '@gitlab/ui';
2022-04-04 11:22:00 +05:30
import Vue from 'vue';
2019-09-30 21:07:59 +05:30
import Vuex from 'vuex';
import DiffDiscussionReply from '~/diffs/components/diff_discussion_reply.vue';
import NoteSignedOutWidget from '~/notes/components/note_signed_out_widget.vue';
2023-03-04 22:38:38 +05:30
import { START_THREAD } from '~/diffs/i18n';
2022-04-04 11:22:00 +05:30
Vue.use(Vuex);
2019-09-30 21:07:59 +05:30
describe('DiffDiscussionReply', () => {
let wrapper;
let getters;
let store;
const createComponent = (props = {}, slots = {}) => {
wrapper = shallowMount(DiffDiscussionReply, {
store,
propsData: {
...props,
},
slots: {
...slots,
},
});
};
describe('if user can reply', () => {
beforeEach(() => {
getters = {
userCanReply: () => true,
getUserData: () => ({
path: 'test-path',
avatar_url: 'avatar_url',
name: 'John Doe',
}),
};
store = new Vuex.Store({
getters,
});
});
it('should render a form if component has form', () => {
createComponent(
{
renderReplyPlaceholder: false,
hasForm: true,
},
{
form: `<div id="test-form"></div>`,
},
);
expect(wrapper.find('#test-form').exists()).toBe(true);
});
2023-03-04 22:38:38 +05:30
it('should render a reply placeholder button if there is no form', () => {
2019-09-30 21:07:59 +05:30
createComponent({
renderReplyPlaceholder: true,
hasForm: false,
});
2023-03-04 22:38:38 +05:30
expect(wrapper.findComponent(GlButton).text()).toBe(START_THREAD);
2019-09-30 21:07:59 +05:30
});
2023-03-04 22:38:38 +05:30
it.each`
userCanReply | hasForm | renderReplyPlaceholder | showButton
${false} | ${false} | ${false} | ${false}
${true} | ${false} | ${false} | ${false}
${true} | ${true} | ${false} | ${false}
${true} | ${true} | ${true} | ${false}
${true} | ${false} | ${true} | ${true}
${false} | ${false} | ${true} | ${false}
`(
'reply button existence is `$showButton` when userCanReply is `$userCanReply`, hasForm is `$hasForm` and renderReplyPlaceholder is `$renderReplyPlaceholder`',
({ userCanReply, hasForm, renderReplyPlaceholder, showButton }) => {
getters = {
userCanReply: () => userCanReply,
};
store = new Vuex.Store({
getters,
});
createComponent({
renderReplyPlaceholder,
hasForm,
});
expect(wrapper.findComponent(GlButton).exists()).toBe(showButton);
},
);
2019-09-30 21:07:59 +05:30
});
it('renders a signed out widget when user is not logged in', () => {
getters = {
userCanReply: () => false,
getUserData: () => null,
};
store = new Vuex.Store({
getters,
});
createComponent({
renderReplyPlaceholder: false,
hasForm: false,
});
2022-10-11 01:57:18 +05:30
expect(wrapper.findComponent(NoteSignedOutWidget).exists()).toBe(true);
2019-09-30 21:07:59 +05:30
});
});