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

pipeline_editor_file_nav_spec.js « file-nav « components « pipeline_editor « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a61796dbed2bcb2bba1fc858f41e6818b0bf3b1e (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import { shallowMount } from '@vue/test-utils';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import createMockApollo from 'helpers/mock_apollo_helper';
import BranchSwitcher from '~/pipeline_editor/components/file_nav/branch_switcher.vue';
import PipelineEditorFileNav from '~/pipeline_editor/components/file_nav/pipeline_editor_file_nav.vue';
import FileTreePopover from '~/pipeline_editor/components/popovers/file_tree_popover.vue';
import getAppStatus from '~/pipeline_editor/graphql/queries/client/app_status.query.graphql';
import {
  EDITOR_APP_STATUS_EMPTY,
  EDITOR_APP_STATUS_LOADING,
  EDITOR_APP_STATUS_VALID,
} from '~/pipeline_editor/constants';

Vue.use(VueApollo);

describe('Pipeline editor file nav', () => {
  let wrapper;

  const mockApollo = createMockApollo();

  const createComponent = ({
    appStatus = EDITOR_APP_STATUS_VALID,
    isNewCiConfigFile = false,
    pipelineEditorFileTree = false,
  } = {}) => {
    mockApollo.clients.defaultClient.cache.writeQuery({
      query: getAppStatus,
      data: {
        app: {
          __typename: 'PipelineEditorApp',
          status: appStatus,
        },
      },
    });

    wrapper = extendedWrapper(
      shallowMount(PipelineEditorFileNav, {
        apolloProvider: mockApollo,
        provide: {
          glFeatures: {
            pipelineEditorFileTree,
          },
        },
        propsData: {
          isNewCiConfigFile,
        },
      }),
    );
  };

  const findBranchSwitcher = () => wrapper.findComponent(BranchSwitcher);
  const findFileTreeBtn = () => wrapper.findByTestId('file-tree-toggle');
  const findPopoverContainer = () => wrapper.findComponent(FileTreePopover);

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

  describe('template', () => {
    beforeEach(() => {
      createComponent();
    });

    it('renders the branch switcher', () => {
      expect(findBranchSwitcher().exists()).toBe(true);
    });

    it('does not render the file tree button', () => {
      expect(findFileTreeBtn().exists()).toBe(false);
    });

    it('does not render the file tree popover', () => {
      expect(findPopoverContainer().exists()).toBe(false);
    });
  });

  describe('with pipelineEditorFileTree feature flag ON', () => {
    describe('when editor is in the empty state', () => {
      beforeEach(() => {
        createComponent({
          appStatus: EDITOR_APP_STATUS_EMPTY,
          isNewCiConfigFile: false,
          pipelineEditorFileTree: true,
        });
      });

      it('does not render the file tree button', () => {
        expect(findFileTreeBtn().exists()).toBe(false);
      });

      it('does not render the file tree popover', () => {
        expect(findPopoverContainer().exists()).toBe(false);
      });
    });

    describe('when user is about to create their config file for the first time', () => {
      beforeEach(() => {
        createComponent({
          appStatus: EDITOR_APP_STATUS_VALID,
          isNewCiConfigFile: true,
          pipelineEditorFileTree: true,
        });
      });

      it('does not render the file tree button', () => {
        expect(findFileTreeBtn().exists()).toBe(false);
      });

      it('does not render the file tree popover', () => {
        expect(findPopoverContainer().exists()).toBe(false);
      });
    });

    describe('when app is in a global loading state', () => {
      it('renders the file tree button with a loading icon', () => {
        createComponent({
          appStatus: EDITOR_APP_STATUS_LOADING,
          isNewCiConfigFile: false,
          pipelineEditorFileTree: true,
        });

        expect(findFileTreeBtn().exists()).toBe(true);
        expect(findFileTreeBtn().attributes('loading')).toBe('true');
      });
    });

    describe('when editor has a non-empty config file open', () => {
      beforeEach(() => {
        createComponent({
          appStatus: EDITOR_APP_STATUS_VALID,
          isNewCiConfigFile: false,
          pipelineEditorFileTree: true,
        });
      });

      it('renders the file tree button', () => {
        expect(findFileTreeBtn().exists()).toBe(true);
        expect(findFileTreeBtn().props('icon')).toBe('file-tree');
      });

      it('renders the file tree popover', () => {
        expect(findPopoverContainer().exists()).toBe(true);
      });

      it('file tree button emits toggle-file-tree event', () => {
        expect(wrapper.emitted('toggle-file-tree')).toBe(undefined);

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

        expect(wrapper.emitted('toggle-file-tree')).toHaveLength(1);
      });
    });
  });
});