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

activity_bar_spec.js « components « ide « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a97e883a8bf2455541d558c33c3cc8b8ce2ca61b (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
import { GlBadge } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import ActivityBar from '~/ide/components/activity_bar.vue';
import { leftSidebarViews } from '~/ide/constants';
import { createStore } from '~/ide/stores';

describe('IDE ActivityBar component', () => {
  let wrapper;
  let store;

  const findChangesBadge = () => wrapper.findComponent(GlBadge);

  const mountComponent = (state) => {
    store = createStore();
    store.replaceState({
      ...store.state,
      projects: { abcproject: { web_url: 'testing' } },
      currentProjectId: 'abcproject',
      ...state,
    });

    wrapper = shallowMount(ActivityBar, { store });
  };

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

  describe('updateActivityBarView', () => {
    beforeEach(() => {
      mountComponent();
      jest.spyOn(wrapper.vm, 'updateActivityBarView').mockImplementation(() => {});
    });

    it('calls updateActivityBarView with edit value on click', () => {
      wrapper.find('.js-ide-edit-mode').trigger('click');

      expect(wrapper.vm.updateActivityBarView).toHaveBeenCalledWith(leftSidebarViews.edit.name);
    });

    it('calls updateActivityBarView with commit value on click', () => {
      wrapper.find('.js-ide-commit-mode').trigger('click');

      expect(wrapper.vm.updateActivityBarView).toHaveBeenCalledWith(leftSidebarViews.commit.name);
    });

    it('calls updateActivityBarView with review value on click', () => {
      wrapper.find('.js-ide-review-mode').trigger('click');

      expect(wrapper.vm.updateActivityBarView).toHaveBeenCalledWith(leftSidebarViews.review.name);
    });
  });

  describe('active item', () => {
    it('sets edit item active', () => {
      mountComponent();

      expect(wrapper.find('.js-ide-edit-mode').classes()).toContain('active');
    });

    it('sets commit item active', () => {
      mountComponent({ currentActivityView: leftSidebarViews.commit.name });

      expect(wrapper.find('.js-ide-commit-mode').classes()).toContain('active');
    });
  });

  describe('changes badge', () => {
    it('is rendered when files are staged', () => {
      mountComponent({ stagedFiles: [{ path: '/path/to/file' }] });

      expect(findChangesBadge().exists()).toBe(true);
      expect(findChangesBadge().text()).toBe('1');
    });

    it('is not rendered when no changes are present', () => {
      mountComponent();

      expect(findChangesBadge().exists()).toBe(false);
    });
  });
});