summaryrefslogtreecommitdiff
path: root/spec/frontend/import_entities/components/group_dropdown_spec.js
blob: b896437ecb2691273a5a427020ae77ae70e9370a (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
import { GlSearchBoxByType, GlDropdown } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue';
import GroupDropdown from '~/import_entities/components/group_dropdown.vue';

describe('Import entities group dropdown component', () => {
  let wrapper;
  let namespacesTracker;

  const createComponent = (propsData) => {
    namespacesTracker = jest.fn();

    wrapper = shallowMount(GroupDropdown, {
      scopedSlots: {
        default: namespacesTracker,
      },
      stubs: { GlDropdown },
      propsData,
    });
  };

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

  it('passes namespaces from props to default slot', () => {
    const namespaces = [
      { id: 1, fullPath: 'ns1' },
      { id: 2, fullPath: 'ns2' },
    ];
    createComponent({ namespaces });

    expect(namespacesTracker).toHaveBeenCalledWith({ namespaces });
  });

  it('filters namespaces based on user input', async () => {
    const namespaces = [
      { id: 1, fullPath: 'match1' },
      { id: 2, fullPath: 'some unrelated' },
      { id: 3, fullPath: 'match2' },
    ];
    createComponent({ namespaces });

    namespacesTracker.mockReset();
    wrapper.findComponent(GlSearchBoxByType).vm.$emit('input', 'match');

    await nextTick();

    expect(namespacesTracker).toHaveBeenCalledWith({
      namespaces: [
        { id: 1, fullPath: 'match1' },
        { id: 3, fullPath: 'match2' },
      ],
    });
  });
});