summaryrefslogtreecommitdiff
path: root/spec/frontend/feature_flags/components/strategies/gitlab_user_list_spec.js
blob: 014c6dd98b9296bfcc13adebcce250a547f5b586 (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
import { mount } from '@vue/test-utils';
import { GlFormSelect } from '@gitlab/ui';
import GitlabUserList from '~/feature_flags/components/strategies/gitlab_user_list.vue';
import { userListStrategy, userList } from '../../mock_data';

const DEFAULT_PROPS = {
  strategy: userListStrategy,
  userLists: [userList],
};

describe('~/feature_flags/components/strategies/gitlab_user_list.vue', () => {
  let wrapper;

  const factory = (props = {}) =>
    mount(GitlabUserList, { propsData: { ...DEFAULT_PROPS, ...props } });

  describe('with user lists', () => {
    beforeEach(() => {
      wrapper = factory();
    });

    it('should show the input for userListId with the correct value', () => {
      const inputWrapper = wrapper.find(GlFormSelect);
      expect(inputWrapper.exists()).toBe(true);
      expect(inputWrapper.element.value).toBe('2');
    });

    it('should emit a change event when altering the userListId', () => {
      const inputWrapper = wrapper.find(GitlabUserList);
      inputWrapper.vm.$emit('change', {
        userListId: '3',
      });
      expect(wrapper.emitted('change')).toEqual([
        [
          {
            userListId: '3',
          },
        ],
      ]);
    });
  });
  describe('without user lists', () => {
    beforeEach(() => {
      wrapper = factory({ userLists: [] });
    });

    it('should display a message that there are no user lists', () => {
      expect(wrapper.text()).toContain('There are no configured user lists');
    });
  });
});