Commit dac3a45a authored by Tom Quirk's avatar Tom Quirk

Remove unnecessary props from todo_button

parent bd99c8b6
...@@ -7,20 +7,12 @@ export default { ...@@ -7,20 +7,12 @@ export default {
GlButton, GlButton,
}, },
props: { props: {
issuableId: {
type: Number,
required: true,
},
issuableType: {
type: String,
required: true,
},
isTodo: { isTodo: {
type: Boolean, type: Boolean,
required: false, required: false,
default: true, default: true,
}, },
isActionActive: { loading: {
type: Boolean, type: Boolean,
required: false, required: false,
default: false, default: false,
...@@ -31,23 +23,11 @@ export default { ...@@ -31,23 +23,11 @@ export default {
return this.isTodo ? __('Mark as done') : __('Add a To-Do'); return this.isTodo ? __('Mark as done') : __('Add a To-Do');
}, },
}, },
methods: {
toggleTodo() {
this.$emit('toggleTodo', {
issuableType: this.issuableType,
issuableId: this.issuableId,
});
},
},
}; };
</script> </script>
<template> <template>
<div> <gl-button :loading="loading" :aria-label="buttonLabel" @click="$emit('click', $event)">
<slot :toggleTodo="toggleTodo" :label="buttonLabel"> {{ buttonLabel }}
<gl-button :loading="isActionActive" :aria-label="buttonLabel" @click="toggleTodo"> </gl-button>
{{ buttonLabel }}
</gl-button></slot
>
</div>
</template> </template>
import { mount } from '@vue/test-utils'; import { shallowMount, mount } from '@vue/test-utils';
import { GlButton, GlLoadingIcon } from '@gitlab/ui'; import { GlButton } from '@gitlab/ui';
import TodoButton from '~/vue_shared/components/todo_button.vue'; import TodoButton from '~/vue_shared/components/todo_button.vue';
const defaultProps = {
issuableId: 1,
issuableType: 'epic',
};
describe('Todo Button', () => { describe('Todo Button', () => {
let wrapper; let wrapper;
const createComponent = (props = {}) => { const createComponent = (props = {}, mountFn = shallowMount) => {
wrapper = mount(TodoButton, { wrapper = mountFn(TodoButton, {
propsData: { propsData: {
...defaultProps,
...props, ...props,
}, },
}); });
...@@ -29,12 +23,11 @@ describe('Todo Button', () => { ...@@ -29,12 +23,11 @@ describe('Todo Button', () => {
expect(wrapper.find(GlButton).exists()).toBe(true); expect(wrapper.find(GlButton).exists()).toBe(true);
}); });
it('emits toggleTodo event when clicked', () => { it('emits click event when clicked', () => {
createComponent(); createComponent({}, mount);
wrapper.find(GlButton).trigger('click'); wrapper.find(GlButton).trigger('click');
expect(wrapper.emitted().toggleTodo).toBeTruthy(); expect(wrapper.emitted().click).toBeTruthy();
expect(wrapper.emitted().toggleTodo[0]).toEqual([defaultProps]);
}); });
it.each` it.each`
...@@ -47,9 +40,9 @@ describe('Todo Button', () => { ...@@ -47,9 +40,9 @@ describe('Todo Button', () => {
expect(wrapper.find(GlButton).text()).toBe(label); expect(wrapper.find(GlButton).text()).toBe(label);
}); });
it('renders loading icon when `isActionActive` is true', () => { it('sets button props correctly when `loading` is true', () => {
createComponent({ isActionActive: true }); createComponent({ loading: true });
expect(wrapper.find(GlLoadingIcon).exists()).toBe(true); expect(wrapper.find(GlButton).props('loading')).toBe(true);
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment