summaryrefslogtreecommitdiff
path: root/spec/frontend/vue_shared/components/todo_button_spec.js
blob: 8043bb7785b1cd1cbd71758adf485def11077b68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { GlButton } from '@gitlab/ui';
import { shallowMount, mount } from '@vue/test-utils';
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);
  });
});