summaryrefslogtreecommitdiff
path: root/spec/frontend/users_select/utils_spec.js
blob: a09935d8a043d94e24d3e5b53523aef6e04ccbac (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
import $ from 'jquery';
import { getAjaxUsersSelectOptions, getAjaxUsersSelectParams } from '~/users_select/utils';

const options = {
  fooBar: 'baz',
  activeUserId: 1,
};

describe('getAjaxUsersSelectOptions', () => {
  it('returns options built from select data attributes', () => {
    const $select = $('<select />', { 'data-foo-bar': 'baz', 'data-user-id': 1 });

    expect(
      getAjaxUsersSelectOptions($select, { fooBar: 'fooBar', activeUserId: 'user-id' }),
    ).toEqual(options);
  });
});

describe('getAjaxUsersSelectParams', () => {
  it('returns query parameters built from provided options', () => {
    expect(
      getAjaxUsersSelectParams(options, {
        foo_bar: 'fooBar',
        active_user_id: 'activeUserId',
        non_existent_key: 'nonExistentKey',
      }),
    ).toEqual({
      foo_bar: 'baz',
      active_user_id: 1,
      non_existent_key: null,
    });
  });
});