summaryrefslogtreecommitdiff
path: root/spec/frontend/feature_flags/store/gitlab_user_lists/getters_spec.js
blob: e267cd59f5001f6bc688df049e34aab7b514c5a8 (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
import {
  userListOptions,
  hasUserLists,
  isLoading,
  hasError,
} from '~/feature_flags/store/gitlab_user_list/getters';
import statuses from '~/feature_flags/store/gitlab_user_list/status';
import createState from '~/feature_flags/store/gitlab_user_list/state';
import { userList } from '../../mock_data';

describe('~/feature_flags/store/gitlab_user_list/getters', () => {
  let mockedState;

  beforeEach(() => {
    mockedState = createState({ projectId: '8' });
    mockedState.userLists = [userList];
  });

  describe('userListOption', () => {
    it('should return user lists in a way usable by a dropdown', () => {
      expect(userListOptions(mockedState)).toEqual([{ value: userList.id, text: userList.name }]);
    });

    it('should return an empty array if there are no lists', () => {
      mockedState.userLists = [];
      expect(userListOptions(mockedState)).toEqual([]);
    });
  });

  describe('hasUserLists', () => {
    it.each`
      userLists     | status            | result
      ${[userList]} | ${statuses.IDLE}  | ${true}
      ${[]}         | ${statuses.IDLE}  | ${false}
      ${[]}         | ${statuses.START} | ${true}
    `(
      'should return $result if there are $userLists.length user lists and the status is $status',
      ({ userLists, status, result }) => {
        mockedState.userLists = userLists;
        mockedState.status = status;
        expect(hasUserLists(mockedState)).toBe(result);
      },
    );
  });

  describe('isLoading', () => {
    it.each`
      status              | result
      ${statuses.LOADING} | ${true}
      ${statuses.ERROR}   | ${false}
      ${statuses.IDLE}    | ${false}
    `('should return $result if the status is "$status"', ({ status, result }) => {
      mockedState.status = status;
      expect(isLoading(mockedState)).toBe(result);
    });
  });

  describe('hasError', () => {
    it.each`
      status              | result
      ${statuses.LOADING} | ${false}
      ${statuses.ERROR}   | ${true}
      ${statuses.IDLE}    | ${false}
    `('should return $result if the status is "$status"', ({ status, result }) => {
      mockedState.status = status;
      expect(hasError(mockedState)).toBe(result);
    });
  });
});