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

sidebar_assignees_spec.js « sidebar « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f1c13a5f8186793db765dd76708285bb048d5a15 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { shallowMount } from '@vue/test-utils';
import AxiosMockAdapter from 'axios-mock-adapter';
import axios from 'axios';
import SidebarAssignees from '~/sidebar/components/assignees/sidebar_assignees.vue';
import Assigness from '~/sidebar/components/assignees/assignees.vue';
import AssigneesRealtime from '~/sidebar/components/assignees/assignees_realtime.vue';
import SidebarMediator from '~/sidebar/sidebar_mediator';
import SidebarService from '~/sidebar/services/sidebar_service';
import SidebarStore from '~/sidebar/stores/sidebar_store';
import Mock from './mock_data';

describe('sidebar assignees', () => {
  let wrapper;
  let mediator;
  let axiosMock;
  const createComponent = (realTimeIssueSidebar = false, props) => {
    wrapper = shallowMount(SidebarAssignees, {
      propsData: {
        issuableIid: '1',
        mediator,
        field: '',
        projectPath: 'projectPath',
        changing: false,
        ...props,
      },
      provide: {
        glFeatures: {
          realTimeIssueSidebar,
        },
      },
      // Attaching to document is required because this component emits something from the parent element :/
      attachTo: document.body,
    });
  };

  beforeEach(() => {
    axiosMock = new AxiosMockAdapter(axios);
    mediator = new SidebarMediator(Mock.mediator);

    jest.spyOn(mediator, 'saveAssignees');
    jest.spyOn(mediator, 'assignYourself');
  });

  afterEach(() => {
    wrapper.destroy();
    wrapper = null;

    SidebarService.singleton = null;
    SidebarStore.singleton = null;
    SidebarMediator.singleton = null;
    axiosMock.restore();
  });

  it('calls the mediator when saves the assignees', () => {
    createComponent();

    expect(mediator.saveAssignees).not.toHaveBeenCalled();

    wrapper.vm.saveAssignees();

    expect(mediator.saveAssignees).toHaveBeenCalled();
  });

  it('calls the mediator when "assignSelf" method is called', () => {
    createComponent();

    expect(mediator.assignYourself).not.toHaveBeenCalled();
    expect(mediator.store.assignees.length).toBe(0);

    wrapper.vm.assignSelf();

    expect(mediator.assignYourself).toHaveBeenCalled();
    expect(mediator.store.assignees.length).toBe(1);
  });

  it('hides assignees until fetched', () => {
    createComponent();

    expect(wrapper.find(Assigness).exists()).toBe(false);

    wrapper.vm.store.isFetching.assignees = false;

    return wrapper.vm.$nextTick(() => {
      expect(wrapper.find(Assigness).exists()).toBe(true);
    });
  });

  describe('when realTimeIssueSidebar is turned on', () => {
    describe('when issuableType is issue', () => {
      it('finds AssigneesRealtime componeont', () => {
        createComponent(true);

        expect(wrapper.find(AssigneesRealtime).exists()).toBe(true);
      });
    });

    describe('when issuableType is MR', () => {
      it('does not find AssigneesRealtime componeont', () => {
        createComponent(true, { issuableType: 'MR' });

        expect(wrapper.find(AssigneesRealtime).exists()).toBe(false);
      });
    });
  });

  describe('when realTimeIssueSidebar is turned off', () => {
    it('does not find AssigneesRealtime', () => {
      createComponent(false, { issuableType: 'issue' });

      expect(wrapper.find(AssigneesRealtime).exists()).toBe(false);
    });
  });
});