@gitlab/ui 32.41.0 → 32.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/components/base/token_selector/token_selector.documentation.js +2 -106
  3. package/dist/components/base/token_selector/token_selector.js +85 -1
  4. package/dist/components/base/tooltip/tooltip.documentation.js +2 -6
  5. package/dist/components/charts/area/area.js +1 -1
  6. package/dist/components/charts/discrete_scatter/discrete_scatter.js +1 -1
  7. package/dist/components/charts/line/line.js +1 -1
  8. package/dist/utility_classes.css +1 -1
  9. package/dist/utility_classes.css.map +1 -1
  10. package/documentation/documented_stories.js +2 -0
  11. package/package.json +13 -13
  12. package/src/components/base/accordion/accordion.spec.js +0 -4
  13. package/src/components/base/accordion/accordion_item.spec.js +0 -4
  14. package/src/components/base/alert/alert.spec.js +0 -4
  15. package/src/components/base/avatar_labeled/avatar_labeled.spec.js +0 -2
  16. package/src/components/base/avatars_inline/avatars_inline.spec.js +0 -2
  17. package/src/components/base/badge/badge.spec.js +0 -2
  18. package/src/components/base/broadcast_message/broadcast_message.spec.js +0 -4
  19. package/src/components/base/button/button.spec.js +0 -5
  20. package/src/components/base/card/card.spec.js +0 -5
  21. package/src/components/base/carousel/carousel.spec.js +0 -4
  22. package/src/components/base/collapse/collapse.spec.js +0 -4
  23. package/src/components/base/datepicker/datepicker.spec.js +0 -4
  24. package/src/components/base/daterange_picker/daterange_picker.spec.js +0 -5
  25. package/src/components/base/drawer/drawer.spec.js +0 -4
  26. package/src/components/base/dropdown/dropdown.spec.js +0 -2
  27. package/src/components/base/dropdown/dropdown_item.spec.js +0 -2
  28. package/src/components/base/filtered_search/filtered_search.spec.js +0 -10
  29. package/src/components/base/filtered_search/filtered_search_suggestion.spec.js +0 -5
  30. package/src/components/base/filtered_search/filtered_search_suggestion_list.spec.js +0 -5
  31. package/src/components/base/filtered_search/filtered_search_term.spec.js +0 -5
  32. package/src/components/base/filtered_search/filtered_search_token.spec.js +0 -5
  33. package/src/components/base/form/form_checkbox_tree/form_checkbox_tree.spec.js +0 -5
  34. package/src/components/base/form/form_combobox/form_combobox.spec.js +0 -4
  35. package/src/components/base/form/form_input/form_input.spec.js +0 -5
  36. package/src/components/base/form/form_input_group/form_input_group.spec.js +0 -4
  37. package/src/components/base/form/form_radio/form_radio.spec.js +0 -4
  38. package/src/components/base/form/form_radio_group/form_radio_group.spec.js +0 -4
  39. package/src/components/base/form/form_select/form_select.spec.js +0 -5
  40. package/src/components/base/form/form_textarea/form_textarea.spec.js +0 -5
  41. package/src/components/base/icon/icon.spec.js +0 -2
  42. package/src/components/base/infinite_scroll/infinite_scroll.spec.js +0 -1
  43. package/src/components/base/keyset_pagination/keyset_pagination.spec.js +0 -5
  44. package/src/components/base/label/label.spec.js +0 -4
  45. package/src/components/base/link/link.spec.js +0 -5
  46. package/src/components/base/loading_icon/loading_icon.spec.js +0 -4
  47. package/src/components/base/modal/modal.spec.js +0 -1
  48. package/src/components/base/nav/nav.spec.js +0 -4
  49. package/src/components/base/nav/nav_item.spec.js +0 -4
  50. package/src/components/base/nav/nav_item_dropdown.spec.js +0 -4
  51. package/src/components/base/paginated_list/paginated_list.spec.js +0 -6
  52. package/src/components/base/pagination/pagination.spec.js +0 -1
  53. package/src/components/base/path/path.spec.js +0 -5
  54. package/src/components/base/popover/popover.spec.js +0 -5
  55. package/src/components/base/search_box_by_click/search_box_by_click.spec.js +0 -4
  56. package/src/components/base/search_box_by_type/search_box_by_type.spec.js +0 -5
  57. package/src/components/base/segmented_control/segmented_control.spec.js +0 -4
  58. package/src/components/base/skeleton_loader/skeleton_loader.spec.js +0 -5
  59. package/src/components/base/sorting/sorting.spec.js +0 -4
  60. package/src/components/base/sorting/sorting_item.spec.js +0 -4
  61. package/src/components/base/tabs/tabs/scrollable_tabs.spec.js +0 -5
  62. package/src/components/base/toggle/toggle.spec.js +0 -4
  63. package/src/components/base/token/token.spec.js +0 -4
  64. package/src/components/base/token_selector/token_container.spec.js +0 -2
  65. package/src/components/base/token_selector/token_selector.documentation.js +0 -137
  66. package/src/components/base/token_selector/token_selector.md +0 -6
  67. package/src/components/base/token_selector/token_selector.spec.js +0 -5
  68. package/src/components/base/token_selector/token_selector.stories.js +96 -113
  69. package/src/components/base/token_selector/token_selector.vue +89 -1
  70. package/src/components/base/token_selector/token_selector_dropdown.spec.js +0 -5
  71. package/src/components/base/tooltip/tooltip.documentation.js +0 -3
  72. package/src/components/base/tooltip/tooltip.md +3 -5
  73. package/src/components/base/tooltip/tooltip.spec.js +0 -5
  74. package/src/components/base/tooltip/tooltip.stories.js +49 -25
  75. package/src/components/base/tooltip/tooltip.vue +1 -0
  76. package/src/components/charts/area/area.spec.js +8 -24
  77. package/src/components/charts/area/area.vue +9 -12
  78. package/src/components/charts/bar/bar.spec.js +4 -11
  79. package/src/components/charts/chart/chart.spec.js +0 -4
  80. package/src/components/charts/column/column_chart.spec.js +0 -4
  81. package/src/components/charts/discrete_scatter/discrete_scatter.stories.js +1 -0
  82. package/src/components/charts/discrete_scatter/discrete_scatter.vue +5 -8
  83. package/src/components/charts/gauge/gauge.spec.js +2 -24
  84. package/src/components/charts/heatmap/heatmap.spec.js +6 -23
  85. package/src/components/charts/legend/legend.spec.js +8 -14
  86. package/src/components/charts/line/line.spec.js +19 -30
  87. package/src/components/charts/line/line.vue +3 -2
  88. package/src/components/charts/single_stat/single_stat.spec.js +0 -4
  89. package/src/components/charts/sparkline/sparkline.spec.js +9 -15
  90. package/src/components/charts/stacked_column/stacked_column.spec.js +0 -1
  91. package/src/components/shared_components/clear_icon_button/clear_icon_button.spec.js +0 -4
  92. package/src/components/shared_components/close_button/close_button.spec.js +0 -4
  93. package/src/components/utilities/friendly_wrap/friendly_wrap.spec.js +0 -4
  94. package/src/components/utilities/intersection_observer/intersection_observer.spec.js +1 -1
  95. package/src/components/utilities/sprintf/sprintf.spec.js +0 -4
  96. package/src/components/utilities/truncate/truncate.spec.js +10 -15
  97. package/src/directives/hover_load/hover_load.spec.js +0 -1
  98. package/src/directives/outside/outside.spec.js +0 -4
  99. package/src/directives/resize_observer/resize_observer.spec.js +0 -4
  100. package/src/directives/safe_html/safe_html.spec.js +0 -4
  101. package/src/directives/safe_link/safe_link.spec.js +0 -5
  102. package/src/scss/utilities.scss +14 -0
  103. package/src/scss/utility-mixins/spacing.scss +4 -0
  104. package/src/scss/utility-mixins/z-index.scss +4 -0
  105. package/dist/components/base/token_selector/examples/index.js +0 -19
  106. package/dist/components/base/token_selector/examples/token_selector.user_defined_tokens.example.js +0 -48
  107. package/dist/components/base/token_selector/examples/token_selector.users.example.js +0 -202
  108. package/dist/components/base/tooltip/examples/index.js +0 -31
  109. package/dist/components/base/tooltip/examples/tooltip.directive_bottom.example.js +0 -38
  110. package/dist/components/base/tooltip/examples/tooltip.directive_default.example.js +0 -38
  111. package/dist/components/base/tooltip/examples/tooltip.directive_left.example.js +0 -38
  112. package/dist/components/base/tooltip/examples/tooltip.directive_right.example.js +0 -38
  113. package/src/components/base/token_selector/examples/index.js +0 -22
  114. package/src/components/base/token_selector/examples/token_selector.user_defined_tokens.example.vue +0 -17
  115. package/src/components/base/token_selector/examples/token_selector.users.example.vue +0 -212
  116. package/src/components/base/tooltip/examples/index.js +0 -36
  117. package/src/components/base/tooltip/examples/tooltip.directive_bottom.example.vue +0 -7
  118. package/src/components/base/tooltip/examples/tooltip.directive_default.example.vue +0 -5
  119. package/src/components/base/tooltip/examples/tooltip.directive_left.example.vue +0 -7
  120. package/src/components/base/tooltip/examples/tooltip.directive_right.example.vue +0 -7
@@ -1,8 +1,6 @@
1
- ## Usage
2
-
3
1
  Using the tooltip component is recommended if you have HTML content.
4
2
  It is also currently required if the tooltip content needs to change while it's visible
5
- (see [this upstream issue]). In all other cases, please use the directive.
3
+ (see [this upstream issue][this upstream issue]). In all other cases, please use the directive.
6
4
 
7
5
  [this upstream issue]: https://github.com/bootstrap-vue/bootstrap-vue/issues/2142
8
6
 
@@ -43,11 +41,11 @@ export default {
43
41
 
44
42
  ## Directive attributes
45
43
 
46
- `v-gl-tooltip` directive uses the same attributes as [`v-b-tooltip`].
44
+ `v-gl-tooltip` directive uses the same attributes as [`v-b-tooltip`][`v-b-tooltip`].
47
45
 
48
46
  ## Under the hood
49
47
 
50
- Tooltip uses [`<b-tooltip>`] and [`v-b-tooltip`] internally.
48
+ Tooltip uses [`<b-tooltip>`][`<b-tooltip>`] and [`v-b-tooltip`][`v-b-tooltip`] internally.
51
49
 
52
50
  [`<b-tooltip>`]: https://bootstrap-vue.org/docs/components/tooltip
53
51
 
@@ -19,11 +19,6 @@ describe('GlTooltip', () => {
19
19
  createWrapper();
20
20
  });
21
21
 
22
- afterEach(() => {
23
- wrapper.destroy();
24
- wrapper = null;
25
- });
26
-
27
22
  it.each(tooltipActionEvents)('passes through the %s event to the bvTooltip instance', (event) => {
28
23
  wrapper.vm.$emit(event);
29
24
 
@@ -1,34 +1,58 @@
1
- import { withKnobs } from '@storybook/addon-knobs';
2
- import { documentedStoriesOf } from '../../../../documentation/documented_stories';
3
- import { GlTooltipDirective } from '../../../../index';
1
+ import { GlTooltip, GlTooltipDirective } from '../../../../index';
4
2
  import readme from './tooltip.md';
5
3
 
6
- const directives = {
7
- GlTooltip: GlTooltipDirective,
8
- };
9
-
10
4
  function makeTooltip(modifier = '') {
11
- return () => ({
12
- directives,
5
+ return {
6
+ directives: {
7
+ GlTooltip: GlTooltipDirective,
8
+ },
13
9
  template: `
14
- <div class="d-flex align-items-center justify-content-center p-5 m-5">
15
- <gl-button
16
- v-gl-tooltip${modifier}
17
- title="some tooltip text"
18
- >
19
- Tooltip
20
- </gl-button>
21
- </div>
22
- `,
10
+ <div class="gl-display-flex gl-align-items-center gl-justify-content-center gl-p-7 gl-m-7">
11
+ <gl-button
12
+ v-gl-tooltip${modifier}
13
+ title="some tooltip text"
14
+ >
15
+ Tooltip
16
+ </gl-button>
17
+ </div>
18
+ `,
23
19
  mounted() {
24
20
  this.$nextTick(() => this.$el.querySelector('button').focus());
25
21
  },
26
- });
22
+ };
27
23
  }
28
24
 
29
- documentedStoriesOf('base/tooltip', readme)
30
- .addDecorator(withKnobs)
31
- .add('top (default)', makeTooltip())
32
- .add('right', makeTooltip('.right'))
33
- .add('bottom', makeTooltip('.bottom'))
34
- .add('left', makeTooltip('.left'));
25
+ export const TopDefault = (args, argTypes) => ({
26
+ ...makeTooltip(),
27
+ props: Object.keys(argTypes),
28
+ });
29
+
30
+ export const Right = (args, argTypes) => ({
31
+ ...makeTooltip('.right'),
32
+ props: Object.keys(argTypes),
33
+ });
34
+
35
+ export const Bottom = (args, argTypes) => ({
36
+ ...makeTooltip('.bottom'),
37
+ props: Object.keys(argTypes),
38
+ });
39
+
40
+ export const Left = (args, argTypes) => ({
41
+ ...makeTooltip('.left'),
42
+ props: Object.keys(argTypes),
43
+ });
44
+
45
+ // A default export contains higher-level info about the component and the stories' settings.
46
+ export default {
47
+ title: 'base/tooltip',
48
+ component: GlTooltip,
49
+ parameters: {
50
+ bootstrapComponent: 'b-tooltip',
51
+ knobs: { disable: true },
52
+ docs: {
53
+ description: {
54
+ component: readme,
55
+ },
56
+ },
57
+ },
58
+ };
@@ -23,6 +23,7 @@ export default {
23
23
  :delay="$options.tooltipDelay"
24
24
  v-on="$listeners"
25
25
  >
26
+ <!-- @slot Tooltip content -->
26
27
  <slot></slot>
27
28
  </b-tooltip>
28
29
  </template>
@@ -5,6 +5,7 @@ import ChartLegend from '../legend/legend.vue';
5
5
  import AreaChart from './area.vue';
6
6
 
7
7
  import { LEGEND_LAYOUT_INLINE, LEGEND_LAYOUT_TABLE } from '~/utils/charts/constants';
8
+ import { createMockChartInstance, ChartTooltipStub } from '~helpers/chart_stubs';
8
9
 
9
10
  let mockChartInstance;
10
11
 
@@ -14,7 +15,6 @@ jest.mock('echarts', () => ({
14
15
 
15
16
  describe('area component', () => {
16
17
  let wrapper;
17
- let option;
18
18
 
19
19
  const findChart = () => wrapper.findComponent(Chart);
20
20
  const findLegend = () => wrapper.findComponent(ChartLegend);
@@ -24,33 +24,17 @@ describe('area component', () => {
24
24
  const emitChartCreated = () => findChart().vm.$emit('created', mockChartInstance);
25
25
 
26
26
  const createShallowWrapper = (props = {}) => {
27
- wrapper = shallowMount(AreaChart, { propsData: { option, data: [], ...props } });
27
+ wrapper = shallowMount(AreaChart, {
28
+ propsData: { option: { series: [] }, data: [], ...props },
29
+ stubs: {
30
+ 'chart-tooltip': ChartTooltipStub,
31
+ },
32
+ });
28
33
  emitChartCreated();
29
34
  };
30
35
 
31
36
  beforeEach(() => {
32
- option = {
33
- series: [],
34
- };
35
-
36
- mockChartInstance = {
37
- getDom: () => {
38
- return {
39
- addEventListener: jest.fn(),
40
- removeEventListener: jest.fn(),
41
- };
42
- },
43
- on: jest.fn(),
44
- off: jest.fn(),
45
- convertToPixel: jest.fn(),
46
- getOption: () => {
47
- return option;
48
- },
49
- };
50
- });
51
-
52
- afterEach(() => {
53
- wrapper.destroy();
37
+ mockChartInstance = createMockChartInstance();
54
38
  });
55
39
 
56
40
  it('emits `created`, with the chart instance', async () => {
@@ -345,8 +345,9 @@ export default {
345
345
  :left="annotationsTooltipPosition.left"
346
346
  placement="bottom"
347
347
  >
348
- <!-- eslint-disable-next-line vue/no-deprecated-slot-attribute -->
349
- <div slot="title">{{ annotationsTooltipTitle }}</div>
348
+ <template #title>
349
+ <div>{{ annotationsTooltipTitle }}</div>
350
+ </template>
350
351
  <div>{{ annotationsTooltipContent }}</div>
351
352
  </chart-tooltip>
352
353
  <chart-tooltip
@@ -359,19 +360,15 @@ export default {
359
360
  :top="dataTooltipPosition.top"
360
361
  :left="dataTooltipPosition.left"
361
362
  >
362
- <template v-if="formatTooltipText">
363
- <!-- eslint-disable-next-line vue/no-deprecated-slot-attribute -->
364
- <slot slot="title" name="tooltip-title"></slot>
365
- <slot name="tooltip-content"></slot>
366
- </template>
367
- <template v-else>
368
- <!-- eslint-disable-next-line vue/no-deprecated-slot-attribute -->
369
- <div slot="title">
363
+ <template #title>
364
+ <slot v-if="formatTooltipText" name="tooltip-title"></slot>
365
+ <template v-else>
370
366
  {{ dataTooltipTitle }}
371
367
  <template v-if="options.xAxis.name">({{ options.xAxis.name }})</template>
372
- </div>
373
- <tooltip-default-format :tooltip-content="dataTooltipContent" />
368
+ </template>
374
369
  </template>
370
+ <slot v-if="formatTooltipText" name="tooltip-content"></slot>
371
+ <tooltip-default-format v-else :tooltip-content="dataTooltipContent" />
375
372
  </chart-tooltip>
376
373
  <chart-legend
377
374
  v-if="compiledOptions"
@@ -2,16 +2,9 @@ import { shallowMount } from '@vue/test-utils';
2
2
  import Chart from '../chart/chart.vue';
3
3
  import BarChart from './bar.vue';
4
4
  import TooltipDefaultFormat from '~/components/shared_components/charts/tooltip_default_format.vue';
5
+ import { createMockChartInstance } from '~helpers/chart_stubs';
5
6
 
6
- const mockChartInstance = {
7
- getDom: () => {
8
- return {
9
- addEventListener: jest.fn(),
10
- removeEventListener: jest.fn(),
11
- };
12
- },
13
- convertToPixel: jest.fn(),
14
- };
7
+ let mockChartInstance;
15
8
 
16
9
  jest.mock('echarts', () => ({
17
10
  getInstanceByDom: () => mockChartInstance,
@@ -45,8 +38,8 @@ describe('Bar chart component', () => {
45
38
  });
46
39
  };
47
40
 
48
- afterEach(() => {
49
- wrapper.destroy();
41
+ beforeEach(() => {
42
+ mockChartInstance = createMockChartInstance();
50
43
  });
51
44
 
52
45
  describe('when mounted', () => {
@@ -25,10 +25,6 @@ describe('chart component', () => {
25
25
  wrapper = shallowMount(...mountArgs);
26
26
  });
27
27
 
28
- afterEach(() => {
29
- wrapper.destroy();
30
- });
31
-
32
28
  it('initializes chart using $refs.chart', () => {
33
29
  expect(echarts.init).toHaveBeenCalledWith(
34
30
  wrapper.findComponent({ ref: 'chart' }).element,
@@ -52,10 +52,6 @@ describe('column chart component', () => {
52
52
  factory();
53
53
  });
54
54
 
55
- afterEach(() => {
56
- wrapper.destroy();
57
- });
58
-
59
55
  it('emits "created" when onCreated is called', () => {
60
56
  wrapper.vm.onCreated(wrapper.vm.chart);
61
57
 
@@ -13,6 +13,7 @@ const template = `
13
13
  :option="option"
14
14
  :y-axis-title="yAxisTitle"
15
15
  :x-axis-title="xAxisTitle"
16
+ data-testid="discrete-scatter-chart"
16
17
  />
17
18
  `;
18
19
 
@@ -174,16 +174,13 @@ export default {
174
174
  :top="tooltipPosition.top"
175
175
  :left="tooltipPosition.left"
176
176
  >
177
- <template v-if="formatTooltipText">
178
- <!-- eslint-disable-next-line vue/no-deprecated-slot-attribute -->
179
- <slot slot="title" name="tooltip-title"></slot>
180
- <slot name="tooltip-content"></slot>
177
+ <template #title>
178
+ <slot name="tooltip-title">{{ tooltipTitle }} ({{ xAxisTitle }})</slot>
181
179
  </template>
182
- <template v-else>
183
- <!-- eslint-disable-next-line vue/no-deprecated-slot-attribute -->
184
- <div slot="title">{{ tooltipTitle }} ({{ xAxisTitle }})</div>
180
+
181
+ <slot name="tooltip-content">
185
182
  <tooltip-default-format :tooltip-content="tooltipContent" />
186
- </template>
183
+ </slot>
187
184
  </chart-tooltip>
188
185
  </div>
189
186
  </template>
@@ -1,8 +1,8 @@
1
1
  import { shallowMount } from '@vue/test-utils';
2
-
3
2
  import { gaugeSafeHues, gaugeWarningHue } from '../../../utils/charts/theme';
4
3
  import Chart from '../chart/chart.vue';
5
4
  import GlGauge from './gauge.vue';
5
+ import { createMockChartInstance } from '~helpers/chart_stubs';
6
6
 
7
7
  const placeholder = '--';
8
8
 
@@ -20,7 +20,6 @@ jest.mock('echarts', () => ({
20
20
 
21
21
  describe('gauge component', () => {
22
22
  let wrapper;
23
- let options;
24
23
 
25
24
  const findChart = () => wrapper.findComponent(Chart);
26
25
  const findChartOptions = () => findChart().props('options');
@@ -38,28 +37,7 @@ describe('gauge component', () => {
38
37
  };
39
38
 
40
39
  beforeEach(() => {
41
- options = {
42
- series: [],
43
- };
44
-
45
- mockChartInstance = {
46
- getDom: () => {
47
- return {
48
- addEventListener: jest.fn(),
49
- removeEventListener: jest.fn(),
50
- };
51
- },
52
- on: jest.fn(),
53
- off: jest.fn(),
54
- convertToPixel: jest.fn(),
55
- getOption: () => {
56
- return options;
57
- },
58
- };
59
- });
60
-
61
- afterEach(() => {
62
- wrapper.destroy();
40
+ mockChartInstance = createMockChartInstance();
63
41
  });
64
42
 
65
43
  it('emits `created`, with the chart instance', () => {
@@ -4,6 +4,7 @@ import Chart from '../chart/chart.vue';
4
4
  import ChartTooltip from '../tooltip/tooltip.vue';
5
5
  import HeatMapChart from './heatmap.vue';
6
6
  import { TOOLTIP_LEFT_OFFSET } from '~/utils/charts/constants';
7
+ import { createMockChartInstance } from '~helpers/chart_stubs';
7
8
 
8
9
  let mockChartInstance;
9
10
 
@@ -13,7 +14,6 @@ jest.mock('echarts', () => ({
13
14
 
14
15
  describe('heatmap component', () => {
15
16
  let wrapper;
16
- let options;
17
17
 
18
18
  const findChart = () => wrapper.findComponent(Chart);
19
19
  const findChartTooltip = () => wrapper.findComponent(ChartTooltip);
@@ -22,33 +22,16 @@ describe('heatmap component', () => {
22
22
  const emitChartCreated = () => findChart().vm.$emit('created', mockChartInstance);
23
23
 
24
24
  beforeEach(() => {
25
- options = {
26
- series: [],
27
- };
28
-
29
- mockChartInstance = {
30
- getDom: () => {
31
- return {
32
- addEventListener: jest.fn(),
33
- removeEventListener: jest.fn(),
34
- };
35
- },
36
- convertToPixel: jest.fn(),
37
- getOption: () => {
38
- return options;
39
- },
40
- };
41
-
42
- wrapper = shallowMount(HeatMapChart, { propsData: { options, dataSeries: [] } });
25
+ mockChartInstance = createMockChartInstance();
26
+
27
+ wrapper = shallowMount(HeatMapChart, {
28
+ propsData: { options: { series: [] }, dataSeries: [] },
29
+ });
43
30
  emitChartCreated();
44
31
 
45
32
  return wrapper.vm.$nextTick();
46
33
  });
47
34
 
48
- afterEach(() => {
49
- wrapper.destroy();
50
- });
51
-
52
35
  it('emits `created`, with the chart instance', () => {
53
36
  expect(wrapper.emitted('created').length).toBe(1);
54
37
  expect(wrapper.emitted('created')[0][0]).toBe(mockChartInstance);
@@ -2,16 +2,13 @@ import { shallowMount } from '@vue/test-utils';
2
2
  import Chart from '../chart/chart.vue';
3
3
  import GlChartSeriesLabel from '../series_label/series_label.vue';
4
4
  import Legend from './legend.vue';
5
+ import { createMockChartInstance } from '~helpers/chart_stubs';
6
+
7
+ let mockChartInstance;
5
8
 
6
9
  jest.mock('echarts', () => ({
7
- getInstanceByDom: jest.fn((instance) => instance),
8
- init: jest.fn(() => ({
9
- dispatchAction: jest.fn(),
10
- resize: jest.fn(),
11
- setOption: jest.fn(),
12
- on: jest.fn(),
13
- off: jest.fn(),
14
- })),
10
+ getInstanceByDom: () => mockChartInstance,
11
+ init: () => mockChartInstance,
15
12
  registerTheme: jest.fn(),
16
13
  }));
17
14
 
@@ -58,24 +55,21 @@ describe('chart legend component', () => {
58
55
  legendWrapper = shallowMount(Legend, {
59
56
  propsData: {
60
57
  ...propsData,
61
- chart,
58
+ chart: mockChartInstance,
62
59
  seriesInfo,
63
60
  },
64
61
  });
65
62
  };
66
63
 
67
64
  beforeEach(async () => {
65
+ mockChartInstance = createMockChartInstance();
66
+
68
67
  chartWrapper = shallowMount(...chartArgs);
69
68
  await chartWrapper.vm.$nextTick();
70
69
  // Runs after mounting the chart so that it has an up to date reference
71
70
  buildLegend();
72
71
  });
73
72
 
74
- afterEach(() => {
75
- chartWrapper.destroy();
76
- legendWrapper.destroy();
77
- });
78
-
79
73
  it('renders the legend with no errors', () => {
80
74
  expect(legendWrapper.exists()).toBe(true);
81
75
  });
@@ -6,6 +6,8 @@ import LineChart from './line.vue';
6
6
 
7
7
  import { LEGEND_LAYOUT_INLINE, LEGEND_LAYOUT_TABLE } from '~/utils/charts/constants';
8
8
 
9
+ import { createMockChartInstance, ChartTooltipStub } from '~helpers/chart_stubs';
10
+
9
11
  let mockChartInstance;
10
12
 
11
13
  jest.mock('echarts', () => ({
@@ -23,36 +25,16 @@ describe('line component', () => {
23
25
 
24
26
  const emitChartCreated = () => findChart().vm.$emit('created', mockChartInstance);
25
27
 
26
- const createShallowWrapper = (props = {}) => {
28
+ const createShallowWrapper = (props = {}, mountOptions = {}) => {
27
29
  wrapper = shallowMount(LineChart, {
28
30
  propsData: { option, data: [], ...props },
31
+ ...mountOptions,
29
32
  });
30
33
  emitChartCreated();
31
34
  };
32
35
 
33
36
  beforeEach(() => {
34
- option = {
35
- series: [],
36
- };
37
-
38
- mockChartInstance = {
39
- getDom: () => {
40
- return {
41
- addEventListener: jest.fn(),
42
- removeEventListener: jest.fn(),
43
- };
44
- },
45
- on: jest.fn(),
46
- off: jest.fn(),
47
- convertToPixel: jest.fn(),
48
- getOption: () => {
49
- return option;
50
- },
51
- };
52
- });
53
-
54
- afterEach(() => {
55
- wrapper.destroy();
37
+ mockChartInstance = createMockChartInstance();
56
38
  });
57
39
 
58
40
  it('emits `created`, with the chart instance', async () => {
@@ -128,14 +110,21 @@ describe('line component', () => {
128
110
  },
129
111
  };
130
112
 
131
- createShallowWrapper({
132
- annotations: [
133
- {
134
- min: '',
135
- max: '',
113
+ createShallowWrapper(
114
+ {
115
+ annotations: [
116
+ {
117
+ min: '',
118
+ max: '',
119
+ },
120
+ ],
121
+ },
122
+ {
123
+ stubs: {
124
+ 'chart-tooltip': ChartTooltipStub,
136
125
  },
137
- ],
138
- });
126
+ }
127
+ );
139
128
 
140
129
  wrapper.vm.onChartDataPointMouseOver(params);
141
130
 
@@ -339,8 +339,9 @@ export default {
339
339
  :left="annotationsTooltipPosition.left"
340
340
  placement="bottom"
341
341
  >
342
- <!-- eslint-disable-next-line vue/no-deprecated-slot-attribute -->
343
- <div slot="title">{{ annotationsTooltipTitle }}</div>
342
+ <template #title>
343
+ <div>{{ annotationsTooltipTitle }}</div>
344
+ </template>
344
345
  <div>{{ annotationsTooltipContent }}</div>
345
346
  </chart-tooltip>
346
347
  <chart-tooltip
@@ -26,10 +26,6 @@ describe('GlSingleStat', () => {
26
26
 
27
27
  const findIemByTestId = (testId) => wrapper.find(`[data-testid="${testId}"]`);
28
28
 
29
- afterEach(() => {
30
- wrapper.destroy();
31
- });
32
-
33
29
  describe('displays the correct default data', () => {
34
30
  beforeEach(() => createWrapper());
35
31
 
@@ -2,14 +2,13 @@ import { shallowMount, createLocalVue } from '@vue/test-utils';
2
2
  import Chart from '../chart/chart.vue';
3
3
  import SparklineChart from './sparkline.vue';
4
4
  import { waitForAnimationFrame } from '~/utils/test_utils';
5
+ import { createMockChartInstance, ChartTooltipStub } from '~helpers/chart_stubs';
5
6
 
6
- const mockResize = jest.fn();
7
- const mockChartInstance = {
8
- subscribedEvents: {},
9
- getDom: () => {},
10
- convertToPixel: () => [],
11
- resize: mockResize,
12
- };
7
+ let mockChartInstance;
8
+
9
+ jest.mock('echarts', () => ({
10
+ getInstanceByDom: () => mockChartInstance,
11
+ }));
13
12
 
14
13
  let triggerResize = () => {};
15
14
  jest.mock('~/directives/resize_observer/resize_observer', () => ({
@@ -22,11 +21,6 @@ jest.mock('~/directives/resize_observer/resize_observer', () => ({
22
21
 
23
22
  const localVue = createLocalVue();
24
23
 
25
- const ChartToolTipStub = {
26
- name: 'chart-tooltip-stub',
27
- template: '<div><slot name="default"></slot><slot name="title"></slot></div>',
28
- };
29
-
30
24
  describe('sparkline chart component', () => {
31
25
  let wrapper;
32
26
  let componentOptions;
@@ -39,7 +33,7 @@ describe('sparkline chart component', () => {
39
33
  },
40
34
  scopedSlots: { latestSeriesEntry: jest.fn() },
41
35
  stubs: {
42
- 'chart-tooltip': ChartToolTipStub,
36
+ 'chart-tooltip': ChartTooltipStub,
43
37
  },
44
38
  };
45
39
 
@@ -50,7 +44,7 @@ describe('sparkline chart component', () => {
50
44
  const getByTestId = (id) => wrapper.find(`[data-testid="${id}"]`);
51
45
  const getChart = () => wrapper.findComponent(Chart);
52
46
 
53
- const getTooltip = () => wrapper.findComponent(ChartToolTipStub);
47
+ const getTooltip = () => wrapper.findComponent(ChartTooltipStub);
54
48
  const getTooltipTitle = () => getByTestId('tooltip-title');
55
49
  const getTooltipContent = () => getByTestId('tooltip-content');
56
50
 
@@ -72,13 +66,13 @@ describe('sparkline chart component', () => {
72
66
  const emitChartCreated = () => getChart().vm.$emit('created', mockChartInstance);
73
67
 
74
68
  beforeEach(() => {
69
+ mockChartInstance = createMockChartInstance();
75
70
  factory();
76
71
  // needs to run after every mount, or the chart-instance is `null` and `beforeDestroy` throws
77
72
  emitChartCreated();
78
73
  });
79
74
 
80
75
  afterEach(() => {
81
- wrapper.destroy();
82
76
  jest.clearAllMocks();
83
77
  });
84
78
 
@@ -56,7 +56,6 @@ describe('stacked column chart component', () => {
56
56
  });
57
57
 
58
58
  afterEach(() => {
59
- wrapper.destroy();
60
59
  jest.restoreAllMocks();
61
60
  });
62
61
 
@@ -17,10 +17,6 @@ describe('Clear Icon Button', () => {
17
17
  createComponent();
18
18
  });
19
19
 
20
- afterEach(() => {
21
- wrapper.destroy();
22
- });
23
-
24
20
  it('renders successfully', () => {
25
21
  expect(wrapper.element).toMatchSnapshot();
26
22
  });
@@ -16,10 +16,6 @@ describe('Clear Icon Button', () => {
16
16
  createComponent();
17
17
  });
18
18
 
19
- afterEach(() => {
20
- wrapper.destroy();
21
- });
22
-
23
19
  it('renders successfully', () => {
24
20
  expect(wrapper.element).toMatchSnapshot();
25
21
  });