Commit 7e6c8784 authored by Olena Horal-Koretska's avatar Olena Horal-Koretska

Merge branch...

Merge branch '207467-add-gradle-setup-and-install-commands-to-the-package-details-page-2' into 'master'

Add Gradle instructions and instruction selector to package details

See merge request gitlab-org/gitlab!55738
parents c8f71727 494a97a9
...@@ -2,12 +2,14 @@ ...@@ -2,12 +2,14 @@
import { GlLink, GlSprintf } from '@gitlab/ui'; import { GlLink, GlSprintf } from '@gitlab/ui';
import { mapGetters, mapState } from 'vuex'; import { mapGetters, mapState } from 'vuex';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import InstallationTitle from '~/packages/details/components/installation_title.vue';
import CodeInstruction from '~/vue_shared/components/registry/code_instruction.vue'; import CodeInstruction from '~/vue_shared/components/registry/code_instruction.vue';
import { TrackingActions, TrackingLabels } from '../constants'; import { TrackingActions, TrackingLabels } from '../constants';
export default { export default {
name: 'ComposerInstallation', name: 'ComposerInstallation',
components: { components: {
InstallationTitle,
CodeInstruction, CodeInstruction,
GlLink, GlLink,
GlSprintf, GlSprintf,
...@@ -27,12 +29,13 @@ export default { ...@@ -27,12 +29,13 @@ export default {
}, },
trackingActions: { ...TrackingActions }, trackingActions: { ...TrackingActions },
TrackingLabels, TrackingLabels,
installOptions: [{ value: 'composer', label: s__('PackageRegistry|Show Composer commands') }],
}; };
</script> </script>
<template> <template>
<div v-if="groupExists" data-testid="root-node"> <div v-if="groupExists" data-testid="root-node">
<h3 class="gl-font-lg">{{ __('Installation') }}</h3> <installation-title package-type="composer" :options="$options.installOptions" />
<code-instruction <code-instruction
:label="$options.i18n.registryInclude" :label="$options.i18n.registryInclude"
......
...@@ -2,12 +2,14 @@ ...@@ -2,12 +2,14 @@
import { GlLink, GlSprintf } from '@gitlab/ui'; import { GlLink, GlSprintf } from '@gitlab/ui';
import { mapGetters, mapState } from 'vuex'; import { mapGetters, mapState } from 'vuex';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import InstallationTitle from '~/packages/details/components/installation_title.vue';
import CodeInstruction from '~/vue_shared/components/registry/code_instruction.vue'; import CodeInstruction from '~/vue_shared/components/registry/code_instruction.vue';
import { TrackingActions, TrackingLabels } from '../constants'; import { TrackingActions, TrackingLabels } from '../constants';
export default { export default {
name: 'ConanInstallation', name: 'ConanInstallation',
components: { components: {
InstallationTitle,
CodeInstruction, CodeInstruction,
GlLink, GlLink,
GlSprintf, GlSprintf,
...@@ -23,12 +25,13 @@ export default { ...@@ -23,12 +25,13 @@ export default {
}, },
trackingActions: { ...TrackingActions }, trackingActions: { ...TrackingActions },
TrackingLabels, TrackingLabels,
installOptions: [{ value: 'conan', label: s__('PackageRegistry|Show Conan commands') }],
}; };
</script> </script>
<template> <template>
<div> <div>
<h3 class="gl-font-lg">{{ __('Installation') }}</h3> <installation-title package-type="conan" :options="$options.installOptions" />
<code-instruction <code-instruction
:label="s__('PackageRegistry|Conan Command')" :label="s__('PackageRegistry|Conan Command')"
......
<script>
import PersistedDropdownSelection from '~/vue_shared/components/registry/persisted_dropdown_selection.vue';
export default {
name: 'InstallationTitle',
components: {
PersistedDropdownSelection,
},
props: {
packageType: {
type: String,
required: true,
},
options: {
type: Array,
required: true,
},
},
computed: {
storageKey() {
return `package_${this.packageType}_installation_instructions`;
},
},
};
</script>
<template>
<div class="gl-display-flex gl-justify-content-space-between gl-align-items-center">
<h3 class="gl-font-lg">{{ __('Installation') }}</h3>
<div>
<persisted-dropdown-selection
:storage-key="storageKey"
:options="options"
@change="$emit('change', $event)"
/>
</div>
</div>
</template>
...@@ -2,12 +2,15 @@ ...@@ -2,12 +2,15 @@
import { GlLink, GlSprintf } from '@gitlab/ui'; import { GlLink, GlSprintf } from '@gitlab/ui';
import { mapGetters, mapState } from 'vuex'; import { mapGetters, mapState } from 'vuex';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import InstallationTitle from '~/packages/details/components/installation_title.vue';
import CodeInstruction from '~/vue_shared/components/registry/code_instruction.vue'; import CodeInstruction from '~/vue_shared/components/registry/code_instruction.vue';
import { TrackingActions, TrackingLabels } from '../constants'; import { TrackingActions, TrackingLabels } from '../constants';
export default { export default {
name: 'MavenInstallation', name: 'MavenInstallation',
components: { components: {
InstallationTitle,
CodeInstruction, CodeInstruction,
GlLink, GlLink,
GlSprintf, GlSprintf,
...@@ -19,7 +22,13 @@ export default { ...@@ -19,7 +22,13 @@ export default {
}, },
computed: { computed: {
...mapState(['mavenHelpPath']), ...mapState(['mavenHelpPath']),
...mapGetters(['mavenInstallationXml', 'mavenInstallationCommand', 'mavenSetupXml']), ...mapGetters([
'mavenInstallationXml',
'mavenInstallationCommand',
'mavenSetupXml',
'gradleGroovyInstalCommand',
'gradleGroovyAddSourceCommand',
]),
showMaven() { showMaven() {
return this.instructionType === 'maven'; return this.instructionType === 'maven';
}, },
...@@ -37,12 +46,20 @@ export default { ...@@ -37,12 +46,20 @@ export default {
}, },
trackingActions: { ...TrackingActions }, trackingActions: { ...TrackingActions },
TrackingLabels, TrackingLabels,
installOptions: [
{ value: 'maven', label: s__('PackageRegistry|Show Maven commands') },
{ value: 'groovy', label: s__('PackageRegistry|Show Gradle Groovy DSL commands') },
],
}; };
</script> </script>
<template> <template>
<div> <div>
<h3 class="gl-font-lg">{{ __('Installation') }}</h3> <installation-title
package-type="maven"
:options="$options.installOptions"
@change="instructionType = $event"
/>
<template v-if="showMaven"> <template v-if="showMaven">
<p> <p>
...@@ -90,5 +107,23 @@ export default { ...@@ -90,5 +107,23 @@ export default {
</template> </template>
</gl-sprintf> </gl-sprintf>
</template> </template>
<template v-else>
<code-instruction
class="gl-mb-5"
:label="s__('PackageRegistry|Gradle Groovy DSL install command')"
:instruction="gradleGroovyInstalCommand"
:copy-text="s__('PackageRegistry|Copy Gradle Groovy DSL install command')"
:tracking-action="$options.trackingActions.COPY_GRADLE_INSTALL_COMMAND"
:tracking-label="$options.TrackingLabels.CODE_INSTRUCTION"
/>
<code-instruction
:label="s__('PackageRegistry|Add Gradle Groovy DSL repository command')"
:instruction="gradleGroovyAddSourceCommand"
:copy-text="s__('PackageRegistry|Copy add Gradle Groovy DSL repository command')"
:tracking-action="$options.trackingActions.COPY_GRADLE_ADD_TO_SOURCE_COMMAND"
:tracking-label="$options.TrackingLabels.CODE_INSTRUCTION"
multiline
/>
</template>
</div> </div>
</template> </template>
...@@ -2,12 +2,14 @@ ...@@ -2,12 +2,14 @@
import { GlLink, GlSprintf } from '@gitlab/ui'; import { GlLink, GlSprintf } from '@gitlab/ui';
import { mapGetters, mapState } from 'vuex'; import { mapGetters, mapState } from 'vuex';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import InstallationTitle from '~/packages/details/components/installation_title.vue';
import CodeInstruction from '~/vue_shared/components/registry/code_instruction.vue'; import CodeInstruction from '~/vue_shared/components/registry/code_instruction.vue';
import { NpmManager, TrackingActions, TrackingLabels } from '../constants'; import { NpmManager, TrackingActions, TrackingLabels } from '../constants';
export default { export default {
name: 'NpmInstallation', name: 'NpmInstallation',
components: { components: {
InstallationTitle,
CodeInstruction, CodeInstruction,
GlLink, GlLink,
GlSprintf, GlSprintf,
...@@ -35,12 +37,13 @@ export default { ...@@ -35,12 +37,13 @@ export default {
}, },
trackingActions: { ...TrackingActions }, trackingActions: { ...TrackingActions },
TrackingLabels, TrackingLabels,
installOptions: [{ value: 'npm', label: s__('PackageRegistry|Show NPM commands') }],
}; };
</script> </script>
<template> <template>
<div> <div>
<h3 class="gl-font-lg">{{ __('Installation') }}</h3> <installation-title package-type="npm" :options="$options.installOptions" />
<code-instruction <code-instruction
:label="s__('PackageRegistry|npm command')" :label="s__('PackageRegistry|npm command')"
......
...@@ -2,12 +2,14 @@ ...@@ -2,12 +2,14 @@
import { GlLink, GlSprintf } from '@gitlab/ui'; import { GlLink, GlSprintf } from '@gitlab/ui';
import { mapGetters, mapState } from 'vuex'; import { mapGetters, mapState } from 'vuex';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import InstallationTitle from '~/packages/details/components/installation_title.vue';
import CodeInstruction from '~/vue_shared/components/registry/code_instruction.vue'; import CodeInstruction from '~/vue_shared/components/registry/code_instruction.vue';
import { TrackingActions, TrackingLabels } from '../constants'; import { TrackingActions, TrackingLabels } from '../constants';
export default { export default {
name: 'NugetInstallation', name: 'NugetInstallation',
components: { components: {
InstallationTitle,
CodeInstruction, CodeInstruction,
GlLink, GlLink,
GlSprintf, GlSprintf,
...@@ -23,12 +25,14 @@ export default { ...@@ -23,12 +25,14 @@ export default {
}, },
trackingActions: { ...TrackingActions }, trackingActions: { ...TrackingActions },
TrackingLabels, TrackingLabels,
installOptions: [{ value: 'nuget', label: s__('PackageRegistry|Show Nuget commands') }],
}; };
</script> </script>
<template> <template>
<div> <div>
<h3 class="gl-font-lg">{{ __('Installation') }}</h3> <installation-title package-type="nuget" :options="$options.installOptions" />
<code-instruction <code-instruction
:label="s__('PackageRegistry|NuGet Command')" :label="s__('PackageRegistry|NuGet Command')"
:instruction="nugetInstallationCommand" :instruction="nugetInstallationCommand"
......
...@@ -2,12 +2,14 @@ ...@@ -2,12 +2,14 @@
import { GlLink, GlSprintf } from '@gitlab/ui'; import { GlLink, GlSprintf } from '@gitlab/ui';
import { mapGetters, mapState } from 'vuex'; import { mapGetters, mapState } from 'vuex';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import InstallationTitle from '~/packages/details/components/installation_title.vue';
import CodeInstruction from '~/vue_shared/components/registry/code_instruction.vue'; import CodeInstruction from '~/vue_shared/components/registry/code_instruction.vue';
import { TrackingActions, TrackingLabels } from '../constants'; import { TrackingActions, TrackingLabels } from '../constants';
export default { export default {
name: 'PyPiInstallation', name: 'PyPiInstallation',
components: { components: {
InstallationTitle,
CodeInstruction, CodeInstruction,
GlLink, GlLink,
GlSprintf, GlSprintf,
...@@ -26,12 +28,13 @@ export default { ...@@ -26,12 +28,13 @@ export default {
}, },
trackingActions: { ...TrackingActions }, trackingActions: { ...TrackingActions },
TrackingLabels, TrackingLabels,
installOptions: [{ value: 'pypi', label: s__('PackageRegistry|Show PyPi commands') }],
}; };
</script> </script>
<template> <template>
<div> <div>
<h3 class="gl-font-lg">{{ __('Installation') }}</h3> <installation-title package-type="pypi" :options="$options.installOptions" />
<code-instruction <code-instruction
:label="s__('PackageRegistry|Pip Command')" :label="s__('PackageRegistry|Pip Command')"
......
...@@ -35,6 +35,9 @@ export const TrackingActions = { ...@@ -35,6 +35,9 @@ export const TrackingActions = {
COPY_COMPOSER_REGISTRY_INCLUDE_COMMAND: 'copy_composer_registry_include_command', COPY_COMPOSER_REGISTRY_INCLUDE_COMMAND: 'copy_composer_registry_include_command',
COPY_COMPOSER_PACKAGE_INCLUDE_COMMAND: 'copy_composer_package_include_command', COPY_COMPOSER_PACKAGE_INCLUDE_COMMAND: 'copy_composer_package_include_command',
COPY_GRADLE_INSTALL_COMMAND: 'copy_gradle_install_command',
COPY_GRADLE_ADD_TO_SOURCE_COMMAND: 'copy_gradle_add_to_source_command',
}; };
export const NpmManager = { export const NpmManager = {
......
...@@ -110,4 +110,20 @@ export const composerPackageInclude = ({ packageEntity }) => ...@@ -110,4 +110,20 @@ export const composerPackageInclude = ({ packageEntity }) =>
// eslint-disable-next-line @gitlab/require-i18n-strings // eslint-disable-next-line @gitlab/require-i18n-strings
`composer req ${[packageEntity.name]}:${packageEntity.version}`; `composer req ${[packageEntity.name]}:${packageEntity.version}`;
export const gradleGroovyInstalCommand = ({ packageEntity }) => {
const {
app_group: group = '',
app_name: name = '',
app_version: version = '',
} = packageEntity.maven_metadatum;
// eslint-disable-next-line @gitlab/require-i18n-strings
return `implementation '${group}:${name}:${version}'`;
};
export const gradleGroovyAddSourceCommand = ({ mavenPath }) =>
// eslint-disable-next-line @gitlab/require-i18n-strings
`gitlab {
url "${mavenPath}"
}`;
export const groupExists = ({ groupListUrl }) => groupListUrl.length > 0; export const groupExists = ({ groupListUrl }) => groupListUrl.length > 0;
---
title: Add Gradle instructions and instruction selector to package details
merge_request: 55738
author:
type: changed
...@@ -21583,6 +21583,9 @@ msgstr "" ...@@ -21583,6 +21583,9 @@ msgstr ""
msgid "PackageRegistry|Add Conan Remote" msgid "PackageRegistry|Add Conan Remote"
msgstr "" msgstr ""
msgid "PackageRegistry|Add Gradle Groovy DSL repository command"
msgstr ""
msgid "PackageRegistry|Add NuGet Source" msgid "PackageRegistry|Add NuGet Source"
msgstr "" msgstr ""
...@@ -21619,6 +21622,9 @@ msgstr "" ...@@ -21619,6 +21622,9 @@ msgstr ""
msgid "PackageRegistry|Copy Conan Setup Command" msgid "PackageRegistry|Copy Conan Setup Command"
msgstr "" msgstr ""
msgid "PackageRegistry|Copy Gradle Groovy DSL install command"
msgstr ""
msgid "PackageRegistry|Copy Maven XML" msgid "PackageRegistry|Copy Maven XML"
msgstr "" msgstr ""
...@@ -21637,6 +21643,9 @@ msgstr "" ...@@ -21637,6 +21643,9 @@ msgstr ""
msgid "PackageRegistry|Copy Pip command" msgid "PackageRegistry|Copy Pip command"
msgstr "" msgstr ""
msgid "PackageRegistry|Copy add Gradle Groovy DSL repository command"
msgstr ""
msgid "PackageRegistry|Copy and paste this inside your %{codeStart}pom.xml%{codeEnd} %{codeStart}dependencies%{codeEnd} block." msgid "PackageRegistry|Copy and paste this inside your %{codeStart}pom.xml%{codeEnd} %{codeStart}dependencies%{codeEnd} block."
msgstr "" msgstr ""
...@@ -21688,6 +21697,9 @@ msgstr "" ...@@ -21688,6 +21697,9 @@ msgstr ""
msgid "PackageRegistry|GitLab Packages allows organizations to utilize GitLab as a private repository for a variety of common package formats. %{linkStart}More Information%{linkEnd}" msgid "PackageRegistry|GitLab Packages allows organizations to utilize GitLab as a private repository for a variety of common package formats. %{linkStart}More Information%{linkEnd}"
msgstr "" msgstr ""
msgid "PackageRegistry|Gradle Groovy DSL install command"
msgstr ""
msgid "PackageRegistry|If you haven't already done so, you will need to add the below to your %{codeStart}.pypirc%{codeEnd} file." msgid "PackageRegistry|If you haven't already done so, you will need to add the below to your %{codeStart}.pypirc%{codeEnd} file."
msgstr "" msgstr ""
...@@ -21760,6 +21772,27 @@ msgstr "" ...@@ -21760,6 +21772,27 @@ msgstr ""
msgid "PackageRegistry|Settings saved successfully" msgid "PackageRegistry|Settings saved successfully"
msgstr "" msgstr ""
msgid "PackageRegistry|Show Composer commands"
msgstr ""
msgid "PackageRegistry|Show Conan commands"
msgstr ""
msgid "PackageRegistry|Show Gradle Groovy DSL commands"
msgstr ""
msgid "PackageRegistry|Show Maven commands"
msgstr ""
msgid "PackageRegistry|Show NPM commands"
msgstr ""
msgid "PackageRegistry|Show Nuget commands"
msgstr ""
msgid "PackageRegistry|Show PyPi commands"
msgstr ""
msgid "PackageRegistry|Sorry, your filter produced no results" msgid "PackageRegistry|Sorry, your filter produced no results"
msgstr "" msgstr ""
......
...@@ -2,11 +2,10 @@ ...@@ -2,11 +2,10 @@
exports[`ConanInstallation renders all the messages 1`] = ` exports[`ConanInstallation renders all the messages 1`] = `
<div> <div>
<h3 <installation-title-stub
class="gl-font-lg" options="[object Object]"
> packagetype="conan"
Installation />
</h3>
<code-instruction-stub <code-instruction-stub
copytext="Copy Conan Command" copytext="Copy Conan Command"
......
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`MavenInstallation renders all the messages 1`] = ` exports[`MavenInstallation gradle renders all the messages 1`] = `
<div> <div>
<h3 <installation-title-stub
class="gl-font-lg" options="[object Object],[object Object]"
> packagetype="maven"
Installation />
</h3>
<code-instruction-stub
class="gl-mb-5"
copytext="Copy Gradle Groovy DSL install command"
instruction="foo/gradle/install"
label="Gradle Groovy DSL install command"
trackingaction="copy_gradle_install_command"
trackinglabel="code_instruction"
/>
<code-instruction-stub
copytext="Copy add Gradle Groovy DSL repository command"
instruction="foo/gradle/add/source"
label="Add Gradle Groovy DSL repository command"
multiline="true"
trackingaction="copy_gradle_add_to_source_command"
trackinglabel="code_instruction"
/>
</div>
`;
exports[`MavenInstallation maven renders all the messages 1`] = `
<div>
<installation-title-stub
options="[object Object],[object Object]"
packagetype="maven"
/>
<p> <p>
<gl-sprintf-stub <gl-sprintf-stub
......
...@@ -2,11 +2,10 @@ ...@@ -2,11 +2,10 @@
exports[`NpmInstallation renders all the messages 1`] = ` exports[`NpmInstallation renders all the messages 1`] = `
<div> <div>
<h3 <installation-title-stub
class="gl-font-lg" options="[object Object]"
> packagetype="npm"
Installation />
</h3>
<code-instruction-stub <code-instruction-stub
copytext="Copy npm command" copytext="Copy npm command"
......
...@@ -2,11 +2,10 @@ ...@@ -2,11 +2,10 @@
exports[`NugetInstallation renders all the messages 1`] = ` exports[`NugetInstallation renders all the messages 1`] = `
<div> <div>
<h3 <installation-title-stub
class="gl-font-lg" options="[object Object]"
> packagetype="nuget"
Installation />
</h3>
<code-instruction-stub <code-instruction-stub
copytext="Copy NuGet Command" copytext="Copy NuGet Command"
......
...@@ -2,11 +2,10 @@ ...@@ -2,11 +2,10 @@
exports[`PypiInstallation renders all the messages 1`] = ` exports[`PypiInstallation renders all the messages 1`] = `
<div> <div>
<h3 <installation-title-stub
class="gl-font-lg" options="[object Object]"
> packagetype="pypi"
Installation />
</h3>
<code-instruction-stub <code-instruction-stub
copytext="Copy Pip command" copytext="Copy Pip command"
......
...@@ -4,6 +4,7 @@ import Vuex from 'vuex'; ...@@ -4,6 +4,7 @@ import Vuex from 'vuex';
import { registryUrl as composerHelpPath } from 'jest/packages/details/mock_data'; import { registryUrl as composerHelpPath } from 'jest/packages/details/mock_data';
import { composerPackage as packageEntity } from 'jest/packages/mock_data'; import { composerPackage as packageEntity } from 'jest/packages/mock_data';
import ComposerInstallation from '~/packages/details/components/composer_installation.vue'; import ComposerInstallation from '~/packages/details/components/composer_installation.vue';
import InstallationTitle from '~/packages/details/components/installation_title.vue';
import { TrackingActions } from '~/packages/details/constants'; import { TrackingActions } from '~/packages/details/constants';
...@@ -33,6 +34,7 @@ describe('ComposerInstallation', () => { ...@@ -33,6 +34,7 @@ describe('ComposerInstallation', () => {
const findPackageInclude = () => wrapper.find('[data-testid="package-include"]'); const findPackageInclude = () => wrapper.find('[data-testid="package-include"]');
const findHelpText = () => wrapper.find('[data-testid="help-text"]'); const findHelpText = () => wrapper.find('[data-testid="help-text"]');
const findHelpLink = () => wrapper.find(GlLink); const findHelpLink = () => wrapper.find(GlLink);
const findInstallationTitle = () => wrapper.findComponent(InstallationTitle);
function createComponent() { function createComponent() {
wrapper = shallowMount(ComposerInstallation, { wrapper = shallowMount(ComposerInstallation, {
...@@ -48,6 +50,19 @@ describe('ComposerInstallation', () => { ...@@ -48,6 +50,19 @@ describe('ComposerInstallation', () => {
wrapper.destroy(); wrapper.destroy();
}); });
describe('install command switch', () => {
it('has the installation title component', () => {
createStore();
createComponent();
expect(findInstallationTitle().exists()).toBe(true);
expect(findInstallationTitle().props()).toMatchObject({
packageType: 'composer',
options: [{ value: 'composer', label: 'Show Composer commands' }],
});
});
});
describe('registry include command', () => { describe('registry include command', () => {
beforeEach(() => { beforeEach(() => {
createStore(); createStore();
......
import { shallowMount, createLocalVue } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex'; import Vuex from 'vuex';
import ConanInstallation from '~/packages/details/components/conan_installation.vue'; import ConanInstallation from '~/packages/details/components/conan_installation.vue';
import InstallationTitle from '~/packages/details/components/installation_title.vue';
import CodeInstructions from '~/vue_shared/components/registry/code_instruction.vue'; import CodeInstructions from '~/vue_shared/components/registry/code_instruction.vue';
import { conanPackage as packageEntity } from '../../mock_data'; import { conanPackage as packageEntity } from '../../mock_data';
import { registryUrl as conanPath } from '../mock_data'; import { registryUrl as conanPath } from '../mock_data';
...@@ -26,6 +27,7 @@ describe('ConanInstallation', () => { ...@@ -26,6 +27,7 @@ describe('ConanInstallation', () => {
}); });
const findCodeInstructions = () => wrapper.findAll(CodeInstructions); const findCodeInstructions = () => wrapper.findAll(CodeInstructions);
const findInstallationTitle = () => wrapper.findComponent(InstallationTitle);
function createComponent() { function createComponent() {
wrapper = shallowMount(ConanInstallation, { wrapper = shallowMount(ConanInstallation, {
...@@ -39,13 +41,23 @@ describe('ConanInstallation', () => { ...@@ -39,13 +41,23 @@ describe('ConanInstallation', () => {
}); });
afterEach(() => { afterEach(() => {
if (wrapper) wrapper.destroy(); wrapper.destroy();
}); });
it('renders all the messages', () => { it('renders all the messages', () => {
expect(wrapper.element).toMatchSnapshot(); expect(wrapper.element).toMatchSnapshot();
}); });
describe('install command switch', () => {
it('has the installation title component', () => {
expect(findInstallationTitle().exists()).toBe(true);
expect(findInstallationTitle().props()).toMatchObject({
packageType: 'conan',
options: [{ value: 'conan', label: 'Show Conan commands' }],
});
});
});
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(conanInstallationCommandStr);
......
import { shallowMount } from '@vue/test-utils';
import InstallationTitle from '~/packages/details/components/installation_title.vue';
import PersistedDropdownSelection from '~/vue_shared/components/registry/persisted_dropdown_selection.vue';
describe('InstallationTitle', () => {
let wrapper;
const defaultProps = { packageType: 'foo', options: [{ value: 'foo', label: 'bar' }] };
const findPersistedDropdownSelection = () => wrapper.findComponent(PersistedDropdownSelection);
const findTitle = () => wrapper.find('h3');
function createComponent({ props = {} } = {}) {
wrapper = shallowMount(InstallationTitle, {
propsData: {
...defaultProps,
...props,
},
});
}
afterEach(() => {
wrapper.destroy();
});
it('has a title', () => {
createComponent();
expect(findTitle().exists()).toBe(true);
expect(findTitle().text()).toBe('Installation');
});
describe('persisted dropdown selection', () => {
it('exists', () => {
createComponent();
expect(findPersistedDropdownSelection().exists()).toBe(true);
});
it('has the correct props', () => {
createComponent();
expect(findPersistedDropdownSelection().props()).toMatchObject({
storageKey: 'package_foo_installation_instructions',
options: defaultProps.options,
});
});
it('on change event emits a change event', () => {
createComponent();
findPersistedDropdownSelection().vm.$emit('change', 'baz');
expect(wrapper.emitted('change')).toEqual([['baz']]);
});
});
});
import { shallowMount, createLocalVue } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import { nextTick } from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
import { registryUrl as mavenPath } from 'jest/packages/details/mock_data'; import { registryUrl as mavenPath } from 'jest/packages/details/mock_data';
import { mavenPackage as packageEntity } from 'jest/packages/mock_data'; import { mavenPackage as packageEntity } from 'jest/packages/mock_data';
import InstallationTitle from '~/packages/details/components/installation_title.vue';
import MavenInstallation from '~/packages/details/components/maven_installation.vue'; import MavenInstallation from '~/packages/details/components/maven_installation.vue';
import { TrackingActions } from '~/packages/details/constants'; import { TrackingActions } from '~/packages/details/constants';
import CodeInstructions from '~/vue_shared/components/registry/code_instruction.vue'; import CodeInstructions from '~/vue_shared/components/registry/code_instruction.vue';
...@@ -15,6 +17,8 @@ describe('MavenInstallation', () => { ...@@ -15,6 +17,8 @@ describe('MavenInstallation', () => {
const xmlCodeBlock = 'foo/xml'; const xmlCodeBlock = 'foo/xml';
const mavenCommandStr = 'foo/command'; const mavenCommandStr = 'foo/command';
const mavenSetupXml = 'foo/setup'; const mavenSetupXml = 'foo/setup';
const gradleGroovyInstallCommandText = 'foo/gradle/install';
const gradleGroovyAddSourceCommandText = 'foo/gradle/add/source';
const store = new Vuex.Store({ const store = new Vuex.Store({
state: { state: {
...@@ -25,24 +29,59 @@ describe('MavenInstallation', () => { ...@@ -25,24 +29,59 @@ describe('MavenInstallation', () => {
mavenInstallationXml: () => xmlCodeBlock, mavenInstallationXml: () => xmlCodeBlock,
mavenInstallationCommand: () => mavenCommandStr, mavenInstallationCommand: () => mavenCommandStr,
mavenSetupXml: () => mavenSetupXml, mavenSetupXml: () => mavenSetupXml,
gradleGroovyInstalCommand: () => gradleGroovyInstallCommandText,
gradleGroovyAddSourceCommand: () => gradleGroovyAddSourceCommandText,
}, },
}); });
const findCodeInstructions = () => wrapper.findAll(CodeInstructions); const findCodeInstructions = () => wrapper.findAll(CodeInstructions);
const findInstallationTitle = () => wrapper.findComponent(InstallationTitle);
function createComponent() { function createComponent({ data = {} } = {}) {
wrapper = shallowMount(MavenInstallation, { wrapper = shallowMount(MavenInstallation, {
localVue, localVue,
store, store,
data() {
return data;
},
}); });
} }
beforeEach(() => { afterEach(() => {
wrapper.destroy();
});
describe('install command switch', () => {
it('has the installation title component', () => {
createComponent(); createComponent();
expect(findInstallationTitle().exists()).toBe(true);
expect(findInstallationTitle().props()).toMatchObject({
packageType: 'maven',
options: [
{ value: 'maven', label: 'Show Maven commands' },
{ value: 'groovy', label: 'Show Gradle Groovy DSL commands' },
],
});
}); });
afterEach(() => { it('on change event updates the instructions to show', async () => {
if (wrapper) wrapper.destroy(); createComponent();
expect(findCodeInstructions().at(0).props('instruction')).toBe(xmlCodeBlock);
findInstallationTitle().vm.$emit('change', 'groovy');
await nextTick();
expect(findCodeInstructions().at(0).props('instruction')).toBe(
gradleGroovyInstallCommandText,
);
});
});
describe('maven', () => {
beforeEach(() => {
createComponent();
}); });
it('renders all the messages', () => { it('renders all the messages', () => {
...@@ -76,4 +115,35 @@ describe('MavenInstallation', () => { ...@@ -76,4 +115,35 @@ describe('MavenInstallation', () => {
}); });
}); });
}); });
});
describe('gradle', () => {
beforeEach(() => {
createComponent({ data: { instructionType: 'gradle' } });
});
it('renders all the messages', () => {
expect(wrapper.element).toMatchSnapshot();
});
describe('installation commands', () => {
it('renders the gradle install command', () => {
expect(findCodeInstructions().at(0).props()).toMatchObject({
instruction: gradleGroovyInstallCommandText,
multiline: false,
trackingAction: TrackingActions.COPY_GRADLE_INSTALL_COMMAND,
});
});
});
describe('setup commands', () => {
it('renders the correct gradle command', () => {
expect(findCodeInstructions().at(1).props()).toMatchObject({
instruction: gradleGroovyAddSourceCommandText,
multiline: true,
trackingAction: TrackingActions.COPY_GRADLE_ADD_TO_SOURCE_COMMAND,
});
});
});
});
}); });
...@@ -2,6 +2,7 @@ import { shallowMount, createLocalVue } from '@vue/test-utils'; ...@@ -2,6 +2,7 @@ import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex'; import Vuex from 'vuex';
import { registryUrl as nugetPath } from 'jest/packages/details/mock_data'; import { registryUrl as nugetPath } from 'jest/packages/details/mock_data';
import { npmPackage as packageEntity } from 'jest/packages/mock_data'; import { npmPackage as packageEntity } from 'jest/packages/mock_data';
import InstallationTitle from '~/packages/details/components/installation_title.vue';
import NpmInstallation from '~/packages/details/components/npm_installation.vue'; import NpmInstallation from '~/packages/details/components/npm_installation.vue';
import { TrackingActions } from '~/packages/details/constants'; import { TrackingActions } from '~/packages/details/constants';
import { npmInstallationCommand, npmSetupCommand } from '~/packages/details/store/getters'; import { npmInstallationCommand, npmSetupCommand } from '~/packages/details/store/getters';
...@@ -14,6 +15,7 @@ describe('NpmInstallation', () => { ...@@ -14,6 +15,7 @@ describe('NpmInstallation', () => {
let wrapper; let wrapper;
const findCodeInstructions = () => wrapper.findAll(CodeInstructions); const findCodeInstructions = () => wrapper.findAll(CodeInstructions);
const findInstallationTitle = () => wrapper.findComponent(InstallationTitle);
function createComponent() { function createComponent() {
const store = new Vuex.Store({ const store = new Vuex.Store({
...@@ -38,13 +40,23 @@ describe('NpmInstallation', () => { ...@@ -38,13 +40,23 @@ describe('NpmInstallation', () => {
}); });
afterEach(() => { afterEach(() => {
if (wrapper) wrapper.destroy(); wrapper.destroy();
}); });
it('renders all the messages', () => { it('renders all the messages', () => {
expect(wrapper.element).toMatchSnapshot(); expect(wrapper.element).toMatchSnapshot();
}); });
describe('install command switch', () => {
it('has the installation title component', () => {
expect(findInstallationTitle().exists()).toBe(true);
expect(findInstallationTitle().props()).toMatchObject({
packageType: 'npm',
options: [{ value: 'npm', label: 'Show NPM commands' }],
});
});
});
describe('installation commands', () => { describe('installation commands', () => {
it('renders the correct npm command', () => { it('renders the correct npm command', () => {
expect(findCodeInstructions().at(0).props()).toMatchObject({ expect(findCodeInstructions().at(0).props()).toMatchObject({
......
...@@ -2,6 +2,7 @@ import { shallowMount, createLocalVue } from '@vue/test-utils'; ...@@ -2,6 +2,7 @@ import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex'; import Vuex from 'vuex';
import { registryUrl as nugetPath } from 'jest/packages/details/mock_data'; import { registryUrl as nugetPath } from 'jest/packages/details/mock_data';
import { nugetPackage as packageEntity } from 'jest/packages/mock_data'; import { nugetPackage as packageEntity } from 'jest/packages/mock_data';
import InstallationTitle from '~/packages/details/components/installation_title.vue';
import NugetInstallation from '~/packages/details/components/nuget_installation.vue'; import NugetInstallation from '~/packages/details/components/nuget_installation.vue';
import { TrackingActions } from '~/packages/details/constants'; import { TrackingActions } from '~/packages/details/constants';
import CodeInstructions from '~/vue_shared/components/registry/code_instruction.vue'; import CodeInstructions from '~/vue_shared/components/registry/code_instruction.vue';
...@@ -27,6 +28,7 @@ describe('NugetInstallation', () => { ...@@ -27,6 +28,7 @@ describe('NugetInstallation', () => {
}); });
const findCodeInstructions = () => wrapper.findAll(CodeInstructions); const findCodeInstructions = () => wrapper.findAll(CodeInstructions);
const findInstallationTitle = () => wrapper.findComponent(InstallationTitle);
function createComponent() { function createComponent() {
wrapper = shallowMount(NugetInstallation, { wrapper = shallowMount(NugetInstallation, {
...@@ -40,13 +42,23 @@ describe('NugetInstallation', () => { ...@@ -40,13 +42,23 @@ describe('NugetInstallation', () => {
}); });
afterEach(() => { afterEach(() => {
if (wrapper) wrapper.destroy(); wrapper.destroy();
}); });
it('renders all the messages', () => { it('renders all the messages', () => {
expect(wrapper.element).toMatchSnapshot(); expect(wrapper.element).toMatchSnapshot();
}); });
describe('install command switch', () => {
it('has the installation title component', () => {
expect(findInstallationTitle().exists()).toBe(true);
expect(findInstallationTitle().props()).toMatchObject({
packageType: 'nuget',
options: [{ value: 'nuget', label: 'Show Nuget commands' }],
});
});
});
describe('installation commands', () => { describe('installation commands', () => {
it('renders the correct command', () => { it('renders the correct command', () => {
expect(findCodeInstructions().at(0).props()).toMatchObject({ expect(findCodeInstructions().at(0).props()).toMatchObject({
......
import { shallowMount, createLocalVue } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex'; import Vuex from 'vuex';
import { pypiPackage as packageEntity } from 'jest/packages/mock_data'; 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'; import PypiInstallation from '~/packages/details/components/pypi_installation.vue';
const localVue = createLocalVue(); const localVue = createLocalVue();
...@@ -26,6 +27,8 @@ describe('PypiInstallation', () => { ...@@ -26,6 +27,8 @@ describe('PypiInstallation', () => {
const pipCommand = () => wrapper.find('[data-testid="pip-command"]'); const pipCommand = () => wrapper.find('[data-testid="pip-command"]');
const setupInstruction = () => wrapper.find('[data-testid="pypi-setup-content"]'); const setupInstruction = () => wrapper.find('[data-testid="pypi-setup-content"]');
const findInstallationTitle = () => wrapper.findComponent(InstallationTitle);
function createComponent() { function createComponent() {
wrapper = shallowMount(PypiInstallation, { wrapper = shallowMount(PypiInstallation, {
localVue, localVue,
...@@ -39,7 +42,16 @@ describe('PypiInstallation', () => { ...@@ -39,7 +42,16 @@ describe('PypiInstallation', () => {
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
wrapper = null; });
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', () => { it('renders all the messages', () => {
......
...@@ -17,6 +17,8 @@ import { ...@@ -17,6 +17,8 @@ import {
composerRegistryInclude, composerRegistryInclude,
composerPackageInclude, composerPackageInclude,
groupExists, groupExists,
gradleGroovyInstalCommand,
gradleGroovyAddSourceCommand,
} from '~/packages/details/store/getters'; } from '~/packages/details/store/getters';
import { import {
conanPackage, conanPackage,
...@@ -235,6 +237,26 @@ describe('Getters PackageDetails Store', () => { ...@@ -235,6 +237,26 @@ describe('Getters PackageDetails Store', () => {
}); });
}); });
describe('gradle groovy string getters', () => {
it('gets the correct gradleGroovyInstalCommand', () => {
setupState();
expect(gradleGroovyInstalCommand(state)).toMatchInlineSnapshot(
`"implementation 'com.test.app:test-app:1.0-SNAPSHOT'"`,
);
});
it('gets the correct gradleGroovyAddSourceCommand', () => {
setupState();
expect(gradleGroovyAddSourceCommand(state)).toMatchInlineSnapshot(`
"gitlab {
url \\"foo/registry\\"
}"
`);
});
});
describe('check if group', () => { describe('check if group', () => {
it('is set', () => { it('is set', () => {
setupState({ groupListUrl: '/groups/composer/-/packages' }); setupState({ groupListUrl: '/groups/composer/-/packages' });
......
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