Commit b388e1d2 authored by Martin Wortschack's avatar Martin Wortschack

Merge branch 'todo-button-shared' into 'master'

Create shared todo_button.vue component

See merge request gitlab-org/gitlab!39931
parents 89ef1f37 e3aa28cc
<script>
import { GlButton } from '@gitlab/ui';
import { __ } from '~/locale';
export default {
components: {
GlButton,
},
props: {
isTodo: {
type: Boolean,
required: false,
default: true,
},
},
computed: {
buttonLabel() {
return this.isTodo ? __('Mark as done') : __('Add a To-Do');
},
},
};
</script>
<template>
<gl-button v-bind="$attrs" :aria-label="buttonLabel" @click="$emit('click', $event)">
{{ buttonLabel }}
</gl-button>
</template>
import { shallowMount, mount } from '@vue/test-utils';
import { GlButton } from '@gitlab/ui';
import TodoButton from '~/vue_shared/components/todo_button.vue';
describe('Todo Button', () => {
let wrapper;
const createComponent = (props = {}, mountFn = shallowMount) => {
wrapper = mountFn(TodoButton, {
propsData: {
...props,
},
});
};
afterEach(() => {
wrapper.destroy();
});
it('renders GlButton', () => {
createComponent();
expect(wrapper.find(GlButton).exists()).toBe(true);
});
it('emits click event when clicked', () => {
createComponent({}, mount);
wrapper.find(GlButton).trigger('click');
expect(wrapper.emitted().click).toBeTruthy();
});
it.each`
label | isTodo
${'Mark as done'} | ${true}
${'Add a To-Do'} | ${false}
`('sets correct label when isTodo is $isTodo', ({ label, isTodo }) => {
createComponent({ isTodo });
expect(wrapper.find(GlButton).text()).toBe(label);
});
it('binds additional props to GlButton', () => {
createComponent({ loading: 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