summaryrefslogtreecommitdiff
path: root/spec/frontend/packages/details/components/pypi_installation_spec.js
blob: 2cec84282d952003eacf5fcc840f206770647838 (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
import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex';
import { pypiPackage as packageEntity } from 'jest/packages/mock_data';
import InstallationTitle from '~/packages/details/components/installation_title.vue';
import PypiInstallation from '~/packages/details/components/pypi_installation.vue';

const localVue = createLocalVue();
localVue.use(Vuex);

describe('PypiInstallation', () => {
  let wrapper;

  const pipCommandStr = 'pip install';
  const pypiSetupStr = 'python setup';

  const store = new Vuex.Store({
    state: {
      packageEntity,
      pypiHelpPath: 'foo',
    },
    getters: {
      pypiPipCommand: () => pipCommandStr,
      pypiSetupCommand: () => pypiSetupStr,
    },
  });

  const pipCommand = () => wrapper.find('[data-testid="pip-command"]');
  const setupInstruction = () => wrapper.find('[data-testid="pypi-setup-content"]');

  const findInstallationTitle = () => wrapper.findComponent(InstallationTitle);

  function createComponent() {
    wrapper = shallowMount(PypiInstallation, {
      localVue,
      store,
    });
  }

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

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

  describe('install command switch', () => {
    it('has the installation title component', () => {
      expect(findInstallationTitle().exists()).toBe(true);
      expect(findInstallationTitle().props()).toMatchObject({
        packageType: 'pypi',
        options: [{ value: 'pypi', label: 'Show PyPi commands' }],
      });
    });
  });

  it('renders all the messages', () => {
    expect(wrapper.element).toMatchSnapshot();
  });

  describe('installation commands', () => {
    it('renders the correct pip command', () => {
      expect(pipCommand().props('instruction')).toBe(pipCommandStr);
    });
  });

  describe('setup commands', () => {
    it('renders the correct setup block', () => {
      expect(setupInstruction().props('instruction')).toBe(pypiSetupStr);
    });
  });
});