2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2018-01-10 23:16:27 -05:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
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
|
|
|
|
2018-02-26 14:43:34 -05:00
|
|
|
import getSetTimeoutPromise from 'spec/helpers/set_timeout_promise_helper';
|
2018-01-10 23:16:27 -05: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}]`,
|
|
|
|
);
|
2018-01-10 23:16:27 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('dismiss', () => {
|
|
|
|
let mock;
|
|
|
|
const context = {
|
|
|
|
hide: () => {},
|
|
|
|
attr: () => '/-/callouts/dismiss',
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
|
|
|
|
spyOn(togglePopover, 'call').and.callFake(() => {});
|
|
|
|
spyOn(context, 'hide').and.callFake(() => {});
|
|
|
|
dismiss.call(context);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
it('calls persistent dismissal endpoint', done => {
|
2018-01-10 23:16:27 -05:00
|
|
|
const spy = jasmine.createSpy('dismiss-endpoint-hit');
|
|
|
|
mock.onPost('/-/callouts/dismiss').reply(spy);
|
|
|
|
|
|
|
|
getSetTimeoutPromise()
|
|
|
|
.then(() => {
|
|
|
|
expect(spy).toHaveBeenCalled();
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
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 => {
|
2018-01-10 23:16:27 -05:00
|
|
|
const context = {
|
|
|
|
getAttribute: () => 'popoverId',
|
|
|
|
dataset: {
|
|
|
|
highlight: 'some-feature',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
spyOn($.fn, 'on').and.callFake(event => {
|
2018-01-10 23:16:27 -05:00
|
|
|
expect(event).toEqual('click');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
inserted.call(context);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|