Welcome to mirror list, hosted at ThFree Co, Russian Federation.

available_agents_dropwdown_spec.js « components « clusters_list « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1ec8764705c21b6f8cf87786f280bd837f2ceffd (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import { GlCollapsibleListbox, GlButton } from '@gitlab/ui';
import { nextTick } from 'vue';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import AvailableAgentsDropdown from '~/clusters_list/components/available_agents_dropdown.vue';
import { I18N_AVAILABLE_AGENTS_DROPDOWN } from '~/clusters_list/constants';

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

  const configuredAgent = 'configured-agent';
  const searchAgentName = 'search-agent';
  const newAgentName = 'new-agent';

  const i18n = I18N_AVAILABLE_AGENTS_DROPDOWN;
  const findDropdown = () => wrapper.findComponent(GlCollapsibleListbox);
  const findCreateButton = () => wrapper.findComponent(GlButton);

  const createWrapper = ({ propsData }) => {
    wrapper = shallowMountExtended(AvailableAgentsDropdown, {
      propsData,
      stubs: { GlCollapsibleListbox },
    });
  };

  describe('there are agents available', () => {
    const propsData = {
      availableAgents: [configuredAgent, searchAgentName, 'test-agent'],
      isRegistering: false,
    };

    beforeEach(() => {
      createWrapper({ propsData });
    });

    it('prompts to select an agent', () => {
      expect(findDropdown().props('toggleText')).toBe(i18n.selectAgent);
    });

    describe('search agent', () => {
      it('renders search button', () => {
        expect(findDropdown().props('searchable')).toBe(true);
      });

      it('renders all agents when search term is empty', () => {
        expect(findDropdown().props('items')).toHaveLength(3);
      });

      it('renders only the agent searched for when the search item exists', async () => {
        findDropdown().vm.$emit('search', searchAgentName);
        await nextTick();

        expect(findDropdown().props('items')).toMatchObject([
          { text: searchAgentName, value: searchAgentName },
        ]);
      });

      describe('create button', () => {
        it.each`
          condition            | search             | createButtonRendered
          ${'is rendered'}     | ${newAgentName}    | ${true}
          ${'is not rendered'} | ${''}              | ${false}
          ${'is not rendered'} | ${searchAgentName} | ${false}
        `('$condition when search is "$search"', async ({ search, createButtonRendered }) => {
          findDropdown().vm.$emit('search', search);
          await nextTick();

          expect(findCreateButton().exists()).toBe(createButtonRendered);
        });
      });
    });

    describe('select existing agent configuration', () => {
      beforeEach(() => {
        findDropdown().vm.$emit('select', configuredAgent);
      });

      it('emits `agentSelected` with the name of the clicked agent', () => {
        expect(wrapper.emitted('agentSelected')).toEqual([[configuredAgent]]);
      });

      it('marks the clicked item as selected', () => {
        expect(findDropdown().props('toggleText')).toBe(configuredAgent);
      });
    });

    describe('create new agent configuration', () => {
      beforeEach(async () => {
        findDropdown().vm.$emit('search', newAgentName);
        await nextTick();
        findCreateButton().vm.$emit('click');
      });

      it('emits agentSelected with the name of the clicked agent', () => {
        expect(wrapper.emitted('agentSelected')).toEqual([[newAgentName]]);
      });

      it('marks the clicked item as selected', () => {
        expect(findDropdown().props('toggleText')).toBe(newAgentName);
      });
    });

    describe('click enter to register new agent without configuration', () => {
      beforeEach(async () => {
        const dropdown = findDropdown();
        dropdown.vm.$emit('search', newAgentName);
        await nextTick();
        await dropdown.trigger('keydown.enter');
      });

      it('emits agentSelected with the name of the clicked agent', () => {
        expect(wrapper.emitted('agentSelected')).toEqual([[newAgentName]]);
      });

      it('marks the clicked item as selected', () => {
        expect(findDropdown().props('toggleText')).toBe(newAgentName);
      });
    });
  });

  describe('registration in progress', () => {
    const propsData = {
      availableAgents: [configuredAgent],
      isRegistering: true,
    };

    beforeEach(() => {
      createWrapper({ propsData });
    });

    it('updates the text in the dropdown', () => {
      expect(findDropdown().props('toggleText')).toBe(i18n.registeringAgent);
    });

    it('displays a loading icon', () => {
      expect(findDropdown().props('loading')).toBe(true);
    });
  });
});