summaryrefslogtreecommitdiff
path: root/spec/frontend/super_sidebar/components/context_switcher_toggle_spec.js
blob: 7172b60d0fa454fe336a6d54b2ec7bc8f6fcc5b9 (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
import { GlAvatar } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import ContextSwitcherToggle from '~/super_sidebar/components/context_switcher_toggle.vue';

describe('ContextSwitcherToggle component', () => {
  let wrapper;

  const context = {
    id: 1,
    title: 'Title',
    avatar: '/path/to/avatar.png',
  };

  const findGlAvatar = () => wrapper.getComponent(GlAvatar);

  const createWrapper = (props = {}) => {
    wrapper = shallowMountExtended(ContextSwitcherToggle, {
      propsData: {
        context,
        expanded: false,
        ...props,
      },
    });
  };

  describe('with an avatar', () => {
    it('passes the correct props to GlAvatar', () => {
      createWrapper();
      const avatar = findGlAvatar();

      expect(avatar.props('shape')).toBe('rect');
      expect(avatar.props('entityName')).toBe(context.title);
      expect(avatar.props('entityId')).toBe(context.id);
      expect(avatar.props('src')).toBe(context.avatar);
    });

    it('renders the avatar with a custom shape', () => {
      const customShape = 'circle';
      createWrapper({
        context: {
          ...context,
          avatar_shape: customShape,
        },
      });
      const avatar = findGlAvatar();

      expect(avatar.props('shape')).toBe(customShape);
    });
  });
});