summaryrefslogtreecommitdiff
path: root/spec/frontend/static_site_editor/components/publish_toolbar_spec.js
blob: f00fc38430f2048cd452d9c09b286eaf6181a687 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { shallowMount } from '@vue/test-utils';
import { GlNewButton, GlLoadingIcon } from '@gitlab/ui';

import PublishToolbar from '~/static_site_editor/components/publish_toolbar.vue';

import { returnUrl } from '../mock_data';

describe('Static Site Editor Toolbar', () => {
  let wrapper;

  const buildWrapper = (propsData = {}) => {
    wrapper = shallowMount(PublishToolbar, {
      propsData: {
        saveable: false,
        ...propsData,
      },
    });
  };

  const findReturnUrlLink = () => wrapper.find({ ref: 'returnUrlLink' });
  const findSaveChangesButton = () => wrapper.find(GlNewButton);
  const findLoadingIndicator = () => wrapper.find(GlLoadingIcon);

  beforeEach(() => {
    buildWrapper();
  });

  afterEach(() => {
    wrapper.destroy();
  });

  it('renders Submit Changes button', () => {
    expect(findSaveChangesButton().exists()).toBe(true);
  });

  it('disables Submit Changes button', () => {
    expect(findSaveChangesButton().attributes('disabled')).toBe('true');
  });

  it('does not display saving changes indicator', () => {
    expect(findLoadingIndicator().classes()).toContain('invisible');
  });

  it('does not render returnUrl link', () => {
    expect(findReturnUrlLink().exists()).toBe(false);
  });

  it('renders returnUrl link when returnUrl prop exists', () => {
    buildWrapper({ returnUrl });

    expect(findReturnUrlLink().exists()).toBe(true);
    expect(findReturnUrlLink().attributes('href')).toBe(returnUrl);
  });

  describe('when saveable', () => {
    it('enables Submit Changes button', () => {
      buildWrapper({ saveable: true });

      expect(findSaveChangesButton().attributes('disabled')).toBeFalsy();
    });
  });

  describe('when saving changes', () => {
    beforeEach(() => {
      buildWrapper({ saveable: true, savingChanges: true });
    });

    it('disables Submit Changes button', () => {
      expect(findSaveChangesButton().attributes('disabled')).toBe('true');
    });

    it('displays saving changes indicator', () => {
      expect(findLoadingIndicator().classes()).not.toContain('invisible');
    });
  });

  it('emits submit event when submit button is clicked', () => {
    buildWrapper({ saveable: true });

    findSaveChangesButton().vm.$emit('click');

    expect(wrapper.emitted('submit')).toHaveLength(1);
  });
});