2020-01-08 10:08:01 -05:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2020-09-04 08:08:27 -04:00
|
|
|
import { GlButton } from '@gitlab/ui';
|
2019-12-09 07:07:58 -05:00
|
|
|
import resolveDiscussionButton from '~/notes/components/discussion_resolve_button.vue';
|
2019-01-28 17:44:17 -05:00
|
|
|
|
|
|
|
const buttonTitle = 'Resolve discussion';
|
|
|
|
|
|
|
|
describe('resolveDiscussionButton', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const factory = options => {
|
|
|
|
wrapper = shallowMount(resolveDiscussionButton, {
|
|
|
|
...options,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
factory({
|
|
|
|
propsData: {
|
|
|
|
isResolving: false,
|
|
|
|
buttonTitle,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should emit a onClick event on button click', () => {
|
2020-09-04 08:08:27 -04:00
|
|
|
const button = wrapper.find(GlButton);
|
2019-01-28 17:44:17 -05:00
|
|
|
|
2020-09-04 08:08:27 -04:00
|
|
|
button.vm.$emit('click');
|
2019-01-28 17:44:17 -05:00
|
|
|
|
2020-01-01 01:09:01 -05:00
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
|
|
|
expect(wrapper.emitted()).toEqual({
|
|
|
|
onClick: [[]],
|
|
|
|
});
|
2019-01-28 17:44:17 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should contain the provided button title', () => {
|
2020-09-04 08:08:27 -04:00
|
|
|
const button = wrapper.find(GlButton);
|
2019-01-28 17:44:17 -05:00
|
|
|
|
|
|
|
expect(button.text()).toContain(buttonTitle);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should show a loading spinner while resolving', () => {
|
|
|
|
factory({
|
|
|
|
propsData: {
|
|
|
|
isResolving: true,
|
|
|
|
buttonTitle,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-09-04 08:08:27 -04:00
|
|
|
const button = wrapper.find(GlButton);
|
2019-01-28 17:44:17 -05:00
|
|
|
|
2020-09-04 08:08:27 -04:00
|
|
|
expect(button.props('loading')).toEqual(true);
|
2019-01-28 17:44:17 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should only show a loading spinner while resolving', () => {
|
|
|
|
factory({
|
|
|
|
propsData: {
|
|
|
|
isResolving: false,
|
|
|
|
buttonTitle,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-09-04 08:08:27 -04:00
|
|
|
const button = wrapper.find(GlButton);
|
2019-01-28 17:44:17 -05:00
|
|
|
|
2020-01-08 10:08:01 -05:00
|
|
|
wrapper.vm.$nextTick(() => {
|
2020-09-04 08:08:27 -04:00
|
|
|
expect(button.props('loading')).toEqual(false);
|
2019-01-28 17:44:17 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|