summaryrefslogtreecommitdiff
path: root/spec/frontend/projects/new/components/new_project_push_tip_popover_spec.js
blob: 31ddbc80ae44385f381ee05977b3fa05852304bc (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
import { GlPopover, GlFormInputGroup } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import NewProjectPushTipPopover from '~/projects/new/components/new_project_push_tip_popover.vue';
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';

describe('New project push tip popover', () => {
  let wrapper;
  const targetId = 'target';
  const pushToCreateProjectCommand = 'command';
  const workingWithProjectsHelpPath = 'path';

  const findPopover = () => wrapper.findComponent(GlPopover);
  const findClipboardButton = () => wrapper.findComponent(ClipboardButton);
  const findFormInput = () => wrapper.findComponent(GlFormInputGroup);
  const findHelpLink = () => wrapper.find('a');
  const findTarget = () => document.getElementById(targetId);

  const buildWrapper = () => {
    wrapper = shallowMount(NewProjectPushTipPopover, {
      propsData: {
        target: findTarget(),
      },
      stubs: {
        GlFormInputGroup,
      },
      provide: {
        pushToCreateProjectCommand,
        workingWithProjectsHelpPath,
      },
    });
  };

  beforeEach(() => {
    setFixtures(`<a id="${targetId}"></a>`);
    buildWrapper();
  });

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

  it('renders popover that targets the specified target', () => {
    expect(findPopover().props()).toMatchObject({
      target: findTarget(),
      triggers: 'click blur',
      placement: 'top',
      title: 'Push to create a project',
    });
  });

  it('renders a readonly form input with the push to create command', () => {
    expect(findFormInput().props()).toMatchObject({
      value: pushToCreateProjectCommand,
      selectOnClick: true,
    });
    expect(findFormInput().attributes()).toMatchObject({
      'aria-label': 'Push project from command line',
      readonly: 'readonly',
    });
  });

  it('allows copying the push command using the clipboard button', () => {
    expect(findClipboardButton().props()).toMatchObject({
      text: pushToCreateProjectCommand,
      tooltipPlacement: 'right',
      title: 'Copy command',
    });
  });

  it('displays a link to open the push command help page reference', () => {
    expect(findHelpLink().attributes().href).toBe(
      `${workingWithProjectsHelpPath}#push-to-create-a-new-project`,
    );
  });
});