2019-02-15 15:39:39 +05:30
|
|
|
import $ from 'jquery';
|
2020-04-22 19:07:51 +05:30
|
|
|
import { mockTracking, unmockTracking } from 'helpers/tracking_helper';
|
2021-01-03 14:25:43 +05:30
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2020-10-24 23:57:45 +05:30
|
|
|
import blobBundle from '~/blob_edit/blob_bundle';
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
import EditorLite from '~/blob_edit/edit_blob';
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
jest.mock('~/blob_edit/edit_blob');
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
describe('BlobBundle', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
it('does not load EditorLite by default', () => {
|
|
|
|
blobBundle();
|
|
|
|
expect(EditorLite).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('loads EditorLite for the edit screen', async () => {
|
|
|
|
setFixtures(`<div class="js-edit-blob-form"></div>`);
|
|
|
|
blobBundle();
|
|
|
|
await waitForPromises();
|
|
|
|
expect(EditorLite).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
describe('No Suggest Popover', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
setFixtures(`
|
2019-02-15 15:39:39 +05:30
|
|
|
<div class="js-edit-blob-form" data-blob-filename="blah">
|
|
|
|
<button class="js-commit-button"></button>
|
|
|
|
<a class="btn btn-cancel" href="#"></a>
|
|
|
|
</div>`);
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
blobBundle();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets the window beforeunload listener to a function returning a string', () => {
|
|
|
|
expect(window.onbeforeunload()).toBe('');
|
|
|
|
});
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
it('removes beforeunload listener if commit button is clicked', () => {
|
|
|
|
$('.js-commit-button').click();
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(window.onbeforeunload).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes beforeunload listener when cancel link is clicked', () => {
|
|
|
|
$('.btn.btn-cancel').click();
|
|
|
|
|
|
|
|
expect(window.onbeforeunload).toBeNull();
|
|
|
|
});
|
2019-02-15 15:39:39 +05:30
|
|
|
});
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
describe('Suggest Popover', () => {
|
|
|
|
let trackingSpy;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
setFixtures(`
|
|
|
|
<div class="js-edit-blob-form" data-blob-filename="blah" id="target">
|
|
|
|
<div class="js-suggest-gitlab-ci-yml"
|
|
|
|
data-target="#target"
|
|
|
|
data-track-label="suggest_gitlab_ci_yml"
|
|
|
|
data-dismiss-key="1"
|
2020-11-24 15:15:51 +05:30
|
|
|
data-human-access="owner"
|
|
|
|
data-merge-request-path="path/to/mr">
|
2020-04-22 19:07:51 +05:30
|
|
|
<button id='commit-changes' class="js-commit-button"></button>
|
|
|
|
<a class="btn btn-cancel" href="#"></a>
|
|
|
|
</div>
|
|
|
|
</div>`);
|
|
|
|
|
|
|
|
trackingSpy = mockTracking('_category_', $('#commit-changes').element, jest.spyOn);
|
|
|
|
document.body.dataset.page = 'projects:blob:new';
|
|
|
|
|
|
|
|
blobBundle();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
unmockTracking();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sends a tracking event when the commit button is clicked', () => {
|
|
|
|
$('#commit-changes').click();
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(trackingSpy).toHaveBeenCalledTimes(1);
|
|
|
|
expect(trackingSpy).toHaveBeenCalledWith(undefined, undefined, {
|
|
|
|
label: 'suggest_gitlab_ci_yml',
|
|
|
|
property: 'owner',
|
|
|
|
});
|
|
|
|
});
|
2019-02-15 15:39:39 +05:30
|
|
|
});
|
|
|
|
});
|