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

feature_highlight_helper_spec.js « feature_highlight « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2c3c3e3267a20b18385da32d8f3b19a9617ae426 (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
import $ from 'jquery';
import axios from '~/lib/utils/axios_utils';
import { getSelector, dismiss, inserted } from '~/feature_highlight/feature_highlight_helper';
import { togglePopover } from '~/shared/popover';

describe('feature highlight helper', () => {
  describe('getSelector', () => {
    it('returns js-feature-highlight selector', () => {
      const highlightId = 'highlightId';

      expect(getSelector(highlightId)).toEqual(
        `.js-feature-highlight[data-highlight=${highlightId}]`,
      );
    });
  });

  describe('dismiss', () => {
    const context = {
      hide: () => {},
      attr: () => '/-/callouts/dismiss',
    };

    beforeEach(() => {
      jest.spyOn(axios, 'post').mockResolvedValue();
      jest.spyOn(togglePopover, 'call').mockImplementation(() => {});
      jest.spyOn(context, 'hide').mockImplementation(() => {});
      dismiss.call(context);
    });

    it('calls persistent dismissal endpoint', () => {
      expect(axios.post).toHaveBeenCalledWith(
        '/-/callouts/dismiss',
        expect.objectContaining({ feature_name: undefined }),
      );
    });

    it('calls hide popover', () => {
      expect(togglePopover.call).toHaveBeenCalledWith(context, false);
    });

    it('calls hide', () => {
      expect(context.hide).toHaveBeenCalled();
    });
  });

  describe('inserted', () => {
    it('registers click event callback', done => {
      const context = {
        getAttribute: () => 'popoverId',
        dataset: {
          highlight: 'some-feature',
        },
      };

      jest.spyOn($.fn, 'on').mockImplementation(event => {
        expect(event).toEqual('click');
        done();
      });
      inserted.call(context);
    });
  });
});