2018-11-27 05:05:25 -05:00
|
|
|
import $ from 'jquery';
|
2020-04-01 14:07:56 -04:00
|
|
|
import { mockTracking, unmockTracking } from 'helpers/tracking_helper';
|
2020-10-16 11:08:46 -04:00
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2020-08-17 17:09:56 -04:00
|
|
|
import blobBundle from '~/blob_edit/blob_bundle';
|
2018-11-27 05:05:25 -05:00
|
|
|
|
2021-06-18 17:10:06 -04:00
|
|
|
import SourceEditor from '~/blob_edit/edit_blob';
|
2020-10-16 11:08:46 -04:00
|
|
|
|
2020-02-28 16:09:15 -05:00
|
|
|
jest.mock('~/blob_edit/edit_blob');
|
|
|
|
|
2018-12-14 12:56:25 -05:00
|
|
|
describe('BlobBundle', () => {
|
2021-06-18 17:10:06 -04:00
|
|
|
it('does not load SourceEditor by default', () => {
|
2020-10-16 11:08:46 -04:00
|
|
|
blobBundle();
|
2021-06-18 17:10:06 -04:00
|
|
|
expect(SourceEditor).not.toHaveBeenCalled();
|
2020-10-16 11:08:46 -04:00
|
|
|
});
|
|
|
|
|
2021-06-18 17:10:06 -04:00
|
|
|
it('loads SourceEditor for the edit screen', async () => {
|
2020-10-16 11:08:46 -04:00
|
|
|
setFixtures(`<div class="js-edit-blob-form"></div>`);
|
|
|
|
blobBundle();
|
|
|
|
await waitForPromises();
|
2021-06-18 17:10:06 -04:00
|
|
|
expect(SourceEditor).toHaveBeenCalled();
|
2020-10-16 11:08:46 -04:00
|
|
|
});
|
|
|
|
|
2020-04-01 14:07:56 -04:00
|
|
|
describe('No Suggest Popover', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
setFixtures(`
|
2018-12-14 12:56:25 -05:00
|
|
|
<div class="js-edit-blob-form" data-blob-filename="blah">
|
2018-11-27 05:05:25 -05:00
|
|
|
<button class="js-commit-button"></button>
|
2022-03-05 01:19:08 -05:00
|
|
|
<button id='cancel-changes'></button>
|
2018-11-27 05:05:25 -05:00
|
|
|
</div>`);
|
|
|
|
|
2020-04-01 14:07:56 -04:00
|
|
|
blobBundle();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets the window beforeunload listener to a function returning a string', () => {
|
|
|
|
expect(window.onbeforeunload()).toBe('');
|
|
|
|
});
|
2018-11-27 05:05:25 -05:00
|
|
|
|
2020-04-01 14:07:56 -04:00
|
|
|
it('removes beforeunload listener if commit button is clicked', () => {
|
|
|
|
$('.js-commit-button').click();
|
2018-11-27 05:05:25 -05:00
|
|
|
|
2020-04-01 14:07:56 -04:00
|
|
|
expect(window.onbeforeunload).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes beforeunload listener when cancel link is clicked', () => {
|
2022-03-05 01:19:08 -05:00
|
|
|
$('#cancel-changes').click();
|
2020-04-01 14:07:56 -04:00
|
|
|
|
|
|
|
expect(window.onbeforeunload).toBeNull();
|
|
|
|
});
|
2018-11-27 05:05:25 -05:00
|
|
|
});
|
2018-12-13 16:27:23 -05:00
|
|
|
|
2020-04-01 14:07:56 -04:00
|
|
|
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-08-26 14:11:43 -04:00
|
|
|
data-human-access="owner"
|
|
|
|
data-merge-request-path="path/to/mr">
|
2020-04-01 14:07:56 -04:00
|
|
|
<button id='commit-changes' class="js-commit-button"></button>
|
2022-03-05 01:19:08 -05:00
|
|
|
<button id='cancel-changes'></button>
|
2020-04-01 14:07:56 -04:00
|
|
|
</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();
|
2018-12-13 16:27:23 -05:00
|
|
|
|
2020-04-01 14:07:56 -04:00
|
|
|
expect(trackingSpy).toHaveBeenCalledTimes(1);
|
|
|
|
expect(trackingSpy).toHaveBeenCalledWith(undefined, undefined, {
|
|
|
|
label: 'suggest_gitlab_ci_yml',
|
|
|
|
property: 'owner',
|
|
|
|
});
|
|
|
|
});
|
2018-12-13 16:27:23 -05:00
|
|
|
});
|
2018-11-27 05:05:25 -05:00
|
|
|
});
|