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

publish_toolbar_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: 9ba7e4a94d16183ab377f9ba2860796d2af0e38b (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
85
86
87
88
89
90
91
92
import { shallowMount } from '@vue/test-utils';

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: {
        hasSettings: false,
        saveable: false,
        ...propsData,
      },
    });
  };

  const findReturnUrlLink = () => wrapper.find({ ref: 'returnUrlLink' });
  const findSaveChangesButton = () => wrapper.find({ ref: 'submit' });
  const findEditSettingsButton = () => wrapper.find({ ref: 'settings' });

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

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

  it('does not render Settings button', () => {
    expect(findEditSettingsButton().exists()).toBe(false);
  });

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

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

  it('does not render the Submit Changes button with a loader', () => {
    expect(findSaveChangesButton().props('loading')).toBe(false);
  });

  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 providing settings CTA', () => {
    it('enables Submit Changes button', () => {
      buildWrapper({ hasSettings: true });

      expect(findEditSettingsButton().exists()).toBe(true);
    });
  });

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

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

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

    it('renders the Submit Changes button with a loading indicator', () => {
      expect(findSaveChangesButton().props('loading')).toBe(true);
    });
  });

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

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

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