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

report_abuse_button_spec.js « components « profile « users « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1ca944dce12a181bffcc4bb9127c728f156d5019 (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
import { GlButton } from '@gitlab/ui';
import { createWrapper } from '@vue/test-utils';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import { BV_HIDE_TOOLTIP } from '~/lib/utils/constants';
import ReportAbuseButton from '~/users/profile/components/report_abuse_button.vue';
import AbuseCategorySelector from '~/abuse_reports/components/abuse_category_selector.vue';

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

  const ACTION_PATH = '/abuse_reports/add_category';
  const USER_ID = 1;
  const REPORTED_FROM_URL = 'http://example.com';

  const createComponent = (props) => {
    wrapper = shallowMountExtended(ReportAbuseButton, {
      propsData: {
        ...props,
      },
      provide: {
        reportAbusePath: ACTION_PATH,
        reportedUserId: USER_ID,
        reportedFromUrl: REPORTED_FROM_URL,
      },
    });
  };

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

  const findReportAbuseButton = () => wrapper.findComponent(GlButton);
  const findAbuseCategorySelector = () => wrapper.findComponent(AbuseCategorySelector);

  it('renders report abuse button', () => {
    expect(findReportAbuseButton().exists()).toBe(true);

    expect(findReportAbuseButton().props()).toMatchObject({
      category: 'primary',
      icon: 'error',
    });

    expect(findReportAbuseButton().attributes('aria-label')).toBe(
      ReportAbuseButton.i18n.reportAbuse,
    );
  });

  it('renders abuse category selector with the drawer initially closed', () => {
    expect(findAbuseCategorySelector().exists()).toBe(true);

    expect(findAbuseCategorySelector().props('showDrawer')).toBe(false);
  });

  describe('when button is clicked', () => {
    beforeEach(async () => {
      await findReportAbuseButton().vm.$emit('click');
    });

    it('opens the abuse category selector', () => {
      expect(findAbuseCategorySelector().props('showDrawer')).toBe(true);
    });

    it('closes the abuse category selector', async () => {
      await findAbuseCategorySelector().vm.$emit('close-drawer');

      expect(findAbuseCategorySelector().props('showDrawer')).toBe(false);
    });
  });

  describe('when user hovers out of the button', () => {
    it(`should emit ${BV_HIDE_TOOLTIP} to close the tooltip`, () => {
      const rootWrapper = createWrapper(wrapper.vm.$root);

      findReportAbuseButton().vm.$emit('mouseout');

      expect(rootWrapper.emitted(BV_HIDE_TOOLTIP)).toHaveLength(1);
    });
  });
});