Commit 19c3dc1f authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch '330847-convert-package-details-page-to-use-graphql-3' into 'master'

Refactor Npm, Nuget  and Pypi installation commands

See merge request gitlab-org/gitlab!67594
parents fd3ad915 a85579da
...@@ -20,12 +20,12 @@ import { numberToHumanSize } from '~/lib/utils/number_utils'; ...@@ -20,12 +20,12 @@ import { numberToHumanSize } from '~/lib/utils/number_utils';
import { objectToQuery } from '~/lib/utils/url_utility'; import { objectToQuery } from '~/lib/utils/url_utility';
import { s__, __ } from '~/locale'; import { s__, __ } from '~/locale';
// import DependencyRow from '~/packages/details/components/dependency_row.vue'; // import DependencyRow from '~/packages/details/components/dependency_row.vue';
// import InstallationCommands from '~/packages/details/components/installation_commands.vue';
// import PackageFiles from '~/packages/details/components/package_files.vue'; // import PackageFiles from '~/packages/details/components/package_files.vue';
// import PackageListRow from '~/packages/shared/components/package_list_row.vue'; // import PackageListRow from '~/packages/shared/components/package_list_row.vue';
import PackagesListLoader from '~/packages/shared/components/packages_list_loader.vue'; import PackagesListLoader from '~/packages/shared/components/packages_list_loader.vue';
import { packageTypeToTrackCategory } from '~/packages/shared/utils'; import { packageTypeToTrackCategory } from '~/packages/shared/utils';
import AdditionalMetadata from '~/packages_and_registries/package_registry/components/details/additional_metadata.vue'; import AdditionalMetadata from '~/packages_and_registries/package_registry/components/details/additional_metadata.vue';
import InstallationCommands from '~/packages_and_registries/package_registry/components/details/installation_commands.vue';
import PackageHistory from '~/packages_and_registries/package_registry/components/details/package_history.vue'; import PackageHistory from '~/packages_and_registries/package_registry/components/details/package_history.vue';
import { import {
PACKAGE_TYPE_NUGET, PACKAGE_TYPE_NUGET,
...@@ -62,7 +62,7 @@ export default { ...@@ -62,7 +62,7 @@ export default {
// DependencyRow, // DependencyRow,
PackageHistory, PackageHistory,
AdditionalMetadata, AdditionalMetadata,
// InstallationCommands, InstallationCommands,
// PackageFiles, // PackageFiles,
}, },
directives: { directives: {
...@@ -240,11 +240,7 @@ export default { ...@@ -240,11 +240,7 @@ export default {
<div v-if="!isLoading" data-qa-selector="package_information_content"> <div v-if="!isLoading" data-qa-selector="package_information_content">
<package-history :package-entity="packageEntity" :project-name="projectName" /> <package-history :package-entity="packageEntity" :project-name="projectName" />
<!-- <installation-commands <installation-commands :package-entity="packageEntity" />
:package-entity="packageEntity"
:npm-path="npmPath"
:npm-help-path="npmHelpPath"
/> -->
<additional-metadata :package-entity="packageEntity" /> <additional-metadata :package-entity="packageEntity" />
</div> </div>
......
<script> <script>
import { GlLink, GlSprintf } from '@gitlab/ui'; import { GlLink, GlSprintf } from '@gitlab/ui';
import { mapGetters, mapState } from 'vuex';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import { NpmManager, TrackingActions, TrackingLabels } from '~/packages/details/constants';
import InstallationTitle from '~/packages_and_registries/package_registry/components/details/installation_title.vue'; import InstallationTitle from '~/packages_and_registries/package_registry/components/details/installation_title.vue';
import {
TRACKING_ACTION_COPY_NPM_INSTALL_COMMAND,
TRACKING_ACTION_COPY_NPM_SETUP_COMMAND,
TRACKING_ACTION_COPY_YARN_INSTALL_COMMAND,
TRACKING_ACTION_COPY_YARN_SETUP_COMMAND,
TRACKING_LABEL_CODE_INSTRUCTION,
NPM_PACKAGE_MANAGER,
YARN_PACKAGE_MANAGER,
} from '~/packages_and_registries/package_registry/constants';
import CodeInstruction from '~/vue_shared/components/registry/code_instruction.vue'; import CodeInstruction from '~/vue_shared/components/registry/code_instruction.vue';
export default { export default {
...@@ -14,40 +22,70 @@ export default { ...@@ -14,40 +22,70 @@ export default {
GlLink, GlLink,
GlSprintf, GlSprintf,
}, },
inject: ['npmHelpPath', 'npmPath'],
props: {
packageEntity: {
type: Object,
required: true,
},
},
data() { data() {
return { return {
instructionType: 'npm', instructionType: NPM_PACKAGE_MANAGER,
}; };
}, },
computed: { computed: {
...mapState(['npmHelpPath']),
...mapGetters(['npmInstallationCommand', 'npmSetupCommand']),
npmCommand() { npmCommand() {
return this.npmInstallationCommand(NpmManager.NPM); return this.npmInstallationCommand(NPM_PACKAGE_MANAGER);
}, },
npmSetup() { npmSetup() {
return this.npmSetupCommand(NpmManager.NPM); return this.npmSetupCommand(NPM_PACKAGE_MANAGER);
}, },
yarnCommand() { yarnCommand() {
return this.npmInstallationCommand(NpmManager.YARN); return this.npmInstallationCommand(YARN_PACKAGE_MANAGER);
}, },
yarnSetupCommand() { yarnSetupCommand() {
return this.npmSetupCommand(NpmManager.YARN); return this.npmSetupCommand(YARN_PACKAGE_MANAGER);
}, },
showNpm() { showNpm() {
return this.instructionType === 'npm'; return this.instructionType === NPM_PACKAGE_MANAGER;
},
},
methods: {
npmInstallationCommand(type) {
// eslint-disable-next-line @gitlab/require-i18n-strings
const instruction = type === NPM_PACKAGE_MANAGER ? 'npm i' : 'yarn add';
return `${instruction} ${this.packageEntity.name}`;
},
npmSetupCommand(type) {
const scope = this.packageEntity.name.substring(0, this.packageEntity.name.indexOf('/'));
if (type === NPM_PACKAGE_MANAGER) {
return `echo ${scope}:registry=${this.npmPath}/ >> .npmrc`;
}
return `echo \\"${scope}:registry\\" \\"${this.npmPath}/\\" >> .yarnrc`;
},
},
packageManagers: {
NPM_PACKAGE_MANAGER,
}, },
tracking: {
TRACKING_ACTION_COPY_NPM_INSTALL_COMMAND,
TRACKING_ACTION_COPY_NPM_SETUP_COMMAND,
TRACKING_ACTION_COPY_YARN_INSTALL_COMMAND,
TRACKING_ACTION_COPY_YARN_SETUP_COMMAND,
TRACKING_LABEL_CODE_INSTRUCTION,
}, },
i18n: { i18n: {
helpText: s__( helpText: s__(
'PackageRegistry|You may also need to setup authentication using an auth token. %{linkStart}See the documentation%{linkEnd} to find out more.', 'PackageRegistry|You may also need to setup authentication using an auth token. %{linkStart}See the documentation%{linkEnd} to find out more.',
), ),
}, },
trackingActions: { ...TrackingActions },
TrackingLabels,
installOptions: [ installOptions: [
{ value: 'npm', label: s__('PackageRegistry|Show NPM commands') }, { value: NPM_PACKAGE_MANAGER, label: s__('PackageRegistry|Show NPM commands') },
{ value: 'yarn', label: s__('PackageRegistry|Show Yarn commands') }, { value: YARN_PACKAGE_MANAGER, label: s__('PackageRegistry|Show Yarn commands') },
], ],
}; };
</script> </script>
...@@ -55,7 +93,7 @@ export default { ...@@ -55,7 +93,7 @@ export default {
<template> <template>
<div> <div>
<installation-title <installation-title
package-type="npm" :package-type="$options.packageManagers.NPM_PACKAGE_MANAGER"
:options="$options.installOptions" :options="$options.installOptions"
@change="instructionType = $event" @change="instructionType = $event"
/> />
...@@ -64,16 +102,16 @@ export default { ...@@ -64,16 +102,16 @@ export default {
v-if="showNpm" v-if="showNpm"
:instruction="npmCommand" :instruction="npmCommand"
:copy-text="s__('PackageRegistry|Copy npm command')" :copy-text="s__('PackageRegistry|Copy npm command')"
:tracking-action="$options.trackingActions.COPY_NPM_INSTALL_COMMAND" :tracking-action="$options.tracking.TRACKING_ACTION_COPY_NPM_INSTALL_COMMAND"
:tracking-label="$options.TrackingLabels.CODE_INSTRUCTION" :tracking-label="$options.tracking.TRACKING_LABEL_CODE_INSTRUCTION"
/> />
<code-instruction <code-instruction
v-else v-else
:instruction="yarnCommand" :instruction="yarnCommand"
:copy-text="s__('PackageRegistry|Copy yarn command')" :copy-text="s__('PackageRegistry|Copy yarn command')"
:tracking-action="$options.trackingActions.COPY_YARN_INSTALL_COMMAND" :tracking-action="$options.tracking.TRACKING_ACTION_COPY_YARN_INSTALL_COMMAND"
:tracking-label="$options.TrackingLabels.CODE_INSTRUCTION" :tracking-label="$options.tracking.TRACKING_LABEL_CODE_INSTRUCTION"
/> />
<h3 class="gl-font-lg">{{ __('Registry setup') }}</h3> <h3 class="gl-font-lg">{{ __('Registry setup') }}</h3>
...@@ -82,16 +120,16 @@ export default { ...@@ -82,16 +120,16 @@ export default {
v-if="showNpm" v-if="showNpm"
:instruction="npmSetup" :instruction="npmSetup"
:copy-text="s__('PackageRegistry|Copy npm setup command')" :copy-text="s__('PackageRegistry|Copy npm setup command')"
:tracking-action="$options.trackingActions.COPY_NPM_SETUP_COMMAND" :tracking-action="$options.tracking.TRACKING_ACTION_COPY_NPM_SETUP_COMMAND"
:tracking-label="$options.TrackingLabels.CODE_INSTRUCTION" :tracking-label="$options.tracking.TRACKING_LABEL_CODE_INSTRUCTION"
/> />
<code-instruction <code-instruction
v-else v-else
:instruction="yarnSetupCommand" :instruction="yarnSetupCommand"
:copy-text="s__('PackageRegistry|Copy yarn setup command')" :copy-text="s__('PackageRegistry|Copy yarn setup command')"
:tracking-action="$options.trackingActions.COPY_YARN_SETUP_COMMAND" :tracking-action="$options.tracking.TRACKING_ACTION_COPY_YARN_SETUP_COMMAND"
:tracking-label="$options.TrackingLabels.CODE_INSTRUCTION" :tracking-label="$options.tracking.TRACKING_LABEL_CODE_INSTRUCTION"
/> />
<gl-sprintf :message="$options.i18n.helpText"> <gl-sprintf :message="$options.i18n.helpText">
......
<script> <script>
import { GlLink, GlSprintf } from '@gitlab/ui'; import { GlLink, GlSprintf } from '@gitlab/ui';
import { mapGetters, mapState } from 'vuex';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import { TrackingActions, TrackingLabels } from '~/packages/details/constants';
import InstallationTitle from '~/packages_and_registries/package_registry/components/details/installation_title.vue'; import InstallationTitle from '~/packages_and_registries/package_registry/components/details/installation_title.vue';
import {
TRACKING_ACTION_COPY_NUGET_INSTALL_COMMAND,
TRACKING_ACTION_COPY_NUGET_SETUP_COMMAND,
TRACKING_LABEL_CODE_INSTRUCTION,
} from '~/packages_and_registries/package_registry/constants';
import CodeInstruction from '~/vue_shared/components/registry/code_instruction.vue'; import CodeInstruction from '~/vue_shared/components/registry/code_instruction.vue';
export default { export default {
...@@ -14,17 +17,31 @@ export default { ...@@ -14,17 +17,31 @@ export default {
GlLink, GlLink,
GlSprintf, GlSprintf,
}, },
inject: ['nugetHelpPath', 'nugetPath'],
props: {
packageEntity: {
type: Object,
required: true,
},
},
computed: { computed: {
...mapState(['nugetHelpPath']), nugetInstallationCommand() {
...mapGetters(['nugetInstallationCommand', 'nugetSetupCommand']), return `nuget install ${this.packageEntity.name} -Source "GitLab"`;
},
nugetSetupCommand() {
return `nuget source Add -Name "GitLab" -Source "${this.nugetPath}" -UserName <your_username> -Password <your_token>`;
},
},
tracking: {
TRACKING_ACTION_COPY_NUGET_INSTALL_COMMAND,
TRACKING_ACTION_COPY_NUGET_SETUP_COMMAND,
TRACKING_LABEL_CODE_INSTRUCTION,
}, },
i18n: { i18n: {
helpText: s__( helpText: s__(
'PackageRegistry|For more information on the NuGet registry, %{linkStart}see the documentation%{linkEnd}.', 'PackageRegistry|For more information on the NuGet registry, %{linkStart}see the documentation%{linkEnd}.',
), ),
}, },
trackingActions: { ...TrackingActions },
TrackingLabels,
installOptions: [{ value: 'nuget', label: s__('PackageRegistry|Show Nuget commands') }], installOptions: [{ value: 'nuget', label: s__('PackageRegistry|Show Nuget commands') }],
}; };
</script> </script>
...@@ -37,8 +54,8 @@ export default { ...@@ -37,8 +54,8 @@ export default {
:label="s__('PackageRegistry|NuGet Command')" :label="s__('PackageRegistry|NuGet Command')"
:instruction="nugetInstallationCommand" :instruction="nugetInstallationCommand"
:copy-text="s__('PackageRegistry|Copy NuGet Command')" :copy-text="s__('PackageRegistry|Copy NuGet Command')"
:tracking-action="$options.trackingActions.COPY_NUGET_INSTALL_COMMAND" :tracking-action="$options.tracking.TRACKING_ACTION_COPY_NUGET_INSTALL_COMMAND"
:tracking-label="$options.TrackingLabels.CODE_INSTRUCTION" :tracking-label="$options.tracking.TRACKING_LABEL_CODE_INSTRUCTION"
/> />
<h3 class="gl-font-lg">{{ __('Registry setup') }}</h3> <h3 class="gl-font-lg">{{ __('Registry setup') }}</h3>
...@@ -46,8 +63,8 @@ export default { ...@@ -46,8 +63,8 @@ export default {
:label="s__('PackageRegistry|Add NuGet Source')" :label="s__('PackageRegistry|Add NuGet Source')"
:instruction="nugetSetupCommand" :instruction="nugetSetupCommand"
:copy-text="s__('PackageRegistry|Copy NuGet Setup Command')" :copy-text="s__('PackageRegistry|Copy NuGet Setup Command')"
:tracking-action="$options.trackingActions.COPY_NUGET_SETUP_COMMAND" :tracking-action="$options.tracking.TRACKING_ACTION_COPY_NUGET_SETUP_COMMAND"
:tracking-label="$options.TrackingLabels.CODE_INSTRUCTION" :tracking-label="$options.tracking.TRACKING_LABEL_CODE_INSTRUCTION"
/> />
<gl-sprintf :message="$options.i18n.helpText"> <gl-sprintf :message="$options.i18n.helpText">
<template #link="{ content }"> <template #link="{ content }">
......
<script> <script>
import { GlLink, GlSprintf } from '@gitlab/ui'; import { GlLink, GlSprintf } from '@gitlab/ui';
import { mapGetters, mapState } from 'vuex';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import { TrackingActions, TrackingLabels } from '~/packages/details/constants';
import InstallationTitle from '~/packages_and_registries/package_registry/components/details/installation_title.vue'; import InstallationTitle from '~/packages_and_registries/package_registry/components/details/installation_title.vue';
import {
TRACKING_ACTION_COPY_PIP_INSTALL_COMMAND,
TRACKING_ACTION_COPY_PYPI_SETUP_COMMAND,
TRACKING_LABEL_CODE_INSTRUCTION,
} from '~/packages_and_registries/package_registry/constants';
import CodeInstruction from '~/vue_shared/components/registry/code_instruction.vue'; import CodeInstruction from '~/vue_shared/components/registry/code_instruction.vue';
export default { export default {
...@@ -14,9 +18,29 @@ export default { ...@@ -14,9 +18,29 @@ export default {
GlLink, GlLink,
GlSprintf, GlSprintf,
}, },
inject: ['pypiHelpPath', 'pypiPath', 'pypiSetupPath'],
props: {
packageEntity: {
type: Object,
required: true,
},
},
computed: { computed: {
...mapState(['pypiHelpPath']), pypiPipCommand() {
...mapGetters(['pypiPipCommand', 'pypiSetupCommand']), // eslint-disable-next-line @gitlab/require-i18n-strings
return `pip install ${this.packageEntity.name} --extra-index-url ${this.pypiPath}`;
},
pypiSetupCommand() {
return `[gitlab]
repository = ${this.pypiSetupPath}
username = __token__
password = <your personal access token>`;
},
},
tracking: {
TRACKING_ACTION_COPY_PIP_INSTALL_COMMAND,
TRACKING_ACTION_COPY_PYPI_SETUP_COMMAND,
TRACKING_LABEL_CODE_INSTRUCTION,
}, },
i18n: { i18n: {
setupText: s__( setupText: s__(
...@@ -26,8 +50,6 @@ export default { ...@@ -26,8 +50,6 @@ export default {
'PackageRegistry|For more information on the PyPi registry, %{linkStart}see the documentation%{linkEnd}.', 'PackageRegistry|For more information on the PyPi registry, %{linkStart}see the documentation%{linkEnd}.',
), ),
}, },
trackingActions: { ...TrackingActions },
TrackingLabels,
installOptions: [{ value: 'pypi', label: s__('PackageRegistry|Show PyPi commands') }], installOptions: [{ value: 'pypi', label: s__('PackageRegistry|Show PyPi commands') }],
}; };
</script> </script>
...@@ -41,8 +63,8 @@ export default { ...@@ -41,8 +63,8 @@ export default {
:instruction="pypiPipCommand" :instruction="pypiPipCommand"
:copy-text="s__('PackageRegistry|Copy Pip command')" :copy-text="s__('PackageRegistry|Copy Pip command')"
data-testid="pip-command" data-testid="pip-command"
:tracking-action="$options.trackingActions.COPY_PIP_INSTALL_COMMAND" :tracking-action="$options.tracking.TRACKING_ACTION_COPY_PIP_INSTALL_COMMAND"
:tracking-label="$options.TrackingLabels.CODE_INSTRUCTION" :tracking-label="$options.tracking.TRACKING_LABEL_CODE_INSTRUCTION"
/> />
<h3 class="gl-font-lg">{{ __('Registry setup') }}</h3> <h3 class="gl-font-lg">{{ __('Registry setup') }}</h3>
...@@ -59,8 +81,8 @@ export default { ...@@ -59,8 +81,8 @@ export default {
:copy-text="s__('PackageRegistry|Copy .pypirc content')" :copy-text="s__('PackageRegistry|Copy .pypirc content')"
data-testid="pypi-setup-content" data-testid="pypi-setup-content"
multiline multiline
:tracking-action="$options.trackingActions.COPY_PYPI_SETUP_COMMAND" :tracking-action="$options.tracking.TRACKING_ACTION_COPY_PYPI_SETUP_COMMAND"
:tracking-label="$options.TrackingLabels.CODE_INSTRUCTION" :tracking-label="$options.tracking.TRACKING_LABEL_CODE_INSTRUCTION"
/> />
<gl-sprintf :message="$options.i18n.helpText"> <gl-sprintf :message="$options.i18n.helpText">
<template #link="{ content }"> <template #link="{ content }">
......
...@@ -83,3 +83,6 @@ export const PACKAGE_ERROR_STATUS = 'error'; ...@@ -83,3 +83,6 @@ export const PACKAGE_ERROR_STATUS = 'error';
export const PACKAGE_DEFAULT_STATUS = 'default'; export const PACKAGE_DEFAULT_STATUS = 'default';
export const PACKAGE_HIDDEN_STATUS = 'hidden'; export const PACKAGE_HIDDEN_STATUS = 'hidden';
export const PACKAGE_PROCESSING_STATUS = 'processing'; export const PACKAGE_PROCESSING_STATUS = 'processing';
export const NPM_PACKAGE_MANAGER = 'npm';
export const YARN_PACKAGE_MANAGER = 'yarn';
...@@ -9,7 +9,7 @@ exports[`NpmInstallation renders all the messages 1`] = ` ...@@ -9,7 +9,7 @@ exports[`NpmInstallation renders all the messages 1`] = `
<code-instruction-stub <code-instruction-stub
copytext="Copy npm command" copytext="Copy npm command"
instruction="npm i @Test/package" instruction="npm i @gitlab-org/package-15"
label="" label=""
trackingaction="copy_npm_install_command" trackingaction="copy_npm_install_command"
trackinglabel="code_instruction" trackinglabel="code_instruction"
...@@ -23,7 +23,7 @@ exports[`NpmInstallation renders all the messages 1`] = ` ...@@ -23,7 +23,7 @@ exports[`NpmInstallation renders all the messages 1`] = `
<code-instruction-stub <code-instruction-stub
copytext="Copy npm setup command" copytext="Copy npm setup command"
instruction="echo @Test:registry=undefined/ >> .npmrc" instruction="echo @gitlab-org:registry=npmPath/ >> .npmrc"
label="" label=""
trackingaction="copy_npm_setup_command" trackingaction="copy_npm_setup_command"
trackinglabel="code_instruction" trackinglabel="code_instruction"
......
...@@ -9,7 +9,7 @@ exports[`NugetInstallation renders all the messages 1`] = ` ...@@ -9,7 +9,7 @@ exports[`NugetInstallation renders all the messages 1`] = `
<code-instruction-stub <code-instruction-stub
copytext="Copy NuGet Command" copytext="Copy NuGet Command"
instruction="foo/command" instruction="nuget install @gitlab-org/package-15 -Source \\"GitLab\\""
label="NuGet Command" label="NuGet Command"
trackingaction="copy_nuget_install_command" trackingaction="copy_nuget_install_command"
trackinglabel="code_instruction" trackinglabel="code_instruction"
...@@ -23,7 +23,7 @@ exports[`NugetInstallation renders all the messages 1`] = ` ...@@ -23,7 +23,7 @@ exports[`NugetInstallation renders all the messages 1`] = `
<code-instruction-stub <code-instruction-stub
copytext="Copy NuGet Setup Command" copytext="Copy NuGet Setup Command"
instruction="foo/setup" instruction="nuget source Add -Name \\"GitLab\\" -Source \\"nugetPath\\" -UserName <your_username> -Password <your_token>"
label="Add NuGet Source" label="Add NuGet Source"
trackingaction="copy_nuget_setup_command" trackingaction="copy_nuget_setup_command"
trackinglabel="code_instruction" trackinglabel="code_instruction"
......
...@@ -10,7 +10,7 @@ exports[`PypiInstallation renders all the messages 1`] = ` ...@@ -10,7 +10,7 @@ exports[`PypiInstallation renders all the messages 1`] = `
<code-instruction-stub <code-instruction-stub
copytext="Copy Pip command" copytext="Copy Pip command"
data-testid="pip-command" data-testid="pip-command"
instruction="pip install" instruction="pip install @gitlab-org/package-15 --extra-index-url pypiPath"
label="Pip Command" label="Pip Command"
trackingaction="copy_pip_install_command" trackingaction="copy_pip_install_command"
trackinglabel="code_instruction" trackinglabel="code_instruction"
...@@ -31,7 +31,10 @@ exports[`PypiInstallation renders all the messages 1`] = ` ...@@ -31,7 +31,10 @@ exports[`PypiInstallation renders all the messages 1`] = `
<code-instruction-stub <code-instruction-stub
copytext="Copy .pypirc content" copytext="Copy .pypirc content"
data-testid="pypi-setup-content" data-testid="pypi-setup-content"
instruction="python setup" instruction="[gitlab]
repository = pypiSetupPath
username = __token__
password = <your personal access token>"
label="" label=""
multiline="true" multiline="true"
trackingaction="copy_pypi_setup_command" trackingaction="copy_pypi_setup_command"
......
...@@ -7,6 +7,7 @@ import createFlash from '~/flash'; ...@@ -7,6 +7,7 @@ import createFlash from '~/flash';
import AdditionalMetadata from '~/packages_and_registries/package_registry/components/details/additional_metadata.vue'; import AdditionalMetadata from '~/packages_and_registries/package_registry/components/details/additional_metadata.vue';
import PackagesApp from '~/packages_and_registries/package_registry/components/details/app.vue'; import PackagesApp from '~/packages_and_registries/package_registry/components/details/app.vue';
import InstallationCommands from '~/packages_and_registries/package_registry/components/details/installation_commands.vue';
import PackageHistory from '~/packages_and_registries/package_registry/components/details/package_history.vue'; import PackageHistory from '~/packages_and_registries/package_registry/components/details/package_history.vue';
import PackageTitle from '~/packages_and_registries/package_registry/components/details/package_title.vue'; import PackageTitle from '~/packages_and_registries/package_registry/components/details/package_title.vue';
import { FETCH_PACKAGE_DETAILS_ERROR_MESSAGE } from '~/packages_and_registries/package_registry/constants'; import { FETCH_PACKAGE_DETAILS_ERROR_MESSAGE } from '~/packages_and_registries/package_registry/constants';
...@@ -50,6 +51,7 @@ describe('PackagesApp', () => { ...@@ -50,6 +51,7 @@ describe('PackagesApp', () => {
const findPackageTitle = () => wrapper.findComponent(PackageTitle); const findPackageTitle = () => wrapper.findComponent(PackageTitle);
const findPackageHistory = () => wrapper.findComponent(PackageHistory); const findPackageHistory = () => wrapper.findComponent(PackageHistory);
const findAdditionalMetadata = () => wrapper.findComponent(AdditionalMetadata); const findAdditionalMetadata = () => wrapper.findComponent(AdditionalMetadata);
const findInstallationCommands = () => wrapper.findComponent(InstallationCommands);
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
...@@ -108,4 +110,15 @@ describe('PackagesApp', () => { ...@@ -108,4 +110,15 @@ describe('PackagesApp', () => {
packageEntity: expect.objectContaining(packageData()), packageEntity: expect.objectContaining(packageData()),
}); });
}); });
it('renders installation commands and has the right props', async () => {
createComponent();
await waitForPromises();
expect(findInstallationCommands().exists()).toBe(true);
expect(findInstallationCommands().props()).toMatchObject({
packageEntity: expect.objectContaining(packageData()),
});
});
}); });
import { shallowMount, createLocalVue } from '@vue/test-utils';
import { nextTick } from 'vue'; import { nextTick } from 'vue';
import Vuex from 'vuex'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import { registryUrl as nugetPath } from 'jest/packages/details/mock_data';
import { npmPackage as packageEntity } from 'jest/packages/mock_data'; import { packageData } from 'jest/packages_and_registries/package_registry/mock_data';
import { TrackingActions } from '~/packages/details/constants';
import { npmInstallationCommand, npmSetupCommand } from '~/packages/details/store/getters';
import InstallationTitle from '~/packages_and_registries/package_registry/components/details/installation_title.vue'; import InstallationTitle from '~/packages_and_registries/package_registry/components/details/installation_title.vue';
import NpmInstallation from '~/packages_and_registries/package_registry/components/details/npm_installation.vue'; import NpmInstallation from '~/packages_and_registries/package_registry/components/details/npm_installation.vue';
import {
TRACKING_ACTION_COPY_NPM_INSTALL_COMMAND,
TRACKING_ACTION_COPY_NPM_SETUP_COMMAND,
TRACKING_ACTION_COPY_YARN_INSTALL_COMMAND,
TRACKING_ACTION_COPY_YARN_SETUP_COMMAND,
PACKAGE_TYPE_NPM,
NPM_PACKAGE_MANAGER,
YARN_PACKAGE_MANAGER,
} from '~/packages_and_registries/package_registry/constants';
import CodeInstructions from '~/vue_shared/components/registry/code_instruction.vue'; import CodeInstructions from '~/vue_shared/components/registry/code_instruction.vue';
const localVue = createLocalVue(); const packageEntity = { ...packageData(), packageType: PACKAGE_TYPE_NPM };
localVue.use(Vuex);
describe('NpmInstallation', () => { describe('NpmInstallation', () => {
let wrapper; let wrapper;
const npmInstallationCommandLabel = 'npm i @Test/package'; const npmInstallationCommandLabel = 'npm i @gitlab-org/package-15';
const yarnInstallationCommandLabel = 'yarn add @Test/package'; const yarnInstallationCommandLabel = 'yarn add @gitlab-org/package-15';
const findCodeInstructions = () => wrapper.findAll(CodeInstructions); const findCodeInstructions = () => wrapper.findAllComponents(CodeInstructions);
const findInstallationTitle = () => wrapper.findComponent(InstallationTitle); const findInstallationTitle = () => wrapper.findComponent(InstallationTitle);
function createComponent({ data = {} } = {}) { function createComponent({ data = {} } = {}) {
const store = new Vuex.Store({ wrapper = shallowMountExtended(NpmInstallation, {
state: { provide: {
packageEntity, npmHelpPath: 'npmHelpPath',
nugetPath, npmPath: 'npmPath',
}, },
getters: { propsData: {
npmInstallationCommand, packageEntity,
npmSetupCommand,
}, },
});
wrapper = shallowMount(NpmInstallation, {
localVue,
store,
data() { data() {
return data; return data;
}, },
...@@ -58,10 +57,10 @@ describe('NpmInstallation', () => { ...@@ -58,10 +57,10 @@ describe('NpmInstallation', () => {
it('has the installation title component', () => { it('has the installation title component', () => {
expect(findInstallationTitle().exists()).toBe(true); expect(findInstallationTitle().exists()).toBe(true);
expect(findInstallationTitle().props()).toMatchObject({ expect(findInstallationTitle().props()).toMatchObject({
packageType: 'npm', packageType: NPM_PACKAGE_MANAGER,
options: [ options: [
{ value: 'npm', label: 'Show NPM commands' }, { value: NPM_PACKAGE_MANAGER, label: 'Show NPM commands' },
{ value: 'yarn', label: 'Show Yarn commands' }, { value: YARN_PACKAGE_MANAGER, label: 'Show Yarn commands' },
], ],
}); });
}); });
...@@ -70,7 +69,7 @@ describe('NpmInstallation', () => { ...@@ -70,7 +69,7 @@ describe('NpmInstallation', () => {
createComponent(); createComponent();
expect(findCodeInstructions().at(0).props('instruction')).toBe(npmInstallationCommandLabel); expect(findCodeInstructions().at(0).props('instruction')).toBe(npmInstallationCommandLabel);
findInstallationTitle().vm.$emit('change', 'yarn'); findInstallationTitle().vm.$emit('change', YARN_PACKAGE_MANAGER);
await nextTick(); await nextTick();
...@@ -86,37 +85,37 @@ describe('NpmInstallation', () => { ...@@ -86,37 +85,37 @@ describe('NpmInstallation', () => {
expect(findCodeInstructions().at(0).props()).toMatchObject({ expect(findCodeInstructions().at(0).props()).toMatchObject({
instruction: npmInstallationCommandLabel, instruction: npmInstallationCommandLabel,
multiline: false, multiline: false,
trackingAction: TrackingActions.COPY_NPM_INSTALL_COMMAND, trackingAction: TRACKING_ACTION_COPY_NPM_INSTALL_COMMAND,
}); });
}); });
it('renders the correct setup command', () => { it('renders the correct setup command', () => {
expect(findCodeInstructions().at(1).props()).toMatchObject({ expect(findCodeInstructions().at(1).props()).toMatchObject({
instruction: 'echo @Test:registry=undefined/ >> .npmrc', instruction: 'echo @gitlab-org:registry=npmPath/ >> .npmrc',
multiline: false, multiline: false,
trackingAction: TrackingActions.COPY_NPM_SETUP_COMMAND, trackingAction: TRACKING_ACTION_COPY_NPM_SETUP_COMMAND,
}); });
}); });
}); });
describe('yarn', () => { describe('yarn', () => {
beforeEach(() => { beforeEach(() => {
createComponent({ data: { instructionType: 'yarn' } }); createComponent({ data: { instructionType: YARN_PACKAGE_MANAGER } });
}); });
it('renders the correct setup command', () => { it('renders the correct setup command', () => {
expect(findCodeInstructions().at(0).props()).toMatchObject({ expect(findCodeInstructions().at(0).props()).toMatchObject({
instruction: yarnInstallationCommandLabel, instruction: yarnInstallationCommandLabel,
multiline: false, multiline: false,
trackingAction: TrackingActions.COPY_YARN_INSTALL_COMMAND, trackingAction: TRACKING_ACTION_COPY_YARN_INSTALL_COMMAND,
}); });
}); });
it('renders the correct registry command', () => { it('renders the correct registry command', () => {
expect(findCodeInstructions().at(1).props()).toMatchObject({ expect(findCodeInstructions().at(1).props()).toMatchObject({
instruction: 'echo \\"@Test:registry\\" \\"undefined/\\" >> .yarnrc', instruction: 'echo \\"@gitlab-org:registry\\" \\"npmPath/\\" >> .yarnrc',
multiline: false, multiline: false,
trackingAction: TrackingActions.COPY_YARN_SETUP_COMMAND, trackingAction: TRACKING_ACTION_COPY_YARN_SETUP_COMMAND,
}); });
}); });
}); });
......
import { shallowMount, createLocalVue } from '@vue/test-utils'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import Vuex from 'vuex'; import { packageData } from 'jest/packages_and_registries/package_registry/mock_data';
import { registryUrl as nugetPath } from 'jest/packages/details/mock_data';
import { nugetPackage as packageEntity } from 'jest/packages/mock_data';
import { TrackingActions } from '~/packages/details/constants';
import InstallationTitle from '~/packages_and_registries/package_registry/components/details/installation_title.vue'; import InstallationTitle from '~/packages_and_registries/package_registry/components/details/installation_title.vue';
import NugetInstallation from '~/packages_and_registries/package_registry/components/details/nuget_installation.vue'; import NugetInstallation from '~/packages_and_registries/package_registry/components/details/nuget_installation.vue';
import {
TRACKING_ACTION_COPY_NUGET_INSTALL_COMMAND,
TRACKING_ACTION_COPY_NUGET_SETUP_COMMAND,
PACKAGE_TYPE_NUGET,
} from '~/packages_and_registries/package_registry/constants';
import CodeInstructions from '~/vue_shared/components/registry/code_instruction.vue'; import CodeInstructions from '~/vue_shared/components/registry/code_instruction.vue';
const localVue = createLocalVue(); const packageEntity = { ...packageData(), packageType: PACKAGE_TYPE_NUGET };
localVue.use(Vuex);
describe('NugetInstallation', () => { describe('NugetInstallation', () => {
let wrapper; let wrapper;
const nugetInstallationCommandStr = 'foo/command'; const nugetInstallationCommandStr = 'nuget install @gitlab-org/package-15 -Source "GitLab"';
const nugetSetupCommandStr = 'foo/setup'; const nugetSetupCommandStr =
'nuget source Add -Name "GitLab" -Source "nugetPath" -UserName <your_username> -Password <your_token>';
const store = new Vuex.Store({ const findCodeInstructions = () => wrapper.findAllComponents(CodeInstructions);
state: {
packageEntity,
nugetPath,
},
getters: {
nugetInstallationCommand: () => nugetInstallationCommandStr,
nugetSetupCommand: () => nugetSetupCommandStr,
},
});
const findCodeInstructions = () => wrapper.findAll(CodeInstructions);
const findInstallationTitle = () => wrapper.findComponent(InstallationTitle); const findInstallationTitle = () => wrapper.findComponent(InstallationTitle);
function createComponent() { function createComponent() {
wrapper = shallowMount(NugetInstallation, { wrapper = shallowMountExtended(NugetInstallation, {
localVue, provide: {
store, nugetHelpPath: 'nugetHelpPath',
nugetPath: 'nugetPath',
},
propsData: {
packageEntity,
},
}); });
} }
...@@ -63,7 +59,7 @@ describe('NugetInstallation', () => { ...@@ -63,7 +59,7 @@ describe('NugetInstallation', () => {
it('renders the correct command', () => { it('renders the correct command', () => {
expect(findCodeInstructions().at(0).props()).toMatchObject({ expect(findCodeInstructions().at(0).props()).toMatchObject({
instruction: nugetInstallationCommandStr, instruction: nugetInstallationCommandStr,
trackingAction: TrackingActions.COPY_NUGET_INSTALL_COMMAND, trackingAction: TRACKING_ACTION_COPY_NUGET_INSTALL_COMMAND,
}); });
}); });
}); });
...@@ -72,7 +68,7 @@ describe('NugetInstallation', () => { ...@@ -72,7 +68,7 @@ describe('NugetInstallation', () => {
it('renders the correct command', () => { it('renders the correct command', () => {
expect(findCodeInstructions().at(1).props()).toMatchObject({ expect(findCodeInstructions().at(1).props()).toMatchObject({
instruction: nugetSetupCommandStr, instruction: nugetSetupCommandStr,
trackingAction: TrackingActions.COPY_NUGET_SETUP_COMMAND, trackingAction: TRACKING_ACTION_COPY_NUGET_SETUP_COMMAND,
}); });
}); });
}); });
......
import { shallowMount, createLocalVue } from '@vue/test-utils'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import Vuex from 'vuex'; import { packageData } from 'jest/packages_and_registries/package_registry/mock_data';
import { pypiPackage as packageEntity } from 'jest/packages/mock_data';
import InstallationTitle from '~/packages_and_registries/package_registry/components/details/installation_title.vue'; import InstallationTitle from '~/packages_and_registries/package_registry/components/details/installation_title.vue';
import PypiInstallation from '~/packages_and_registries/package_registry/components/details/pypi_installation.vue'; import PypiInstallation from '~/packages_and_registries/package_registry/components/details/pypi_installation.vue';
import {
PACKAGE_TYPE_PYPI,
TRACKING_ACTION_COPY_PIP_INSTALL_COMMAND,
TRACKING_ACTION_COPY_PYPI_SETUP_COMMAND,
} from '~/packages_and_registries/package_registry/constants';
const localVue = createLocalVue(); const packageEntity = { ...packageData(), packageType: PACKAGE_TYPE_PYPI };
localVue.use(Vuex);
describe('PypiInstallation', () => { describe('PypiInstallation', () => {
let wrapper; let wrapper;
const pipCommandStr = 'pip install'; const pipCommandStr = 'pip install @gitlab-org/package-15 --extra-index-url pypiPath';
const pypiSetupStr = 'python setup'; const pypiSetupStr = `[gitlab]
repository = pypiSetupPath
username = __token__
password = <your personal access token>`;
const store = new Vuex.Store({ const pipCommand = () => wrapper.findByTestId('pip-command');
state: { const setupInstruction = () => wrapper.findByTestId('pypi-setup-content');
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); const findInstallationTitle = () => wrapper.findComponent(InstallationTitle);
function createComponent() { function createComponent() {
wrapper = shallowMount(PypiInstallation, { wrapper = shallowMountExtended(PypiInstallation, {
localVue, provide: {
store, pypiHelpPath: 'pypiHelpPath',
pypiPath: 'pypiPath',
pypiSetupPath: 'pypiSetupPath',
},
propsData: {
packageEntity,
},
}); });
} }
...@@ -60,13 +61,20 @@ describe('PypiInstallation', () => { ...@@ -60,13 +61,20 @@ describe('PypiInstallation', () => {
describe('installation commands', () => { describe('installation commands', () => {
it('renders the correct pip command', () => { it('renders the correct pip command', () => {
expect(pipCommand().props('instruction')).toBe(pipCommandStr); expect(pipCommand().props()).toMatchObject({
instruction: pipCommandStr,
trackingAction: TRACKING_ACTION_COPY_PIP_INSTALL_COMMAND,
});
}); });
}); });
describe('setup commands', () => { describe('setup commands', () => {
it('renders the correct setup block', () => { it('renders the correct setup block', () => {
expect(setupInstruction().props('instruction')).toBe(pypiSetupStr); expect(setupInstruction().props()).toMatchObject({
instruction: pypiSetupStr,
multiline: true,
trackingAction: TRACKING_ACTION_COPY_PYPI_SETUP_COMMAND,
});
}); });
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment