summaryrefslogtreecommitdiff
path: root/spec/frontend/editor/components/helpers.js
blob: 12f90390c1810ad09d3fb2aee7b354310cd7433c (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
import { EDITOR_TOOLBAR_RIGHT_GROUP } from '~/editor/constants';
import { apolloProvider } from '~/editor/components/source_editor_toolbar_graphql';
import getToolbarItemsQuery from '~/editor/graphql/get_items.query.graphql';

export const buildButton = (id = 'foo-bar-btn', options = {}) => {
  return {
    __typename: 'Item',
    id,
    label: options.label || 'Foo Bar Button',
    icon: options.icon || 'check',
    selected: options.selected || false,
    group: options.group || EDITOR_TOOLBAR_RIGHT_GROUP,
    onClick: options.onClick || (() => {}),
    category: options.category || 'primary',
    selectedLabel: options.selectedLabel || 'smth',
  };
};

export const warmUpCacheWithItems = (items = []) => {
  apolloProvider.defaultClient.cache.writeQuery({
    query: getToolbarItemsQuery,
    data: {
      items: {
        nodes: items,
      },
    },
  });
};