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

timeline_chart_spec.js « components « error_tracking « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f864d11804c4e8fecfcf39b593ddd22eb974c59a (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
import { GlChart } from '@gitlab/ui/dist/charts';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import TimelineChart from '~/error_tracking/components/timeline_chart.vue';

const MOCK_HEIGHT = 123;

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

  function mountComponent(timelineData = []) {
    wrapper = shallowMountExtended(TimelineChart, {
      stubs: { GlChart: true },
      propsData: {
        timelineData: [...timelineData],
        height: MOCK_HEIGHT,
      },
    });
  }

  beforeEach(() => {
    mountComponent();
  });

  it('renders the component', () => {
    expect(wrapper.exists()).toBe(true);
  });

  it('does not render a chart if timelineData is missing', () => {
    wrapper = shallowMountExtended(TimelineChart, {
      stubs: { GlChart: true },
      propsData: {
        timelineData: undefined,
        height: MOCK_HEIGHT,
      },
    });
    expect(wrapper.findComponent(GlChart).exists()).toBe(false);
  });

  it('renders a gl-chart', () => {
    expect(wrapper.findComponent(GlChart).exists()).toBe(true);
    expect(wrapper.findComponent(GlChart).props('height')).toBe(MOCK_HEIGHT);
  });

  describe('timeline-data', () => {
    describe.each([
      {
        mockItems: [
          [1686218400, 1],
          [1686222000, 2],
        ],
        expectedX: ['Jun 8, 2023 10:00am UTC', 'Jun 8, 2023 11:00am UTC'],
        expectedY: [1, 2],
        description: 'tuples with dates as timestamps in seconds',
      },
      {
        mockItems: [
          ['06-05-2023', 1],
          ['06-06-2023', 2],
        ],
        expectedX: ['Jun 5, 2023 12:00am UTC', 'Jun 6, 2023 12:00am UTC'],
        expectedY: [1, 2],
        description: 'tuples with non-numeric dates',
      },
      {
        mockItems: [
          { time: 1686218400, count: 1 },
          { time: 1686222000, count: 2 },
        ],
        expectedX: ['Jun 8, 2023 10:00am UTC', 'Jun 8, 2023 11:00am UTC'],
        expectedY: [1, 2],
        description: 'objects with dates as timestamps in seconds',
      },
      {
        mockItems: [
          { time: '06-05-2023', count: 1 },
          { time: '06-06-2023', count: 2 },
        ],
        expectedX: ['Jun 5, 2023 12:00am UTC', 'Jun 6, 2023 12:00am UTC'],
        expectedY: [1, 2],
        description: 'objects with non-numeric dates',
      },
    ])('when timeline-data items are $description', ({ mockItems, expectedX, expectedY }) => {
      it(`renders the chart correctly`, () => {
        mountComponent(mockItems);

        const chartOptions = wrapper.findComponent(GlChart).props('options');
        const xData = chartOptions.xAxis.data;
        const yData = chartOptions.series[0].data;
        expect(xData).toEqual(expectedX);
        expect(yData).toEqual(expectedY);
      });
    });
  });
});