summaryrefslogtreecommitdiff
path: root/spec/frontend/packages/details/components/npm_installation_spec.js
blob: dd6e62185a99c10775829717477c22c91b9e6cc7 (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
import Vuex from 'vuex';
import { shallowMount, createLocalVue } from '@vue/test-utils';
import { npmPackage as packageEntity } from 'jest/packages/mock_data';
import { registryUrl as nugetPath } from 'jest/packages/details/mock_data';
import NpmInstallation from '~/packages/details/components/npm_installation.vue';
import CodeInstructions from '~/vue_shared/components/registry/code_instruction.vue';
import { TrackingActions } from '~/packages/details/constants';
import { npmInstallationCommand, npmSetupCommand } from '~/packages/details/store/getters';

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

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

  const findCodeInstructions = () => wrapper.findAll(CodeInstructions);

  function createComponent() {
    const store = new Vuex.Store({
      state: {
        packageEntity,
        nugetPath,
      },
      getters: {
        npmInstallationCommand,
        npmSetupCommand,
      },
    });

    wrapper = shallowMount(NpmInstallation, {
      localVue,
      store,
    });
  }

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

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

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

  describe('installation commands', () => {
    it('renders the correct npm command', () => {
      expect(findCodeInstructions().at(0).props()).toMatchObject({
        instruction: 'npm i @Test/package',
        multiline: false,
        trackingAction: TrackingActions.COPY_NPM_INSTALL_COMMAND,
      });
    });

    it('renders the correct yarn command', () => {
      expect(findCodeInstructions().at(1).props()).toMatchObject({
        instruction: 'yarn add @Test/package',
        multiline: false,
        trackingAction: TrackingActions.COPY_YARN_INSTALL_COMMAND,
      });
    });
  });

  describe('setup commands', () => {
    it('renders the correct npm command', () => {
      expect(findCodeInstructions().at(2).props()).toMatchObject({
        instruction: 'echo @Test:registry=undefined/ >> .npmrc',
        multiline: false,
        trackingAction: TrackingActions.COPY_NPM_SETUP_COMMAND,
      });
    });

    it('renders the correct yarn command', () => {
      expect(findCodeInstructions().at(3).props()).toMatchObject({
        instruction: 'echo \\"@Test:registry\\" \\"undefined/\\" >> .yarnrc',
        multiline: false,
        trackingAction: TrackingActions.COPY_YARN_SETUP_COMMAND,
      });
    });
  });
});