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

config_toggle_spec.js « components « boards « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5330721451e67cecccd5684fe9fa4091749bf456 (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
55
import Vuex from 'vuex';
import Vue from 'vue';
import { shallowMount } from '@vue/test-utils';
import { GlButton } from '@gitlab/ui';
import ConfigToggle from '~/boards/components/config_toggle.vue';
import eventHub from '~/boards/eventhub';
import store from '~/boards/stores';
import { mockTracking } from 'helpers/tracking_helper';

describe('ConfigToggle', () => {
  let wrapper;

  Vue.use(Vuex);

  const createComponent = (provide = {}) =>
    shallowMount(ConfigToggle, {
      store,
      provide: {
        canAdminList: true,
        ...provide,
      },
    });

  const findButton = () => wrapper.findComponent(GlButton);

  it('renders a button with label `View scope` when `canAdminList` is `false`', () => {
    wrapper = createComponent({ canAdminList: false });
    expect(findButton().text()).toBe('View scope');
  });

  it('renders a button with label `Edit board` when `canAdminList` is `true`', () => {
    wrapper = createComponent();
    expect(findButton().text()).toBe('Edit board');
  });

  it('emits `showBoardModal` when button is clicked', () => {
    const eventHubSpy = jest.spyOn(eventHub, '$emit');
    wrapper = createComponent();

    findButton().vm.$emit('click', { preventDefault: () => {} });

    expect(eventHubSpy).toHaveBeenCalledWith('showBoardModal', 'edit');
  });

  it('tracks clicking the button', () => {
    const trackingSpy = mockTracking(undefined, wrapper.element, jest.spyOn);
    wrapper = createComponent();

    findButton().vm.$emit('click', { preventDefault: () => {} });

    expect(trackingSpy).toHaveBeenCalledWith(undefined, 'click_button', {
      label: 'edit_board',
    });
  });
});