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

navigation_popover_spec.js « components « attention_requests « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d0231afbdc4e14137761c83a222bebffdbf21cd0 (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
import { shallowMount } from '@vue/test-utils';
import { GlPopover, GlButton, GlSprintf, GlIcon } from '@gitlab/ui';
import { GlBreakpointInstance as bp } from '@gitlab/ui/dist/utils';
import NavigationPopover from '~/attention_requests/components/navigation_popover.vue';
import { makeMockUserCalloutDismisser } from 'helpers/mock_user_callout_dismisser';

let wrapper;
let dismiss;

function createComponent(provideData = {}, shouldShowCallout = true) {
  wrapper = shallowMount(NavigationPopover, {
    provide: {
      message: ['Test'],
      observerElSelector: '.js-test',
      observerElToggledClass: 'show',
      featureName: 'attention_requests',
      popoverTarget: '.js-test-popover',
      ...provideData,
    },
    stubs: {
      UserCalloutDismisser: makeMockUserCalloutDismisser({
        dismiss,
        shouldShowCallout,
      }),
      GlSprintf,
    },
  });
}

describe('Attention requests navigation popover', () => {
  beforeEach(() => {
    setFixtures('<div><div class="js-test-popover"></div><div class="js-test"></div></div>');
    dismiss = jest.fn();
  });

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

  it('hides popover if callout is disabled', () => {
    createComponent({}, false);

    expect(wrapper.findComponent(GlPopover).exists()).toBe(false);
  });

  it('shows popover if callout is enabled', () => {
    createComponent();

    expect(wrapper.findComponent(GlPopover).exists()).toBe(true);
  });

  it.each`
    isDesktop | device       | expectedPlacement
    ${true}   | ${'desktop'} | ${'left'}
    ${false}  | ${'mobile'}  | ${'bottom'}
  `(
    'sets popover position to $expectedPlacement on $device',
    ({ isDesktop, expectedPlacement }) => {
      jest.spyOn(bp, 'isDesktop').mockReturnValue(isDesktop);

      createComponent();

      expect(wrapper.findComponent(GlPopover).props('placement')).toBe(expectedPlacement);
    },
  );

  it('calls dismiss when clicking action button', () => {
    createComponent();

    wrapper
      .findComponent(GlButton)
      .vm.$emit('click', { preventDefault() {}, stopPropagation() {} });

    expect(dismiss).toHaveBeenCalled();
  });

  it('shows icon in text', () => {
    createComponent({ showAttentionIcon: true, message: ['%{strongStart}Test%{strongEnd}'] });

    const icon = wrapper.findComponent(GlIcon);

    expect(icon.exists()).toBe(true);
    expect(icon.props('name')).toBe('attention');
  });
});