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

add_request_spec.js « components « performance_bar « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5460feb66fec462bd22cc732761b8d5c7bdb731f (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
import { mount } from '@vue/test-utils';
import { nextTick } from 'vue';
import { GlFormInput, GlButton } from '@gitlab/ui';
import AddRequest from '~/performance_bar/components/add_request.vue';

describe('add request form', () => {
  let wrapper;

  const findGlFormInput = () => wrapper.findComponent(GlFormInput);
  const findGlButton = () => wrapper.findComponent(GlButton);

  beforeEach(() => {
    wrapper = mount(AddRequest);
  });

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

  it('hides the input on load', () => {
    expect(findGlFormInput().exists()).toBe(false);
  });

  describe('when clicking the button', () => {
    beforeEach(async () => {
      findGlButton().trigger('click');
      await nextTick();
    });

    it('shows the form', () => {
      expect(findGlFormInput().exists()).toBe(true);
    });

    describe('when pressing escape', () => {
      beforeEach(async () => {
        findGlFormInput().trigger('keyup.esc');
        await nextTick();
      });

      it('hides the input', () => {
        expect(findGlFormInput().exists()).toBe(false);
      });
    });

    describe('when submitting the form', () => {
      beforeEach(async () => {
        findGlFormInput().setValue('http://gitlab.example.com/users/root/calendar.json');
        await nextTick();
        findGlFormInput().trigger('keyup.enter');
        await nextTick();
      });

      it('emits an event to add the request', () => {
        expect(wrapper.emitted()['add-request']).toHaveLength(1);
        expect(wrapper.emitted()['add-request'][0]).toEqual([
          'http://gitlab.example.com/users/root/calendar.json',
        ]);
      });

      it('hides the input', () => {
        expect(findGlFormInput().exists()).toBe(false);
      });

      it('clears the value for next time', async () => {
        findGlButton().trigger('click');
        await nextTick();
        expect(findGlFormInput().text()).toEqual('');
      });
    });
  });
});