Commit 1f561d70 authored by Natalia Tepluhina's avatar Natalia Tepluhina

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

Refactor installation components to Apollo in package details

See merge request gitlab-org/gitlab!67320
parents 16e58d1c 06be399a
<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_COMPOSER_REGISTRY_INCLUDE_COMMAND,
TRACKING_ACTION_COPY_COMPOSER_PACKAGE_INCLUDE_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 +17,25 @@ export default { ...@@ -14,9 +17,25 @@ export default {
GlLink, GlLink,
GlSprintf, GlSprintf,
}, },
inject: ['composerHelpPath', 'composerConfigRepositoryName', 'composerPath', 'groupListUrl'],
props: {
packageEntity: {
type: Object,
required: true,
},
},
computed: { computed: {
...mapState(['composerHelpPath']), composerRegistryInclude() {
...mapGetters(['composerRegistryInclude', 'composerPackageInclude', 'groupExists']), // eslint-disable-next-line @gitlab/require-i18n-strings
return `composer config repositories.${this.composerConfigRepositoryName} '{"type": "composer", "url": "${this.composerPath}"}'`;
},
composerPackageInclude() {
// eslint-disable-next-line @gitlab/require-i18n-strings
return `composer req ${[this.packageEntity.name]}:${this.packageEntity.version}`;
},
groupExists() {
return this.groupListUrl?.length > 0;
},
}, },
i18n: { i18n: {
registryInclude: s__('PackageRegistry|Add composer registry'), registryInclude: s__('PackageRegistry|Add composer registry'),
...@@ -27,8 +46,11 @@ export default { ...@@ -27,8 +46,11 @@ export default {
'PackageRegistry|For more information on Composer packages in GitLab, %{linkStart}see the documentation.%{linkEnd}', 'PackageRegistry|For more information on Composer packages in GitLab, %{linkStart}see the documentation.%{linkEnd}',
), ),
}, },
trackingActions: { ...TrackingActions }, tracking: {
TrackingLabels, TRACKING_ACTION_COPY_COMPOSER_REGISTRY_INCLUDE_COMMAND,
TRACKING_ACTION_COPY_COMPOSER_PACKAGE_INCLUDE_COMMAND,
TRACKING_LABEL_CODE_INSTRUCTION,
},
installOptions: [{ value: 'composer', label: s__('PackageRegistry|Show Composer commands') }], installOptions: [{ value: 'composer', label: s__('PackageRegistry|Show Composer commands') }],
}; };
</script> </script>
...@@ -41,8 +63,8 @@ export default { ...@@ -41,8 +63,8 @@ export default {
:label="$options.i18n.registryInclude" :label="$options.i18n.registryInclude"
:instruction="composerRegistryInclude" :instruction="composerRegistryInclude"
:copy-text="$options.i18n.copyRegistryInclude" :copy-text="$options.i18n.copyRegistryInclude"
:tracking-action="$options.trackingActions.COPY_COMPOSER_REGISTRY_INCLUDE_COMMAND" :tracking-action="$options.tracking.TRACKING_ACTION_COPY_COMPOSER_REGISTRY_INCLUDE_COMMAND"
:tracking-label="$options.TrackingLabels.CODE_INSTRUCTION" :tracking-label="$options.tracking.TRACKING_LABEL_CODE_INSTRUCTION"
data-testid="registry-include" data-testid="registry-include"
/> />
...@@ -50,8 +72,8 @@ export default { ...@@ -50,8 +72,8 @@ export default {
:label="$options.i18n.packageInclude" :label="$options.i18n.packageInclude"
:instruction="composerPackageInclude" :instruction="composerPackageInclude"
:copy-text="$options.i18n.copyPackageInclude" :copy-text="$options.i18n.copyPackageInclude"
:tracking-action="$options.trackingActions.COPY_COMPOSER_PACKAGE_INCLUDE_COMMAND" :tracking-action="$options.tracking.TRACKING_ACTION_COPY_COMPOSER_PACKAGE_INCLUDE_COMMAND"
:tracking-label="$options.TrackingLabels.CODE_INSTRUCTION" :tracking-label="$options.tracking.TRACKING_LABEL_CODE_INSTRUCTION"
data-testid="package-include" data-testid="package-include"
/> />
<span data-testid="help-text"> <span data-testid="help-text">
......
<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_CONAN_COMMAND,
TRACKING_ACTION_COPY_CONAN_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,34 @@ export default { ...@@ -14,17 +17,34 @@ export default {
GlLink, GlLink,
GlSprintf, GlSprintf,
}, },
inject: ['conanHelpPath', 'conanPath'],
props: {
packageEntity: {
type: Object,
required: true,
},
},
computed: { computed: {
...mapState(['conanHelpPath']), conanInstallationCommand() {
...mapGetters(['conanInstallationCommand', 'conanSetupCommand']), // eslint-disable-next-line @gitlab/require-i18n-strings
return `conan install ${this.packageEntity.name} --remote=gitlab`;
},
conanSetupCommand() {
// eslint-disable-next-line @gitlab/require-i18n-strings
return `conan remote add gitlab ${this.conanPath}`;
},
}, },
i18n: { i18n: {
helpText: s__( helpText: s__(
'PackageRegistry|For more information on the Conan registry, %{linkStart}see the documentation%{linkEnd}.', 'PackageRegistry|For more information on the Conan registry, %{linkStart}see the documentation%{linkEnd}.',
), ),
}, },
trackingActions: { ...TrackingActions }, tracking: {
TrackingLabels, TRACKING_ACTION_COPY_CONAN_COMMAND,
TRACKING_ACTION_COPY_CONAN_SETUP_COMMAND,
TRACKING_LABEL_CODE_INSTRUCTION,
},
installOptions: [{ value: 'conan', label: s__('PackageRegistry|Show Conan commands') }], installOptions: [{ value: 'conan', label: s__('PackageRegistry|Show Conan commands') }],
}; };
</script> </script>
...@@ -37,8 +57,8 @@ export default { ...@@ -37,8 +57,8 @@ export default {
:label="s__('PackageRegistry|Conan Command')" :label="s__('PackageRegistry|Conan Command')"
:instruction="conanInstallationCommand" :instruction="conanInstallationCommand"
:copy-text="s__('PackageRegistry|Copy Conan Command')" :copy-text="s__('PackageRegistry|Copy Conan Command')"
:tracking-action="$options.trackingActions.COPY_CONAN_COMMAND" :tracking-action="$options.tracking.TRACKING_ACTION_COPY_CONAN_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>
...@@ -47,8 +67,8 @@ export default { ...@@ -47,8 +67,8 @@ export default {
:label="s__('PackageRegistry|Add Conan Remote')" :label="s__('PackageRegistry|Add Conan Remote')"
:instruction="conanSetupCommand" :instruction="conanSetupCommand"
:copy-text="s__('PackageRegistry|Copy Conan Setup Command')" :copy-text="s__('PackageRegistry|Copy Conan Setup Command')"
:tracking-action="$options.trackingActions.COPY_CONAN_SETUP_COMMAND" :tracking-action="$options.tracking.TRACKING_ACTION_COPY_CONAN_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 { PackageType, TERRAFORM_PACKAGE_TYPE } from '~/packages/shared/constants'; import {
import TerraformInstallation from '~/packages_and_registries/infrastructure_registry/components/terraform_installation.vue'; PACKAGE_TYPE_CONAN,
PACKAGE_TYPE_MAVEN,
PACKAGE_TYPE_NPM,
PACKAGE_TYPE_NUGET,
PACKAGE_TYPE_PYPI,
PACKAGE_TYPE_COMPOSER,
} from '~/packages_and_registries/package_registry/constants';
import ComposerInstallation from './composer_installation.vue'; import ComposerInstallation from './composer_installation.vue';
import ConanInstallation from './conan_installation.vue'; import ConanInstallation from './conan_installation.vue';
import MavenInstallation from './maven_installation.vue'; import MavenInstallation from './maven_installation.vue';
...@@ -11,33 +17,22 @@ import PypiInstallation from './pypi_installation.vue'; ...@@ -11,33 +17,22 @@ import PypiInstallation from './pypi_installation.vue';
export default { export default {
name: 'InstallationCommands', name: 'InstallationCommands',
components: { components: {
[PackageType.CONAN]: ConanInstallation, [PACKAGE_TYPE_CONAN]: ConanInstallation,
[PackageType.MAVEN]: MavenInstallation, [PACKAGE_TYPE_MAVEN]: MavenInstallation,
[PackageType.NPM]: NpmInstallation, [PACKAGE_TYPE_NPM]: NpmInstallation,
[PackageType.NUGET]: NugetInstallation, [PACKAGE_TYPE_NUGET]: NugetInstallation,
[PackageType.PYPI]: PypiInstallation, [PACKAGE_TYPE_PYPI]: PypiInstallation,
[PackageType.COMPOSER]: ComposerInstallation, [PACKAGE_TYPE_COMPOSER]: ComposerInstallation,
[TERRAFORM_PACKAGE_TYPE]: TerraformInstallation,
}, },
props: { props: {
packageEntity: { packageEntity: {
type: Object, type: Object,
required: true, required: true,
}, },
npmPath: {
type: String,
required: false,
default: '',
},
npmHelpPath: {
type: String,
required: false,
default: '',
},
}, },
computed: { computed: {
installationComponent() { installationComponent() {
return this.$options.components[this.packageEntity.package_type]; return this.$options.components[this.packageEntity.packageType];
}, },
}, },
}; };
...@@ -45,11 +40,6 @@ export default { ...@@ -45,11 +40,6 @@ export default {
<template> <template>
<div v-if="installationComponent"> <div v-if="installationComponent">
<component <component :is="installationComponent" :package-entity="packageEntity" />
:is="installationComponent"
:name="packageEntity.name"
:registry-url="npmPath"
:help-url="npmHelpPath"
/>
</div> </div>
</template> </template>
<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_MAVEN_XML,
TRACKING_ACTION_COPY_MAVEN_COMMAND,
TRACKING_ACTION_COPY_MAVEN_SETUP,
TRACKING_ACTION_COPY_GRADLE_INSTALL_COMMAND,
TRACKING_ACTION_COPY_GRADLE_ADD_TO_SOURCE_COMMAND,
TRACKING_ACTION_COPY_KOTLIN_INSTALL_COMMAND,
TRACKING_ACTION_COPY_KOTLIN_ADD_TO_SOURCE_COMMAND,
TRACKING_LABEL_CODE_INSTRUCTION,
TRACKING_LABEL_MAVEN_INSTALLATION,
} 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,22 +23,80 @@ export default { ...@@ -14,22 +23,80 @@ export default {
GlLink, GlLink,
GlSprintf, GlSprintf,
}, },
inject: ['mavenHelpPath', 'mavenPath'],
props: {
packageEntity: {
type: Object,
required: true,
},
},
data() { data() {
return { return {
instructionType: 'maven', instructionType: 'maven',
}; };
}, },
computed: { computed: {
...mapState(['mavenHelpPath']), appGroup() {
...mapGetters([ return this.packageEntity.metadata.appGroup;
'mavenInstallationXml', },
'mavenInstallationCommand', appName() {
'mavenSetupXml', return this.packageEntity.metadata.appName;
'gradleGroovyInstalCommand', },
'gradleGroovyAddSourceCommand', appVersion() {
'gradleKotlinInstalCommand', return this.packageEntity.metadata.appVersion;
'gradleKotlinAddSourceCommand', },
]), mavenInstallationXml() {
return `<dependency>
<groupId>${this.appGroup}</groupId>
<artifactId>${this.appName}</artifactId>
<version>${this.appVersion}</version>
</dependency>`;
},
mavenInstallationCommand() {
return `mvn dependency:get -Dartifact=${this.appGroup}:${this.appName}:${this.appVersion}`;
},
mavenSetupXml() {
return `<repositories>
<repository>
<id>gitlab-maven</id>
<url>${this.mavenPath}</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>gitlab-maven</id>
<url>${this.mavenPath}</url>
</repository>
<snapshotRepository>
<id>gitlab-maven</id>
<url>${this.mavenPath}</url>
</snapshotRepository>
</distributionManagement>`;
},
gradleGroovyInstalCommand() {
// eslint-disable-next-line @gitlab/require-i18n-strings
return `implementation '${this.appGroup}:${this.appName}:${this.appVersion}'`;
},
gradleGroovyAddSourceCommand() {
// eslint-disable-next-line @gitlab/require-i18n-strings
return `maven {
url '${this.mavenPath}'
}`;
},
gradleKotlinInstalCommand() {
return `implementation("${this.appGroup}:${this.appName}:${this.appVersion}")`;
},
gradleKotlinAddSourceCommand() {
return `maven("${this.mavenPath}")`;
},
showMaven() { showMaven() {
return this.instructionType === 'maven'; return this.instructionType === 'maven';
}, },
...@@ -48,8 +115,18 @@ export default { ...@@ -48,8 +115,18 @@ export default {
'PackageRegistry|For more information on the Maven registry, %{linkStart}see the documentation%{linkEnd}.', 'PackageRegistry|For more information on the Maven registry, %{linkStart}see the documentation%{linkEnd}.',
), ),
}, },
trackingActions: { ...TrackingActions }, tracking: {
TrackingLabels, TRACKING_ACTION_COPY_MAVEN_XML,
TRACKING_ACTION_COPY_MAVEN_COMMAND,
TRACKING_ACTION_COPY_MAVEN_SETUP,
TRACKING_ACTION_COPY_GRADLE_INSTALL_COMMAND,
TRACKING_ACTION_COPY_GRADLE_ADD_TO_SOURCE_COMMAND,
TRACKING_ACTION_COPY_KOTLIN_INSTALL_COMMAND,
TRACKING_ACTION_COPY_KOTLIN_ADD_TO_SOURCE_COMMAND,
TRACKING_LABEL_CODE_INSTRUCTION,
TRACKING_LABEL_MAVEN_INSTALLATION,
},
installOptions: [ installOptions: [
{ value: 'maven', label: s__('PackageRegistry|Maven XML') }, { value: 'maven', label: s__('PackageRegistry|Maven XML') },
{ value: 'groovy', label: s__('PackageRegistry|Gradle Groovy DSL') }, { value: 'groovy', label: s__('PackageRegistry|Gradle Groovy DSL') },
...@@ -78,8 +155,8 @@ export default { ...@@ -78,8 +155,8 @@ export default {
<code-instruction <code-instruction
:instruction="mavenInstallationXml" :instruction="mavenInstallationXml"
:copy-text="s__('PackageRegistry|Copy Maven XML')" :copy-text="s__('PackageRegistry|Copy Maven XML')"
:tracking-action="$options.trackingActions.COPY_MAVEN_XML" :tracking-action="$options.tracking.TRACKING_ACTION_COPY_MAVEN_XML"
:tracking-label="$options.TrackingLabels.CODE_INSTRUCTION" :tracking-label="$options.tracking.TRACKING_LABEL_CODE_INSTRUCTION"
multiline multiline
/> />
...@@ -87,8 +164,8 @@ export default { ...@@ -87,8 +164,8 @@ export default {
:label="s__('PackageRegistry|Maven Command')" :label="s__('PackageRegistry|Maven Command')"
:instruction="mavenInstallationCommand" :instruction="mavenInstallationCommand"
:copy-text="s__('PackageRegistry|Copy Maven command')" :copy-text="s__('PackageRegistry|Copy Maven command')"
:tracking-action="$options.trackingActions.COPY_MAVEN_COMMAND" :tracking-action="$options.tracking.TRACKING_ACTION_COPY_MAVEN_COMMAND"
:tracking-label="$options.TrackingLabels.CODE_INSTRUCTION" :tracking-label="$options.tracking.TRACKING_LABEL_CODE_INSTRUCTION"
/> />
<h3 class="gl-font-lg">{{ s__('PackageRegistry|Registry setup') }}</h3> <h3 class="gl-font-lg">{{ s__('PackageRegistry|Registry setup') }}</h3>
...@@ -102,8 +179,8 @@ export default { ...@@ -102,8 +179,8 @@ export default {
<code-instruction <code-instruction
:instruction="mavenSetupXml" :instruction="mavenSetupXml"
:copy-text="s__('PackageRegistry|Copy Maven registry XML')" :copy-text="s__('PackageRegistry|Copy Maven registry XML')"
:tracking-action="$options.trackingActions.COPY_MAVEN_SETUP" :tracking-action="$options.tracking.TRACKING_ACTION_COPY_MAVEN_SETUP"
:tracking-label="$options.TrackingLabels.CODE_INSTRUCTION" :tracking-label="$options.tracking.TRACKING_LABEL_CODE_INSTRUCTION"
multiline multiline
/> />
<gl-sprintf :message="$options.i18n.helpText"> <gl-sprintf :message="$options.i18n.helpText">
...@@ -118,15 +195,15 @@ export default { ...@@ -118,15 +195,15 @@ export default {
:label="s__('PackageRegistry|Gradle Groovy DSL install command')" :label="s__('PackageRegistry|Gradle Groovy DSL install command')"
:instruction="gradleGroovyInstalCommand" :instruction="gradleGroovyInstalCommand"
:copy-text="s__('PackageRegistry|Copy Gradle Groovy DSL install command')" :copy-text="s__('PackageRegistry|Copy Gradle Groovy DSL install command')"
:tracking-action="$options.trackingActions.COPY_GRADLE_INSTALL_COMMAND" :tracking-action="$options.tracking.TRACKING_ACTION_COPY_GRADLE_INSTALL_COMMAND"
:tracking-label="$options.TrackingLabels.CODE_INSTRUCTION" :tracking-label="$options.tracking.TRACKING_LABEL_CODE_INSTRUCTION"
/> />
<code-instruction <code-instruction
:label="s__('PackageRegistry|Add Gradle Groovy DSL repository command')" :label="s__('PackageRegistry|Add Gradle Groovy DSL repository command')"
:instruction="gradleGroovyAddSourceCommand" :instruction="gradleGroovyAddSourceCommand"
:copy-text="s__('PackageRegistry|Copy add Gradle Groovy DSL repository command')" :copy-text="s__('PackageRegistry|Copy add Gradle Groovy DSL repository command')"
:tracking-action="$options.trackingActions.COPY_GRADLE_ADD_TO_SOURCE_COMMAND" :tracking-action="$options.tracking.TRACKING_ACTION_COPY_GRADLE_ADD_TO_SOURCE_COMMAND"
:tracking-label="$options.TrackingLabels.CODE_INSTRUCTION" :tracking-label="$options.tracking.TRACKING_LABEL_CODE_INSTRUCTION"
multiline multiline
/> />
</template> </template>
...@@ -136,15 +213,15 @@ export default { ...@@ -136,15 +213,15 @@ export default {
:label="s__('PackageRegistry|Gradle Kotlin DSL install command')" :label="s__('PackageRegistry|Gradle Kotlin DSL install command')"
:instruction="gradleKotlinInstalCommand" :instruction="gradleKotlinInstalCommand"
:copy-text="s__('PackageRegistry|Copy Gradle Kotlin DSL install command')" :copy-text="s__('PackageRegistry|Copy Gradle Kotlin DSL install command')"
:tracking-action="$options.trackingActions.COPY_KOTLIN_INSTALL_COMMAND" :tracking-action="$options.tracking.TRACKING_ACTION_COPY_KOTLIN_INSTALL_COMMAND"
:tracking-label="$options.TrackingLabels.CODE_INSTRUCTION" :tracking-label="$options.tracking.TRACKING_LABEL_CODE_INSTRUCTION"
/> />
<code-instruction <code-instruction
:label="s__('PackageRegistry|Add Gradle Kotlin DSL repository command')" :label="s__('PackageRegistry|Add Gradle Kotlin DSL repository command')"
:instruction="gradleKotlinAddSourceCommand" :instruction="gradleKotlinAddSourceCommand"
:copy-text="s__('PackageRegistry|Copy add Gradle Kotlin DSL repository command')" :copy-text="s__('PackageRegistry|Copy add Gradle Kotlin DSL repository command')"
:tracking-action="$options.trackingActions.COPY_KOTLIN_ADD_TO_SOURCE_COMMAND" :tracking-action="$options.tracking.TRACKING_ACTION_COPY_KOTLIN_ADD_TO_SOURCE_COMMAND"
:tracking-label="$options.TrackingLabels.CODE_INSTRUCTION" :tracking-label="$options.tracking.TRACKING_LABEL_CODE_INSTRUCTION"
multiline multiline
/> />
</template> </template>
......
...@@ -10,7 +10,6 @@ export const PACKAGE_TYPE_RUBYGEMS = 'RUBYGEMS'; ...@@ -10,7 +10,6 @@ export const PACKAGE_TYPE_RUBYGEMS = 'RUBYGEMS';
export const PACKAGE_TYPE_GENERIC = 'GENERIC'; export const PACKAGE_TYPE_GENERIC = 'GENERIC';
export const PACKAGE_TYPE_DEBIAN = 'DEBIAN'; export const PACKAGE_TYPE_DEBIAN = 'DEBIAN';
export const PACKAGE_TYPE_HELM = 'HELM'; export const PACKAGE_TYPE_HELM = 'HELM';
export const PACKAGE_TYPE_TERRAFORM = 'terraform_module';
export const DELETE_PACKAGE_TRACKING_ACTION = 'delete_package'; export const DELETE_PACKAGE_TRACKING_ACTION = 'delete_package';
export const REQUEST_DELETE_PACKAGE_TRACKING_ACTION = 'request_delete_package'; export const REQUEST_DELETE_PACKAGE_TRACKING_ACTION = 'request_delete_package';
...@@ -20,6 +19,46 @@ export const DELETE_PACKAGE_FILE_TRACKING_ACTION = 'delete_package_file'; ...@@ -20,6 +19,46 @@ export const DELETE_PACKAGE_FILE_TRACKING_ACTION = 'delete_package_file';
export const REQUEST_DELETE_PACKAGE_FILE_TRACKING_ACTION = 'request_delete_package_file'; export const REQUEST_DELETE_PACKAGE_FILE_TRACKING_ACTION = 'request_delete_package_file';
export const CANCEL_DELETE_PACKAGE_FILE_TRACKING_ACTION = 'cancel_delete_package_file'; export const CANCEL_DELETE_PACKAGE_FILE_TRACKING_ACTION = 'cancel_delete_package_file';
export const TRACKING_LABEL_CODE_INSTRUCTION = 'code_instruction';
export const TRACKING_LABEL_CONAN_INSTALLATION = 'conan_installation';
export const TRACKING_LABEL_MAVEN_INSTALLATION = 'maven_installation';
export const TRACKING_LABEL_NPM_INSTALLATION = 'npm_installation';
export const TRACKING_LABEL_NUGET_INSTALLATION = 'nuget_installation';
export const TRACKING_LABEL_PYPI_INSTALLATION = 'pypi_installation';
export const TRACKING_LABEL_COMPOSER_INSTALLATION = 'composer_installation';
export const TRACKING_ACTION_INSTALLATION = 'installation';
export const TRACKING_ACTION_REGISTRY_SETUP = 'registry_setup';
export const TRACKING_ACTION_COPY_CONAN_COMMAND = 'copy_conan_command';
export const TRACKING_ACTION_COPY_CONAN_SETUP_COMMAND = 'copy_conan_setup_command';
export const TRACKING_ACTION_COPY_MAVEN_XML = 'copy_maven_xml';
export const TRACKING_ACTION_COPY_MAVEN_COMMAND = 'copy_maven_command';
export const TRACKING_ACTION_COPY_MAVEN_SETUP = 'copy_maven_setup_xml';
export const TRACKING_ACTION_COPY_GRADLE_INSTALL_COMMAND = 'copy_gradle_install_command';
export const TRACKING_ACTION_COPY_GRADLE_ADD_TO_SOURCE_COMMAND =
'copy_gradle_add_to_source_command';
export const TRACKING_ACTION_COPY_KOTLIN_INSTALL_COMMAND = 'copy_kotlin_install_command';
export const TRACKING_ACTION_COPY_KOTLIN_ADD_TO_SOURCE_COMMAND =
'copy_kotlin_add_to_source_command';
export const TRACKING_ACTION_COPY_NPM_INSTALL_COMMAND = 'copy_npm_install_command';
export const TRACKING_ACTION_COPY_NPM_SETUP_COMMAND = 'copy_npm_setup_command';
export const TRACKING_ACTION_COPY_YARN_INSTALL_COMMAND = 'copy_yarn_install_command';
export const TRACKING_ACTION_COPY_YARN_SETUP_COMMAND = 'copy_yarn_setup_command';
export const TRACKING_ACTION_COPY_NUGET_INSTALL_COMMAND = 'copy_nuget_install_command';
export const TRACKING_ACTION_COPY_NUGET_SETUP_COMMAND = 'copy_nuget_setup_command';
export const TRACKING_ACTION_COPY_PIP_INSTALL_COMMAND = 'copy_pip_install_command';
export const TRACKING_ACTION_COPY_PYPI_SETUP_COMMAND = 'copy_pypi_setup_command';
export const TRACKING_ACTION_COPY_COMPOSER_REGISTRY_INCLUDE_COMMAND =
'copy_composer_registry_include_command';
export const TRACKING_ACTION_COPY_COMPOSER_PACKAGE_INCLUDE_COMMAND =
'copy_composer_package_include_command';
export const TrackingCategories = { export const TrackingCategories = {
[PACKAGE_TYPE_MAVEN]: 'MavenPackages', [PACKAGE_TYPE_MAVEN]: 'MavenPackages',
[PACKAGE_TYPE_NPM]: 'NpmPackages', [PACKAGE_TYPE_NPM]: 'NpmPackages',
......
...@@ -9,7 +9,7 @@ exports[`ConanInstallation renders all the messages 1`] = ` ...@@ -9,7 +9,7 @@ exports[`ConanInstallation renders all the messages 1`] = `
<code-instruction-stub <code-instruction-stub
copytext="Copy Conan Command" copytext="Copy Conan Command"
instruction="foo/command" instruction="conan install @gitlab-org/package-15 --remote=gitlab"
label="Conan Command" label="Conan Command"
trackingaction="copy_conan_command" trackingaction="copy_conan_command"
trackinglabel="code_instruction" trackinglabel="code_instruction"
...@@ -23,7 +23,7 @@ exports[`ConanInstallation renders all the messages 1`] = ` ...@@ -23,7 +23,7 @@ exports[`ConanInstallation renders all the messages 1`] = `
<code-instruction-stub <code-instruction-stub
copytext="Copy Conan Setup Command" copytext="Copy Conan Setup Command"
instruction="foo/setup" instruction="conan remote add gitlab conanPath"
label="Add Conan Remote" label="Add Conan Remote"
trackingaction="copy_conan_setup_command" trackingaction="copy_conan_setup_command"
trackinglabel="code_instruction" trackinglabel="code_instruction"
......
...@@ -10,7 +10,7 @@ exports[`MavenInstallation groovy renders all the messages 1`] = ` ...@@ -10,7 +10,7 @@ exports[`MavenInstallation groovy renders all the messages 1`] = `
<code-instruction-stub <code-instruction-stub
class="gl-mb-5" class="gl-mb-5"
copytext="Copy Gradle Groovy DSL install command" copytext="Copy Gradle Groovy DSL install command"
instruction="foo/gradle/groovy/install" instruction="implementation 'appGroup:appName:appVersion'"
label="Gradle Groovy DSL install command" label="Gradle Groovy DSL install command"
trackingaction="copy_gradle_install_command" trackingaction="copy_gradle_install_command"
trackinglabel="code_instruction" trackinglabel="code_instruction"
...@@ -18,7 +18,9 @@ exports[`MavenInstallation groovy renders all the messages 1`] = ` ...@@ -18,7 +18,9 @@ exports[`MavenInstallation groovy renders all the messages 1`] = `
<code-instruction-stub <code-instruction-stub
copytext="Copy add Gradle Groovy DSL repository command" copytext="Copy add Gradle Groovy DSL repository command"
instruction="foo/gradle/groovy/add/source" instruction="maven {
url 'mavenPath'
}"
label="Add Gradle Groovy DSL repository command" label="Add Gradle Groovy DSL repository command"
multiline="true" multiline="true"
trackingaction="copy_gradle_add_to_source_command" trackingaction="copy_gradle_add_to_source_command"
...@@ -37,7 +39,7 @@ exports[`MavenInstallation kotlin renders all the messages 1`] = ` ...@@ -37,7 +39,7 @@ exports[`MavenInstallation kotlin renders all the messages 1`] = `
<code-instruction-stub <code-instruction-stub
class="gl-mb-5" class="gl-mb-5"
copytext="Copy Gradle Kotlin DSL install command" copytext="Copy Gradle Kotlin DSL install command"
instruction="foo/gradle/kotlin/install" instruction="implementation(\\"appGroup:appName:appVersion\\")"
label="Gradle Kotlin DSL install command" label="Gradle Kotlin DSL install command"
trackingaction="copy_kotlin_install_command" trackingaction="copy_kotlin_install_command"
trackinglabel="code_instruction" trackinglabel="code_instruction"
...@@ -45,7 +47,7 @@ exports[`MavenInstallation kotlin renders all the messages 1`] = ` ...@@ -45,7 +47,7 @@ exports[`MavenInstallation kotlin renders all the messages 1`] = `
<code-instruction-stub <code-instruction-stub
copytext="Copy add Gradle Kotlin DSL repository command" copytext="Copy add Gradle Kotlin DSL repository command"
instruction="foo/gradle/kotlin/add/source" instruction="maven(\\"mavenPath\\")"
label="Add Gradle Kotlin DSL repository command" label="Add Gradle Kotlin DSL repository command"
multiline="true" multiline="true"
trackingaction="copy_kotlin_add_to_source_command" trackingaction="copy_kotlin_add_to_source_command"
...@@ -69,7 +71,11 @@ exports[`MavenInstallation maven renders all the messages 1`] = ` ...@@ -69,7 +71,11 @@ exports[`MavenInstallation maven renders all the messages 1`] = `
<code-instruction-stub <code-instruction-stub
copytext="Copy Maven XML" copytext="Copy Maven XML"
instruction="foo/xml" instruction="<dependency>
<groupId>appGroup</groupId>
<artifactId>appName</artifactId>
<version>appVersion</version>
</dependency>"
label="" label=""
multiline="true" multiline="true"
trackingaction="copy_maven_xml" trackingaction="copy_maven_xml"
...@@ -78,7 +84,7 @@ exports[`MavenInstallation maven renders all the messages 1`] = ` ...@@ -78,7 +84,7 @@ exports[`MavenInstallation maven renders all the messages 1`] = `
<code-instruction-stub <code-instruction-stub
copytext="Copy Maven command" copytext="Copy Maven command"
instruction="foo/command" instruction="mvn dependency:get -Dartifact=appGroup:appName:appVersion"
label="Maven Command" label="Maven Command"
trackingaction="copy_maven_command" trackingaction="copy_maven_command"
trackinglabel="code_instruction" trackinglabel="code_instruction"
...@@ -98,7 +104,24 @@ exports[`MavenInstallation maven renders all the messages 1`] = ` ...@@ -98,7 +104,24 @@ exports[`MavenInstallation maven renders all the messages 1`] = `
<code-instruction-stub <code-instruction-stub
copytext="Copy Maven registry XML" copytext="Copy Maven registry XML"
instruction="foo/setup" instruction="<repositories>
<repository>
<id>gitlab-maven</id>
<url>mavenPath</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>gitlab-maven</id>
<url>mavenPath</url>
</repository>
<snapshotRepository>
<id>gitlab-maven</id>
<url>mavenPath</url>
</snapshotRepository>
</distributionManagement>"
label="" label=""
multiline="true" multiline="true"
trackingaction="copy_maven_setup_xml" trackingaction="copy_maven_setup_xml"
......
import { GlSprintf, GlLink } from '@gitlab/ui'; import { GlSprintf, GlLink } from '@gitlab/ui';
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 composerHelpPath } from 'jest/packages/details/mock_data';
import { composerPackage as packageEntity } from 'jest/packages/mock_data';
import { TrackingActions } from '~/packages/details/constants';
import ComposerInstallation from '~/packages_and_registries/package_registry/components/details/composer_installation.vue'; import ComposerInstallation from '~/packages_and_registries/package_registry/components/details/composer_installation.vue';
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_COMPOSER_REGISTRY_INCLUDE_COMMAND,
TRACKING_ACTION_COPY_COMPOSER_PACKAGE_INCLUDE_COMMAND,
PACKAGE_TYPE_COMPOSER,
} from '~/packages_and_registries/package_registry/constants';
const localVue = createLocalVue(); const packageEntity = { ...packageData(), packageType: PACKAGE_TYPE_COMPOSER };
localVue.use(Vuex);
describe('ComposerInstallation', () => { describe('ComposerInstallation', () => {
let wrapper; let wrapper;
let store;
const composerRegistryIncludeStr = 'foo/registry';
const composerPackageIncludeStr = 'foo/package';
const createStore = (groupExists = true) => {
store = new Vuex.Store({
state: { packageEntity, composerHelpPath },
getters: {
composerRegistryInclude: () => composerRegistryIncludeStr,
composerPackageInclude: () => composerPackageIncludeStr,
groupExists: () => groupExists,
},
});
};
const findRootNode = () => wrapper.find('[data-testid="root-node"]'); const findRootNode = () => wrapper.findByTestId('root-node');
const findRegistryInclude = () => wrapper.find('[data-testid="registry-include"]'); const findRegistryInclude = () => wrapper.findByTestId('registry-include');
const findPackageInclude = () => wrapper.find('[data-testid="package-include"]'); const findPackageInclude = () => wrapper.findByTestId('package-include');
const findHelpText = () => wrapper.find('[data-testid="help-text"]'); const findHelpText = () => wrapper.findByTestId('help-text');
const findHelpLink = () => wrapper.find(GlLink); const findHelpLink = () => wrapper.findComponent(GlLink);
const findInstallationTitle = () => wrapper.findComponent(InstallationTitle); const findInstallationTitle = () => wrapper.findComponent(InstallationTitle);
function createComponent() { function createComponent(groupListUrl = 'groupListUrl') {
wrapper = shallowMount(ComposerInstallation, { wrapper = shallowMountExtended(ComposerInstallation, {
localVue, provide: {
store, composerHelpPath: 'composerHelpPath',
composerConfigRepositoryName: 'composerConfigRepositoryName',
composerPath: 'composerPath',
groupListUrl,
},
propsData: { packageEntity },
stubs: { stubs: {
GlSprintf, GlSprintf,
}, },
...@@ -51,7 +42,6 @@ describe('ComposerInstallation', () => { ...@@ -51,7 +42,6 @@ describe('ComposerInstallation', () => {
describe('install command switch', () => { describe('install command switch', () => {
it('has the installation title component', () => { it('has the installation title component', () => {
createStore();
createComponent(); createComponent();
expect(findInstallationTitle().exists()).toBe(true); expect(findInstallationTitle().exists()).toBe(true);
...@@ -64,7 +54,6 @@ describe('ComposerInstallation', () => { ...@@ -64,7 +54,6 @@ describe('ComposerInstallation', () => {
describe('registry include command', () => { describe('registry include command', () => {
beforeEach(() => { beforeEach(() => {
createStore();
createComponent(); createComponent();
}); });
...@@ -72,9 +61,9 @@ describe('ComposerInstallation', () => { ...@@ -72,9 +61,9 @@ describe('ComposerInstallation', () => {
const registryIncludeCommand = findRegistryInclude(); const registryIncludeCommand = findRegistryInclude();
expect(registryIncludeCommand.exists()).toBe(true); expect(registryIncludeCommand.exists()).toBe(true);
expect(registryIncludeCommand.props()).toMatchObject({ expect(registryIncludeCommand.props()).toMatchObject({
instruction: composerRegistryIncludeStr, instruction: `composer config repositories.composerConfigRepositoryName '{"type": "composer", "url": "composerPath"}'`,
copyText: 'Copy registry include', copyText: 'Copy registry include',
trackingAction: TrackingActions.COPY_COMPOSER_REGISTRY_INCLUDE_COMMAND, trackingAction: TRACKING_ACTION_COPY_COMPOSER_REGISTRY_INCLUDE_COMMAND,
}); });
}); });
...@@ -85,7 +74,6 @@ describe('ComposerInstallation', () => { ...@@ -85,7 +74,6 @@ describe('ComposerInstallation', () => {
describe('package include command', () => { describe('package include command', () => {
beforeEach(() => { beforeEach(() => {
createStore();
createComponent(); createComponent();
}); });
...@@ -93,9 +81,9 @@ describe('ComposerInstallation', () => { ...@@ -93,9 +81,9 @@ describe('ComposerInstallation', () => {
const registryIncludeCommand = findPackageInclude(); const registryIncludeCommand = findPackageInclude();
expect(registryIncludeCommand.exists()).toBe(true); expect(registryIncludeCommand.exists()).toBe(true);
expect(registryIncludeCommand.props()).toMatchObject({ expect(registryIncludeCommand.props()).toMatchObject({
instruction: composerPackageIncludeStr, instruction: 'composer req @gitlab-org/package-15:1.0.0',
copyText: 'Copy require package include', copyText: 'Copy require package include',
trackingAction: TrackingActions.COPY_COMPOSER_PACKAGE_INCLUDE_COMMAND, trackingAction: TRACKING_ACTION_COPY_COMPOSER_PACKAGE_INCLUDE_COMMAND,
}); });
}); });
...@@ -108,7 +96,7 @@ describe('ComposerInstallation', () => { ...@@ -108,7 +96,7 @@ describe('ComposerInstallation', () => {
'For more information on Composer packages in GitLab, see the documentation.', 'For more information on Composer packages in GitLab, see the documentation.',
); );
expect(findHelpLink().attributes()).toMatchObject({ expect(findHelpLink().attributes()).toMatchObject({
href: composerHelpPath, href: 'composerHelpPath',
target: '_blank', target: '_blank',
}); });
}); });
...@@ -116,15 +104,13 @@ describe('ComposerInstallation', () => { ...@@ -116,15 +104,13 @@ describe('ComposerInstallation', () => {
describe('root node', () => { describe('root node', () => {
it('is normally rendered', () => { it('is normally rendered', () => {
createStore();
createComponent(); createComponent();
expect(findRootNode().exists()).toBe(true); expect(findRootNode().exists()).toBe(true);
}); });
it('is not rendered when the group does not exist', () => { it('is not rendered when the group does not exist', () => {
createStore(false); createComponent('');
createComponent();
expect(findRootNode().exists()).toBe(false); expect(findRootNode().exists()).toBe(false);
}); });
......
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 conanPath } from 'jest/packages/details/mock_data';
import { conanPackage as packageEntity } from 'jest/packages/mock_data';
import ConanInstallation from '~/packages_and_registries/package_registry/components/details/conan_installation.vue'; import ConanInstallation from '~/packages_and_registries/package_registry/components/details/conan_installation.vue';
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 { PACKAGE_TYPE_CONAN } 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_CONAN };
localVue.use(Vuex);
describe('ConanInstallation', () => { describe('ConanInstallation', () => {
let wrapper; let wrapper;
const conanInstallationCommandStr = 'foo/command'; const findCodeInstructions = () => wrapper.findAllComponents(CodeInstructions);
const conanSetupCommandStr = 'foo/setup';
const store = new Vuex.Store({
state: {
packageEntity,
conanPath,
},
getters: {
conanInstallationCommand: () => conanInstallationCommandStr,
conanSetupCommand: () => conanSetupCommandStr,
},
});
const findCodeInstructions = () => wrapper.findAll(CodeInstructions);
const findInstallationTitle = () => wrapper.findComponent(InstallationTitle); const findInstallationTitle = () => wrapper.findComponent(InstallationTitle);
function createComponent() { function createComponent() {
wrapper = shallowMount(ConanInstallation, { wrapper = shallowMountExtended(ConanInstallation, {
localVue, provide: {
store, conanHelpPath: 'conanHelpPath',
conanPath: 'conanPath',
},
propsData: {
packageEntity,
},
}); });
} }
...@@ -60,13 +49,17 @@ describe('ConanInstallation', () => { ...@@ -60,13 +49,17 @@ describe('ConanInstallation', () => {
describe('installation commands', () => { describe('installation commands', () => {
it('renders the correct command', () => { it('renders the correct command', () => {
expect(findCodeInstructions().at(0).props('instruction')).toBe(conanInstallationCommandStr); expect(findCodeInstructions().at(0).props('instruction')).toBe(
'conan install @gitlab-org/package-15 --remote=gitlab',
);
}); });
}); });
describe('setup commands', () => { describe('setup commands', () => {
it('renders the correct command', () => { it('renders the correct command', () => {
expect(findCodeInstructions().at(1).props('instruction')).toBe(conanSetupCommandStr); expect(findCodeInstructions().at(1).props('instruction')).toBe(
'conan remote add gitlab conanPath',
);
}); });
}); });
}); });
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { import { packageData } from 'jest/packages_and_registries/package_registry/mock_data';
conanPackage,
mavenPackage,
npmPackage,
nugetPackage,
pypiPackage,
composerPackage,
terraformModule,
} from 'jest/packages/mock_data';
import TerraformInstallation from '~/packages_and_registries/infrastructure_registry/components/terraform_installation.vue';
import ComposerInstallation from '~/packages_and_registries/package_registry/components/details/composer_installation.vue'; import ComposerInstallation from '~/packages_and_registries/package_registry/components/details/composer_installation.vue';
import ConanInstallation from '~/packages_and_registries/package_registry/components/details/conan_installation.vue'; import ConanInstallation from '~/packages_and_registries/package_registry/components/details/conan_installation.vue';
import InstallationCommands from '~/packages_and_registries/package_registry/components/details/installation_commands.vue'; import InstallationCommands from '~/packages_and_registries/package_registry/components/details/installation_commands.vue';
...@@ -17,6 +8,21 @@ import MavenInstallation from '~/packages_and_registries/package_registry/compon ...@@ -17,6 +8,21 @@ import MavenInstallation from '~/packages_and_registries/package_registry/compon
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 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 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_CONAN,
PACKAGE_TYPE_MAVEN,
PACKAGE_TYPE_NPM,
PACKAGE_TYPE_NUGET,
PACKAGE_TYPE_PYPI,
PACKAGE_TYPE_COMPOSER,
} from '~/packages_and_registries/package_registry/constants';
const conanPackage = { ...packageData(), packageType: PACKAGE_TYPE_CONAN };
const mavenPackage = { ...packageData(), packageType: PACKAGE_TYPE_MAVEN };
const npmPackage = { ...packageData(), packageType: PACKAGE_TYPE_NPM };
const nugetPackage = { ...packageData(), packageType: PACKAGE_TYPE_NUGET };
const pypiPackage = { ...packageData(), packageType: PACKAGE_TYPE_PYPI };
const composerPackage = { ...packageData(), packageType: PACKAGE_TYPE_COMPOSER };
describe('InstallationCommands', () => { describe('InstallationCommands', () => {
let wrapper; let wrapper;
...@@ -33,7 +39,6 @@ describe('InstallationCommands', () => { ...@@ -33,7 +39,6 @@ describe('InstallationCommands', () => {
const nugetInstallation = () => wrapper.find(NugetInstallation); const nugetInstallation = () => wrapper.find(NugetInstallation);
const pypiInstallation = () => wrapper.find(PypiInstallation); const pypiInstallation = () => wrapper.find(PypiInstallation);
const composerInstallation = () => wrapper.find(ComposerInstallation); const composerInstallation = () => wrapper.find(ComposerInstallation);
const terraformInstallation = () => wrapper.findComponent(TerraformInstallation);
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
...@@ -48,9 +53,8 @@ describe('InstallationCommands', () => { ...@@ -48,9 +53,8 @@ describe('InstallationCommands', () => {
${nugetPackage} | ${nugetInstallation} ${nugetPackage} | ${nugetInstallation}
${pypiPackage} | ${pypiInstallation} ${pypiPackage} | ${pypiInstallation}
${composerPackage} | ${composerInstallation} ${composerPackage} | ${composerInstallation}
${terraformModule} | ${terraformInstallation}
`('renders', ({ packageEntity, selector }) => { `('renders', ({ packageEntity, selector }) => {
it(`${packageEntity.package_type} instructions exist`, () => { it(`${packageEntity.packageType} instructions exist`, () => {
createComponent({ packageEntity }); createComponent({ packageEntity });
expect(selector()).toExist(); expect(selector()).toExist();
......
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 mavenPath } from 'jest/packages/details/mock_data';
import { mavenPackage as packageEntity } from 'jest/packages/mock_data'; import {
import { TrackingActions } from '~/packages/details/constants'; packageData,
mavenMetadata,
} from 'jest/packages_and_registries/package_registry/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 MavenInstallation from '~/packages_and_registries/package_registry/components/details/maven_installation.vue'; import MavenInstallation from '~/packages_and_registries/package_registry/components/details/maven_installation.vue';
import {
TRACKING_ACTION_COPY_MAVEN_XML,
TRACKING_ACTION_COPY_MAVEN_COMMAND,
TRACKING_ACTION_COPY_MAVEN_SETUP,
TRACKING_ACTION_COPY_GRADLE_INSTALL_COMMAND,
TRACKING_ACTION_COPY_GRADLE_ADD_TO_SOURCE_COMMAND,
TRACKING_ACTION_COPY_KOTLIN_INSTALL_COMMAND,
TRACKING_ACTION_COPY_KOTLIN_ADD_TO_SOURCE_COMMAND,
PACKAGE_TYPE_MAVEN,
} 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();
localVue.use(Vuex);
describe('MavenInstallation', () => { describe('MavenInstallation', () => {
let wrapper; let wrapper;
const xmlCodeBlock = 'foo/xml'; const packageEntity = {
const mavenCommandStr = 'foo/command'; ...packageData(),
const mavenSetupXml = 'foo/setup'; packageType: PACKAGE_TYPE_MAVEN,
const gradleGroovyInstallCommandText = 'foo/gradle/groovy/install'; metadata: mavenMetadata(),
const gradleGroovyAddSourceCommandText = 'foo/gradle/groovy/add/source'; };
const gradleKotlinInstallCommandText = 'foo/gradle/kotlin/install';
const gradleKotlinAddSourceCommandText = 'foo/gradle/kotlin/add/source'; const mavenHelpPath = 'mavenHelpPath';
const mavenPath = 'mavenPath';
const xmlCodeBlock = `<dependency>
<groupId>appGroup</groupId>
<artifactId>appName</artifactId>
<version>appVersion</version>
</dependency>`;
const mavenCommandStr = 'mvn dependency:get -Dartifact=appGroup:appName:appVersion';
const mavenSetupXml = `<repositories>
<repository>
<id>gitlab-maven</id>
<url>${mavenPath}</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>gitlab-maven</id>
<url>${mavenPath}</url>
</repository>
<snapshotRepository>
<id>gitlab-maven</id>
<url>${mavenPath}</url>
</snapshotRepository>
</distributionManagement>`;
const gradleGroovyInstallCommandText = `implementation 'appGroup:appName:appVersion'`;
const gradleGroovyAddSourceCommandText = `maven {
url '${mavenPath}'
}`;
const gradleKotlinInstallCommandText = `implementation("appGroup:appName:appVersion")`;
const gradleKotlinAddSourceCommandText = `maven("${mavenPath}")`;
const findCodeInstructions = () => wrapper.findAllComponents(CodeInstructions);
const findInstallationTitle = () => wrapper.findComponent(InstallationTitle);
const store = new Vuex.Store({ function createComponent({ data = {} } = {}) {
state: { wrapper = shallowMountExtended(MavenInstallation, {
packageEntity, provide: {
mavenHelpPath,
mavenPath, mavenPath,
}, },
getters: { propsData: {
mavenInstallationXml: () => xmlCodeBlock, packageEntity,
mavenInstallationCommand: () => mavenCommandStr,
mavenSetupXml: () => mavenSetupXml,
gradleGroovyInstalCommand: () => gradleGroovyInstallCommandText,
gradleGroovyAddSourceCommand: () => gradleGroovyAddSourceCommandText,
gradleKotlinInstalCommand: () => gradleKotlinInstallCommandText,
gradleKotlinAddSourceCommand: () => gradleKotlinAddSourceCommandText,
}, },
});
const findCodeInstructions = () => wrapper.findAll(CodeInstructions);
const findInstallationTitle = () => wrapper.findComponent(InstallationTitle);
function createComponent({ data = {} } = {}) {
wrapper = shallowMount(MavenInstallation, {
localVue,
store,
data() { data() {
return data; return data;
}, },
...@@ -98,7 +127,7 @@ describe('MavenInstallation', () => { ...@@ -98,7 +127,7 @@ describe('MavenInstallation', () => {
expect(findCodeInstructions().at(0).props()).toMatchObject({ expect(findCodeInstructions().at(0).props()).toMatchObject({
instruction: xmlCodeBlock, instruction: xmlCodeBlock,
multiline: true, multiline: true,
trackingAction: TrackingActions.COPY_MAVEN_XML, trackingAction: TRACKING_ACTION_COPY_MAVEN_XML,
}); });
}); });
...@@ -106,7 +135,7 @@ describe('MavenInstallation', () => { ...@@ -106,7 +135,7 @@ describe('MavenInstallation', () => {
expect(findCodeInstructions().at(1).props()).toMatchObject({ expect(findCodeInstructions().at(1).props()).toMatchObject({
instruction: mavenCommandStr, instruction: mavenCommandStr,
multiline: false, multiline: false,
trackingAction: TrackingActions.COPY_MAVEN_COMMAND, trackingAction: TRACKING_ACTION_COPY_MAVEN_COMMAND,
}); });
}); });
}); });
...@@ -116,7 +145,7 @@ describe('MavenInstallation', () => { ...@@ -116,7 +145,7 @@ describe('MavenInstallation', () => {
expect(findCodeInstructions().at(2).props()).toMatchObject({ expect(findCodeInstructions().at(2).props()).toMatchObject({
instruction: mavenSetupXml, instruction: mavenSetupXml,
multiline: true, multiline: true,
trackingAction: TrackingActions.COPY_MAVEN_SETUP, trackingAction: TRACKING_ACTION_COPY_MAVEN_SETUP,
}); });
}); });
}); });
...@@ -136,7 +165,7 @@ describe('MavenInstallation', () => { ...@@ -136,7 +165,7 @@ describe('MavenInstallation', () => {
expect(findCodeInstructions().at(0).props()).toMatchObject({ expect(findCodeInstructions().at(0).props()).toMatchObject({
instruction: gradleGroovyInstallCommandText, instruction: gradleGroovyInstallCommandText,
multiline: false, multiline: false,
trackingAction: TrackingActions.COPY_GRADLE_INSTALL_COMMAND, trackingAction: TRACKING_ACTION_COPY_GRADLE_INSTALL_COMMAND,
}); });
}); });
}); });
...@@ -146,7 +175,7 @@ describe('MavenInstallation', () => { ...@@ -146,7 +175,7 @@ describe('MavenInstallation', () => {
expect(findCodeInstructions().at(1).props()).toMatchObject({ expect(findCodeInstructions().at(1).props()).toMatchObject({
instruction: gradleGroovyAddSourceCommandText, instruction: gradleGroovyAddSourceCommandText,
multiline: true, multiline: true,
trackingAction: TrackingActions.COPY_GRADLE_ADD_TO_SOURCE_COMMAND, trackingAction: TRACKING_ACTION_COPY_GRADLE_ADD_TO_SOURCE_COMMAND,
}); });
}); });
}); });
...@@ -166,7 +195,7 @@ describe('MavenInstallation', () => { ...@@ -166,7 +195,7 @@ describe('MavenInstallation', () => {
expect(findCodeInstructions().at(0).props()).toMatchObject({ expect(findCodeInstructions().at(0).props()).toMatchObject({
instruction: gradleKotlinInstallCommandText, instruction: gradleKotlinInstallCommandText,
multiline: false, multiline: false,
trackingAction: TrackingActions.COPY_KOTLIN_INSTALL_COMMAND, trackingAction: TRACKING_ACTION_COPY_KOTLIN_INSTALL_COMMAND,
}); });
}); });
}); });
...@@ -176,7 +205,7 @@ describe('MavenInstallation', () => { ...@@ -176,7 +205,7 @@ describe('MavenInstallation', () => {
expect(findCodeInstructions().at(1).props()).toMatchObject({ expect(findCodeInstructions().at(1).props()).toMatchObject({
instruction: gradleKotlinAddSourceCommandText, instruction: gradleKotlinAddSourceCommandText,
multiline: true, multiline: true,
trackingAction: TrackingActions.COPY_KOTLIN_ADD_TO_SOURCE_COMMAND, trackingAction: TRACKING_ACTION_COPY_KOTLIN_ADD_TO_SOURCE_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