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

subscriptions_page_spec.js « pages « subscriptions « jira_connect « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4956af76ead0983945c5ba212aa5b39a45e2bde9 (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
import { GlEmptyState, GlLoadingIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import SubscriptionsPage from '~/jira_connect/subscriptions/pages/subscriptions_page.vue';
import AddNamespaceButton from '~/jira_connect/subscriptions/components/add_namespace_button.vue';
import SubscriptionsList from '~/jira_connect/subscriptions/components/subscriptions_list.vue';
import createStore from '~/jira_connect/subscriptions/store';

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

  const findAddNamespaceButton = () => wrapper.findComponent(AddNamespaceButton);
  const findGlLoadingIcon = () => wrapper.findComponent(GlLoadingIcon);
  const findSubscriptionsList = () => wrapper.findComponent(SubscriptionsList);
  const findEmptyState = () => wrapper.findComponent(GlEmptyState);

  const createComponent = ({ props, initialState } = {}) => {
    store = createStore(initialState);

    wrapper = shallowMount(SubscriptionsPage, {
      store,
      propsData: { hasSubscriptions: false, ...props },
      stubs: {
        GlEmptyState,
      },
    });
  };

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

  describe('template', () => {
    describe.each`
      scenario                        | subscriptionsLoading | hasSubscriptions | expectSubscriptionsList | expectEmptyState
      ${'with subscriptions loading'} | ${true}              | ${false}         | ${false}                | ${false}
      ${'with subscriptions'}         | ${false}             | ${true}          | ${true}                 | ${false}
      ${'without subscriptions'}      | ${false}             | ${false}         | ${false}                | ${true}
    `(
      '$scenario',
      ({ subscriptionsLoading, hasSubscriptions, expectEmptyState, expectSubscriptionsList }) => {
        beforeEach(() => {
          createComponent({
            initialState: { subscriptionsLoading },
            props: {
              hasSubscriptions,
            },
          });
        });

        it(`${
          subscriptionsLoading ? 'does not render' : 'renders'
        } button to add namespace`, () => {
          expect(findAddNamespaceButton().exists()).toBe(!subscriptionsLoading);
        });

        it(`${subscriptionsLoading ? 'renders' : 'does not render'} GlLoadingIcon`, () => {
          expect(findGlLoadingIcon().exists()).toBe(subscriptionsLoading);
        });

        it(`${expectEmptyState ? 'renders' : 'does not render'} empty state`, () => {
          expect(findEmptyState().exists()).toBe(expectEmptyState);
        });

        it(`${expectSubscriptionsList ? 'renders' : 'does not render'} subscriptions list`, () => {
          expect(findSubscriptionsList().exists()).toBe(expectSubscriptionsList);
        });
      },
    );
  });
});