gitlab-org--gitlab-foss/spec/frontend/feature_highlight/feature_highlight_helper_spec.js

63 lines
1.7 KiB
JavaScript
Raw Normal View History

import $ from 'jquery';
import axios from '~/lib/utils/axios_utils';
2018-10-17 03:13:26 -04:00
import { getSelector, dismiss, inserted } from '~/feature_highlight/feature_highlight_helper';
2018-03-28 13:12:30 -04:00
import { togglePopover } from '~/shared/popover';
2018-03-27 22:45:36 -04:00
describe('feature highlight helper', () => {
describe('getSelector', () => {
it('returns js-feature-highlight selector', () => {
const highlightId = 'highlightId';
2018-10-09 14:03:09 -04:00
2018-10-17 03:13:26 -04:00
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', () => {
2018-10-17 03:13:26 -04:00
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);
});
});
});