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

app_spec.js « components « jira_connect « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: be990d5061c5a61807a66689763d196b0de5de71 (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
import Vue from 'vue';
import Vuex from 'vuex';
import { shallowMount } from '@vue/test-utils';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import { GlAlert } from '@gitlab/ui';
import JiraConnectApp from '~/jira_connect/components/app.vue';
import createStore from '~/jira_connect/store';
import { SET_ERROR_MESSAGE } from '~/jira_connect/store/mutation_types';

Vue.use(Vuex);

describe('JiraConnectApp', () => {
  let wrapper;
  let store;

  const findAlert = () => wrapper.findComponent(GlAlert);
  const findHeader = () => wrapper.findByTestId('new-jira-connect-ui-heading');
  const findHeaderText = () => findHeader().text();

  const createComponent = (options = {}) => {
    store = createStore();

    wrapper = extendedWrapper(
      shallowMount(JiraConnectApp, {
        store,
        provide: {
          glFeatures: { newJiraConnectUi: true },
        },
        ...options,
      }),
    );
  };

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

  describe('template', () => {
    it('renders new UI', () => {
      createComponent();

      expect(findHeader().exists()).toBe(true);
      expect(findHeaderText()).toBe('Linked namespaces');
    });

    describe('newJiraConnectUi is false', () => {
      it('does not render new UI', () => {
        createComponent({
          provide: {
            glFeatures: { newJiraConnectUi: false },
          },
        });

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

    it.each`
      errorMessage    | errorShouldRender
      ${'Test error'} | ${true}
      ${''}           | ${false}
      ${undefined}    | ${false}
    `(
      'renders correct alert when errorMessage is `$errorMessage`',
      async ({ errorMessage, errorShouldRender }) => {
        createComponent();

        store.commit(SET_ERROR_MESSAGE, errorMessage);
        await wrapper.vm.$nextTick();

        expect(findAlert().exists()).toBe(errorShouldRender);
        if (errorShouldRender) {
          expect(findAlert().isVisible()).toBe(errorShouldRender);
          expect(findAlert().html()).toContain(errorMessage);
        }
      },
    );
  });
});