2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2019-12-10 04:07:51 -05:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2018-01-10 23:16:27 -05:00
|
|
|
import * as featureHighlight from '~/feature_highlight/feature_highlight';
|
2018-03-27 23:14:44 -04:00
|
|
|
import * as popover from '~/shared/popover';
|
2018-02-20 17:20:48 -05:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2018-01-10 23:16:27 -05:00
|
|
|
|
2020-04-28 14:09:35 -04:00
|
|
|
jest.mock('~/shared/popover');
|
|
|
|
|
2018-01-10 23:16:27 -05:00
|
|
|
describe('feature highlight', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
setFixtures(`
|
|
|
|
<div>
|
2018-02-20 17:20:48 -05:00
|
|
|
<div class="js-feature-highlight" data-highlight="test" data-highlight-priority="10" data-dismiss-endpoint="/test" disabled>
|
2018-01-10 23:16:27 -05:00
|
|
|
Trigger
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="feature-highlight-popover-content">
|
|
|
|
Content
|
|
|
|
<div class="dismiss-feature-highlight">
|
|
|
|
Dismiss
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setupFeatureHighlightPopover', () => {
|
2018-02-20 17:20:48 -05:00
|
|
|
let mock;
|
2018-01-10 23:16:27 -05:00
|
|
|
const selector = '.js-feature-highlight[data-highlight=test]';
|
2018-02-20 17:20:48 -05:00
|
|
|
|
2018-01-10 23:16:27 -05:00
|
|
|
beforeEach(() => {
|
2018-02-20 17:20:48 -05:00
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
mock.onGet('/test').reply(200);
|
2020-04-28 14:09:35 -04:00
|
|
|
jest.spyOn(window, 'addEventListener').mockImplementation(() => {});
|
2018-01-10 23:16:27 -05:00
|
|
|
featureHighlight.setupFeatureHighlightPopover('test', 0);
|
|
|
|
});
|
|
|
|
|
2018-02-20 17:20:48 -05:00
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
});
|
|
|
|
|
2018-01-10 23:16:27 -05:00
|
|
|
it('setup popover content', () => {
|
|
|
|
const $popoverContent = $('.feature-highlight-popover-content');
|
|
|
|
const outerHTML = $popoverContent.prop('outerHTML');
|
|
|
|
|
|
|
|
expect($(selector).data('content')).toEqual(outerHTML);
|
|
|
|
});
|
|
|
|
|
2018-03-28 06:38:56 -04:00
|
|
|
it('setup mouseenter', () => {
|
2018-01-10 23:16:27 -05:00
|
|
|
$(selector).trigger('mouseenter');
|
|
|
|
|
2020-04-28 14:09:35 -04:00
|
|
|
expect(popover.mouseenter).toHaveBeenCalledWith(expect.any(Object));
|
2018-01-10 23:16:27 -05:00
|
|
|
});
|
|
|
|
|
2020-04-28 14:09:35 -04:00
|
|
|
it('setup debounced mouseleave', () => {
|
2018-01-10 23:16:27 -05:00
|
|
|
$(selector).trigger('mouseleave');
|
|
|
|
|
2020-04-28 14:09:35 -04:00
|
|
|
expect(popover.debouncedMouseleave).toHaveBeenCalled();
|
2018-01-10 23:16:27 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('setup show.bs.popover', () => {
|
|
|
|
$(selector).trigger('show.bs.popover');
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2020-04-28 14:09:35 -04:00
|
|
|
expect(window.addEventListener).toHaveBeenCalledWith('scroll', expect.any(Function), {
|
2018-10-17 03:13:26 -04:00
|
|
|
once: true,
|
|
|
|
});
|
2018-01-10 23:16:27 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('removes disabled attribute', () => {
|
|
|
|
expect($('.js-feature-highlight').is(':disabled')).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('findHighestPriorityFeature', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
setFixtures(`
|
|
|
|
<div class="js-feature-highlight" data-highlight="test" data-highlight-priority="10" disabled></div>
|
|
|
|
<div class="js-feature-highlight" data-highlight="test-high-priority" data-highlight-priority="20" disabled></div>
|
|
|
|
<div class="js-feature-highlight" data-highlight="test-low-priority" data-highlight-priority="0" disabled></div>
|
|
|
|
`);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should pick the highest priority feature highlight', () => {
|
|
|
|
setFixtures(`
|
|
|
|
<div class="js-feature-highlight" data-highlight="test" data-highlight-priority="10" disabled></div>
|
|
|
|
<div class="js-feature-highlight" data-highlight="test-high-priority" data-highlight-priority="20" disabled></div>
|
|
|
|
<div class="js-feature-highlight" data-highlight="test-low-priority" data-highlight-priority="0" disabled></div>
|
|
|
|
`);
|
|
|
|
|
|
|
|
expect($('.js-feature-highlight').length).toBeGreaterThan(1);
|
|
|
|
expect(featureHighlight.findHighestPriorityFeature()).toEqual('test-high-priority');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should work when no priority is set', () => {
|
|
|
|
setFixtures(`
|
|
|
|
<div class="js-feature-highlight" data-highlight="test" disabled></div>
|
|
|
|
`);
|
|
|
|
|
|
|
|
expect(featureHighlight.findHighestPriorityFeature()).toEqual('test');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should pick the highest priority feature highlight when some have no priority set', () => {
|
|
|
|
setFixtures(`
|
|
|
|
<div class="js-feature-highlight" data-highlight="test-no-priority1" disabled></div>
|
|
|
|
<div class="js-feature-highlight" data-highlight="test" data-highlight-priority="10" disabled></div>
|
|
|
|
<div class="js-feature-highlight" data-highlight="test-no-priority2" disabled></div>
|
|
|
|
<div class="js-feature-highlight" data-highlight="test-high-priority" data-highlight-priority="20" disabled></div>
|
|
|
|
<div class="js-feature-highlight" data-highlight="test-low-priority" data-highlight-priority="0" disabled></div>
|
|
|
|
`);
|
|
|
|
|
|
|
|
expect($('.js-feature-highlight').length).toBeGreaterThan(1);
|
|
|
|
expect(featureHighlight.findHighestPriorityFeature()).toEqual('test-high-priority');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('highlightFeatures', () => {
|
|
|
|
it('calls setupFeatureHighlightPopover', () => {
|
|
|
|
expect(featureHighlight.highlightFeatures()).toEqual('test');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|