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

log_control_buttons_spec.js « components « logs « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 55b28445786df26519c2a0873bd06711d56a9f8d (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
import { shallowMount } from '@vue/test-utils';
import { GlButton } from '@gitlab/ui';
import LogControlButtons from '~/logs/components/log_control_buttons.vue';

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

  const findScrollToTop = () => wrapper.find('.js-scroll-to-top');
  const findScrollToBottom = () => wrapper.find('.js-scroll-to-bottom');
  const findRefreshBtn = () => wrapper.find('.js-refresh-log');

  const initWrapper = (opts) => {
    wrapper = shallowMount(LogControlButtons, {
      listeners: {
        scrollUp: () => {},
        scrollDown: () => {},
      },
      ...opts,
    });
  };

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

  it('displays UI elements', () => {
    initWrapper();

    expect(findScrollToTop().is(GlButton)).toBe(true);
    expect(findScrollToBottom().is(GlButton)).toBe(true);
    expect(findRefreshBtn().is(GlButton)).toBe(true);
  });

  it('emits a `refresh` event on click on `refresh` button', () => {
    initWrapper();

    // An `undefined` value means no event was emitted
    expect(wrapper.emitted('refresh')).toBe(undefined);

    findRefreshBtn().vm.$emit('click');

    return wrapper.vm.$nextTick().then(() => {
      expect(wrapper.emitted('refresh')).toHaveLength(1);
    });
  });

  describe('when scrolling actions are enabled', () => {
    beforeEach(() => {
      // mock scrolled to the middle of a long page
      initWrapper();
      return wrapper.vm.$nextTick();
    });

    it('click on "scroll to top" scrolls up', () => {
      expect(findScrollToTop().attributes('disabled')).toBeUndefined();

      findScrollToTop().vm.$emit('click');

      expect(wrapper.emitted('scrollUp')).toHaveLength(1);
    });

    it('click on "scroll to bottom" scrolls down', () => {
      expect(findScrollToBottom().attributes('disabled')).toBeUndefined();

      findScrollToBottom().vm.$emit('click');

      expect(wrapper.emitted('scrollDown')).toHaveLength(1);
    });
  });

  describe('when scrolling actions are disabled', () => {
    beforeEach(() => {
      initWrapper({ listeners: {} });
      return wrapper.vm.$nextTick();
    });

    it('buttons are disabled', () => {
      return wrapper.vm.$nextTick(() => {
        expect(findScrollToTop().exists()).toBe(false);
        expect(findScrollToBottom().exists()).toBe(false);
        // This should be enabled when gitlab-ui contains:
        // https://gitlab.com/gitlab-org/gitlab-ui/-/merge_requests/1149
        // expect(findScrollToBottom().is('[disabled]')).toBe(true);
      });
    });
  });
});