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

success_spec.js « pages « static_site_editor « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3e19e2413e775194b5ef88944ab1270728e68fc1 (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
93
94
95
96
97
98
99
100
101
import { shallowMount } from '@vue/test-utils';
import { GlEmptyState, GlButton } from '@gitlab/ui';
import Success from '~/static_site_editor/pages/success.vue';
import { savedContentMeta, returnUrl, sourcePath } from '../mock_data';
import { HOME_ROUTE } from '~/static_site_editor/router/constants';

describe('static_site_editor/pages/success', () => {
  const mergeRequestsIllustrationPath = 'illustrations/merge_requests.svg';
  let wrapper;
  let router;

  const buildRouter = () => {
    router = {
      push: jest.fn(),
    };
  };

  const buildWrapper = (data = {}) => {
    wrapper = shallowMount(Success, {
      mocks: {
        $router: router,
      },
      stubs: {
        GlEmptyState,
        GlButton,
      },
      propsData: {
        mergeRequestsIllustrationPath,
      },
      data() {
        return {
          savedContentMeta,
          appData: {
            returnUrl,
            sourcePath,
          },
          ...data,
        };
      },
    });
  };

  const findEmptyState = () => wrapper.find(GlEmptyState);
  const findReturnUrlButton = () => wrapper.find(GlButton);

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

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

  it('renders empty state with a link to the created merge request', () => {
    buildWrapper();

    expect(findEmptyState().exists()).toBe(true);
    expect(findEmptyState().props()).toMatchObject({
      primaryButtonText: 'View merge request',
      primaryButtonLink: savedContentMeta.mergeRequest.url,
      title: 'Your merge request has been created',
      svgPath: mergeRequestsIllustrationPath,
    });
  });

  it('displays merge request instructions in the empty state', () => {
    buildWrapper();

    expect(findEmptyState().text()).toContain(
      'To see your changes live you will need to do the following things:',
    );
    expect(findEmptyState().text()).toContain('1. Add a clear title to describe the change.');
    expect(findEmptyState().text()).toContain(
      '2. Add a description to explain why the change is being made.',
    );
    expect(findEmptyState().text()).toContain(
      '3. Assign a person to review and accept the merge request.',
    );
  });

  it('displays return to site button', () => {
    buildWrapper();

    expect(findReturnUrlButton().text()).toBe('Return to site');
    expect(findReturnUrlButton().attributes().href).toBe(returnUrl);
  });

  it('displays source path', () => {
    buildWrapper();

    expect(wrapper.text()).toContain(`Update ${sourcePath} file`);
  });

  it('redirects to the HOME route when content has not been submitted', () => {
    buildWrapper({ savedContentMeta: null });

    expect(router.push).toHaveBeenCalledWith(HOME_ROUTE);
    expect(wrapper.html()).toBe('');
  });
});