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

new_top_level_group_alert_spec.js « components « groups « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: db9a5c7b16bf0d042460ecc6d1c6b6e1d6c2e658 (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
import { shallowMount } from '@vue/test-utils';
import NewTopLevelGroupAlert from '~/groups/components/new_top_level_group_alert.vue';
import { makeMockUserCalloutDismisser } from 'helpers/mock_user_callout_dismisser';
import { helpPagePath } from '~/helpers/help_page_helper';

describe('NewTopLevelGroupAlert', () => {
  let wrapper;
  let userCalloutDismissSpy;

  const findAlert = () => wrapper.findComponent({ ref: 'newTopLevelAlert' });
  const createSubGroupPath = '/groups/new?parent_id=1#create-group-pane';

  const createComponent = ({ shouldShowCallout = true } = {}) => {
    userCalloutDismissSpy = jest.fn();

    wrapper = shallowMount(NewTopLevelGroupAlert, {
      provide: {
        createSubGroupPath,
      },
      stubs: {
        UserCalloutDismisser: makeMockUserCalloutDismisser({
          dismiss: userCalloutDismissSpy,
          shouldShowCallout,
        }),
      },
    });
  };

  beforeEach(() => {
    createComponent();
  });

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

  describe('when the component is created', () => {
    beforeEach(() => {
      createComponent({
        shouldShowCallout: true,
      });
    });

    it('renders a button with a link to create a new sub-group', () => {
      expect(findAlert().props('primaryButtonText')).toBe(
        NewTopLevelGroupAlert.i18n.primaryBtnText,
      );
      expect(findAlert().props('primaryButtonLink')).toBe(
        helpPagePath('user/group/subgroups/index'),
      );
    });
  });

  describe('dismissing the alert', () => {
    beforeEach(() => {
      findAlert().vm.$emit('dismiss');
    });

    it('calls the dismiss callback', () => {
      expect(userCalloutDismissSpy).toHaveBeenCalled();
    });
  });

  describe('when the alert has been dismissed', () => {
    beforeEach(() => {
      createComponent({
        shouldShowCallout: false,
      });
    });

    it('does not show the alert', () => {
      expect(findAlert().exists()).toBe(false);
    });
  });
});