summaryrefslogtreecommitdiff
path: root/spec/frontend/invite_members/components/user_limit_notification_spec.js
blob: c779cf2ee3f9bf8dd2d54b7545abc757fc827c4d (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 { GlAlert, GlSprintf } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import UserLimitNotification from '~/invite_members/components/user_limit_notification.vue';

describe('UserLimitNotification', () => {
  let wrapper;

  const findAlert = () => wrapper.findComponent(GlAlert);

  const createComponent = (providers = {}) => {
    wrapper = shallowMountExtended(UserLimitNotification, {
      provide: {
        name: 'my group',
        newTrialRegistrationPath: 'newTrialRegistrationPath',
        purchasePath: 'purchasePath',
        freeUsersLimit: 5,
        membersCount: 1,
        ...providers,
      },
      stubs: { GlSprintf },
    });
  };

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

  describe('when limit is not reached', () => {
    beforeEach(() => {
      createComponent();
    });

    it('renders empty block', () => {
      expect(findAlert().exists()).toBe(false);
    });
  });

  describe('when close to limit', () => {
    beforeEach(() => {
      createComponent({ membersCount: 3 });
    });

    it("renders user's limit notification", () => {
      const alert = findAlert();

      expect(alert.attributes('title')).toEqual(
        'You only have space for 2 more members in my group',
      );

      expect(alert.text()).toEqual(
        'To get more members an owner of this namespace can start a trial or upgrade to a paid tier.',
      );
    });
  });

  describe('when limit is reached', () => {
    beforeEach(() => {
      createComponent({ membersCount: 5 });
    });

    it("renders user's limit notification", () => {
      const alert = findAlert();

      expect(alert.attributes('title')).toEqual("You've reached your 5 members limit for my group");

      expect(alert.text()).toEqual(
        'New members will be unable to participate. You can manage your members by removing ones you no longer need. To get more members an owner of this namespace can start a trial or upgrade to a paid tier.',
      );
    });
  });
});