Welcome to mirror list, hosted at ThFree Co, Russian Federation.

unsaved_changes_confirm_dialog_spec.js « components « static_site_editor « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9b8b22da6934e57b50a0eed1c64427c391d3cfa6 (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
38
39
40
41
42
43
44
import { shallowMount } from '@vue/test-utils';

import UnsavedChangesConfirmDialog from '~/static_site_editor/components/unsaved_changes_confirm_dialog.vue';

describe('static_site_editor/components/unsaved_changes_confirm_dialog', () => {
  let wrapper;
  let event;
  let returnValueSetter;

  const buildWrapper = (propsData = {}) => {
    wrapper = shallowMount(UnsavedChangesConfirmDialog, {
      propsData,
    });
  };

  beforeEach(() => {
    event = new Event('beforeunload');

    jest.spyOn(event, 'preventDefault');
    returnValueSetter = jest.spyOn(event, 'returnValue', 'set');
  });

  afterEach(() => {
    event.preventDefault.mockRestore();
    returnValueSetter.mockRestore();
    wrapper.destroy();
  });

  it('displays confirmation dialog when modified = true', () => {
    buildWrapper({ modified: true });
    window.dispatchEvent(event);

    expect(event.preventDefault).toHaveBeenCalled();
    expect(returnValueSetter).toHaveBeenCalledWith('');
  });

  it('does not display confirmation dialog when modified = false', () => {
    buildWrapper();
    window.dispatchEvent(event);

    expect(event.preventDefault).not.toHaveBeenCalled();
    expect(returnValueSetter).not.toHaveBeenCalled();
  });
});