summaryrefslogtreecommitdiff
path: root/spec/javascripts/blob_edit/blob_bundle_spec.js
blob: 57f60a4a3ddf7e8406a136fbbb85cdf5065900ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import blobBundle from '~/blob_edit/blob_bundle';
import $ from 'jquery';

window.ace = {
  config: {
    set: () => {},
    loadModule: () => {},
  },
  edit: () => ({ focus: () => {} }),
};

describe('EditBlob', () => {
  beforeEach(() => {
    setFixtures(`
      <div class="js-edit-blob-form">
        <button class="js-commit-button"></button>
        <a class="btn btn-cancel" href="#"></a>
      </div>`);
    blobBundle();
  });

  it('sets the window beforeunload listener to a function returning a string', () => {
    expect(window.onbeforeunload()).toBe('');
  });

  it('removes beforeunload listener if commit button is clicked', () => {
    $('.js-commit-button').click();

    expect(window.onbeforeunload).toBeNull();
  });

  it('removes beforeunload listener when cancel link is clicked', () => {
    $('.btn.btn-cancel').click();

    expect(window.onbeforeunload).toBeNull();
  });
});