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

resizable_chart_container_spec.js « resizable_chart « components « vue_shared « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 40f0c0f29f25089c67a44f72d8c13c4f126b30a9 (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
import { mount } from '@vue/test-utils';
import $ from 'jquery';
import Vue from 'vue';
import ResizableChartContainer from '~/vue_shared/components/resizable_chart/resizable_chart_container.vue';

jest.mock('~/lib/utils/common_utils', () => ({
  debounceByAnimationFrame(callback) {
    return jest.spyOn({ callback }, 'callback');
  },
}));

describe('Resizable Chart Container', () => {
  let wrapper;

  beforeEach(() => {
    wrapper = mount(ResizableChartContainer, {
      scopedSlots: {
        default: `
          <template #default="{ width, height }">
            <div class="slot">
              <span class="width">{{width}}</span>
              <span class="height">{{height}}</span>
            </div>
          </template>
        `,
      },
    });
  });

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

  it('renders the component', () => {
    expect(wrapper.element).toMatchSnapshot();
  });

  it('updates the slot width and height props', () => {
    const width = 1920;
    const height = 1080;

    // JSDOM mocks and sets clientWidth/clientHeight to 0 so we set manually
    wrapper.vm.$refs.chartWrapper = { clientWidth: width, clientHeight: height };

    $(document).trigger('content.resize');

    return Vue.nextTick().then(() => {
      const widthNode = wrapper.find('.slot > .width');
      const heightNode = wrapper.find('.slot > .height');

      expect(parseInt(widthNode.text(), 10)).toEqual(width);
      expect(parseInt(heightNode.text(), 10)).toEqual(height);
    });
  });

  it('calls onResize on manual resize', () => {
    $(document).trigger('content.resize');
    expect(wrapper.vm.debouncedResize).toHaveBeenCalled();
  });

  it('calls onResize on page resize', () => {
    window.dispatchEvent(new Event('resize'));
    expect(wrapper.vm.debouncedResize).toHaveBeenCalled();
  });
});