debian-mirror-gitlab/spec/frontend/feature_highlight/feature_highlight_helper_spec.js

63 lines
1.7 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2018-03-17 18:26:18 +05:30
import axios from '~/lib/utils/axios_utils';
2018-12-13 13:39:08 +05:30
import { getSelector, dismiss, inserted } from '~/feature_highlight/feature_highlight_helper';
2018-10-15 14:42:47 +05:30
import { togglePopover } from '~/shared/popover';
2018-03-17 18:26:18 +05:30
describe('feature highlight helper', () => {
describe('getSelector', () => {
it('returns js-feature-highlight selector', () => {
const highlightId = 'highlightId';
2018-12-13 13:39:08 +05:30
expect(getSelector(highlightId)).toEqual(
`.js-feature-highlight[data-highlight=${highlightId}]`,
);
2018-03-17 18:26:18 +05:30
});
});
describe('dismiss', () => {
const context = {
hide: () => {},
attr: () => '/-/callouts/dismiss',
};
beforeEach(() => {
2020-05-24 23:13:21 +05:30
jest.spyOn(axios, 'post').mockResolvedValue();
jest.spyOn(togglePopover, 'call').mockImplementation(() => {});
jest.spyOn(context, 'hide').mockImplementation(() => {});
2018-03-17 18:26:18 +05:30
dismiss.call(context);
});
2020-05-24 23:13:21 +05:30
it('calls persistent dismissal endpoint', () => {
expect(axios.post).toHaveBeenCalledWith(
'/-/callouts/dismiss',
expect.objectContaining({ feature_name: undefined }),
);
2018-03-17 18:26:18 +05:30
});
it('calls hide popover', () => {
expect(togglePopover.call).toHaveBeenCalledWith(context, false);
});
it('calls hide', () => {
expect(context.hide).toHaveBeenCalled();
});
});
describe('inserted', () => {
2018-12-13 13:39:08 +05:30
it('registers click event callback', done => {
2018-03-17 18:26:18 +05:30
const context = {
getAttribute: () => 'popoverId',
dataset: {
highlight: 'some-feature',
},
};
2020-05-24 23:13:21 +05:30
jest.spyOn($.fn, 'on').mockImplementation(event => {
2018-03-17 18:26:18 +05:30
expect(event).toEqual('click');
done();
});
inserted.call(context);
});
});
});