Welcome to mirror list, hosted at ThFree Co, Russian Federation.

task_list_item_actions_spec.js « components « show « issues « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d52f9d574536bb251beda5d429ed94137c56524e (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
49
50
51
52
53
54
import { GlDropdown, GlDropdownItem } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import TaskListItemActions from '~/issues/show/components/task_list_item_actions.vue';
import eventHub from '~/issues/show/event_hub';

describe('TaskListItemActions component', () => {
  let wrapper;

  const findGlDropdown = () => wrapper.findComponent(GlDropdown);
  const findConvertToTaskItem = () => wrapper.findAllComponents(GlDropdownItem).at(0);
  const findDeleteItem = () => wrapper.findAllComponents(GlDropdownItem).at(1);

  const mountComponent = () => {
    const li = document.createElement('li');
    li.dataset.sourcepos = '3:1-3:10';
    li.appendChild(document.createElement('div'));
    document.body.appendChild(li);

    wrapper = shallowMount(TaskListItemActions, {
      provide: { canUpdate: true, toggleClass: 'task-list-item-actions' },
      attachTo: document.querySelector('div'),
    });
  };

  beforeEach(() => {
    mountComponent();
  });

  it('renders dropdown', () => {
    expect(findGlDropdown().props()).toMatchObject({
      category: 'tertiary',
      icon: 'ellipsis_v',
      right: true,
      text: TaskListItemActions.i18n.taskActions,
      textSrOnly: true,
    });
  });

  it('emits event when `Convert to task` dropdown item is clicked', () => {
    jest.spyOn(eventHub, '$emit');

    findConvertToTaskItem().vm.$emit('click');

    expect(eventHub.$emit).toHaveBeenCalledWith('convert-task-list-item', '3:1-3:10');
  });

  it('emits event when `Delete` dropdown item is clicked', () => {
    jest.spyOn(eventHub, '$emit');

    findDeleteItem().vm.$emit('click');

    expect(eventHub.$emit).toHaveBeenCalledWith('delete-task-list-item', '3:1-3:10');
  });
});