Commit 911a5878 authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera Committed by Enrique Alcántara

Move npm and yarn to new dropdown UI

parent 3e1bf200
...@@ -14,6 +14,11 @@ export default { ...@@ -14,6 +14,11 @@ export default {
GlLink, GlLink,
GlSprintf, GlSprintf,
}, },
data() {
return {
instructionType: 'npm',
};
},
computed: { computed: {
...mapState(['npmHelpPath']), ...mapState(['npmHelpPath']),
...mapGetters(['npmInstallationCommand', 'npmSetupCommand']), ...mapGetters(['npmInstallationCommand', 'npmSetupCommand']),
...@@ -29,6 +34,9 @@ export default { ...@@ -29,6 +34,9 @@ export default {
yarnSetupCommand() { yarnSetupCommand() {
return this.npmSetupCommand(NpmManager.YARN); return this.npmSetupCommand(NpmManager.YARN);
}, },
showNpm() {
return this.instructionType === 'npm';
},
}, },
i18n: { i18n: {
helpText: s__( helpText: s__(
...@@ -37,16 +45,23 @@ export default { ...@@ -37,16 +45,23 @@ export default {
}, },
trackingActions: { ...TrackingActions }, trackingActions: { ...TrackingActions },
TrackingLabels, TrackingLabels,
installOptions: [{ value: 'npm', label: s__('PackageRegistry|Show NPM commands') }], installOptions: [
{ value: 'npm', label: s__('PackageRegistry|Show NPM commands') },
{ value: 'yarn', label: s__('PackageRegistry|Show Yarn commands') },
],
}; };
</script> </script>
<template> <template>
<div> <div>
<installation-title package-type="npm" :options="$options.installOptions" /> <installation-title
package-type="npm"
:options="$options.installOptions"
@change="instructionType = $event"
/>
<code-instruction <code-instruction
:label="s__('PackageRegistry|npm command')" 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.trackingActions.COPY_NPM_INSTALL_COMMAND"
...@@ -54,7 +69,7 @@ export default { ...@@ -54,7 +69,7 @@ export default {
/> />
<code-instruction <code-instruction
:label="s__('PackageRegistry|yarn command')" 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.trackingActions.COPY_YARN_INSTALL_COMMAND"
...@@ -64,7 +79,7 @@ export default { ...@@ -64,7 +79,7 @@ export default {
<h3 class="gl-font-lg">{{ __('Registry setup') }}</h3> <h3 class="gl-font-lg">{{ __('Registry setup') }}</h3>
<code-instruction <code-instruction
:label="s__('PackageRegistry|npm command')" 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.trackingActions.COPY_NPM_SETUP_COMMAND"
...@@ -72,7 +87,7 @@ export default { ...@@ -72,7 +87,7 @@ export default {
/> />
<code-instruction <code-instruction
:label="s__('PackageRegistry|yarn command')" 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.trackingActions.COPY_YARN_SETUP_COMMAND"
......
---
title: Move npm and yarn to new dropdown UI
merge_request: 59628
author:
type: changed
...@@ -22742,6 +22742,9 @@ msgstr "" ...@@ -22742,6 +22742,9 @@ msgstr ""
msgid "PackageRegistry|Show PyPi commands" msgid "PackageRegistry|Show PyPi commands"
msgstr "" msgstr ""
msgid "PackageRegistry|Show Yarn commands"
msgstr ""
msgid "PackageRegistry|Sorry, your filter produced no results" msgid "PackageRegistry|Sorry, your filter produced no results"
msgstr "" msgstr ""
...@@ -22784,15 +22787,9 @@ msgstr "" ...@@ -22784,15 +22787,9 @@ msgstr ""
msgid "PackageRegistry|npm" msgid "PackageRegistry|npm"
msgstr "" msgstr ""
msgid "PackageRegistry|npm command"
msgstr ""
msgid "PackageRegistry|published by %{author}" msgid "PackageRegistry|published by %{author}"
msgstr "" msgstr ""
msgid "PackageRegistry|yarn command"
msgstr ""
msgid "Packages" msgid "Packages"
msgstr "" msgstr ""
......
...@@ -3,26 +3,18 @@ ...@@ -3,26 +3,18 @@
exports[`NpmInstallation renders all the messages 1`] = ` exports[`NpmInstallation renders all the messages 1`] = `
<div> <div>
<installation-title-stub <installation-title-stub
options="[object Object]" options="[object Object],[object Object]"
packagetype="npm" packagetype="npm"
/> />
<code-instruction-stub <code-instruction-stub
copytext="Copy npm command" copytext="Copy npm command"
instruction="npm i @Test/package" instruction="npm i @Test/package"
label="npm command" label=""
trackingaction="copy_npm_install_command" trackingaction="copy_npm_install_command"
trackinglabel="code_instruction" trackinglabel="code_instruction"
/> />
<code-instruction-stub
copytext="Copy yarn command"
instruction="yarn add @Test/package"
label="yarn command"
trackingaction="copy_yarn_install_command"
trackinglabel="code_instruction"
/>
<h3 <h3
class="gl-font-lg" class="gl-font-lg"
> >
...@@ -32,19 +24,11 @@ exports[`NpmInstallation renders all the messages 1`] = ` ...@@ -32,19 +24,11 @@ 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 @Test:registry=undefined/ >> .npmrc"
label="npm command" label=""
trackingaction="copy_npm_setup_command" trackingaction="copy_npm_setup_command"
trackinglabel="code_instruction" trackinglabel="code_instruction"
/> />
<code-instruction-stub
copytext="Copy yarn setup command"
instruction="echo \\\\\\"@Test:registry\\\\\\" \\\\\\"undefined/\\\\\\" >> .yarnrc"
label="yarn command"
trackingaction="copy_yarn_setup_command"
trackinglabel="code_instruction"
/>
<gl-sprintf-stub <gl-sprintf-stub
message="You may also need to setup authentication using an auth token. %{linkStart}See the documentation%{linkEnd} to find out more." message="You may also need to setup authentication using an auth token. %{linkStart}See the documentation%{linkEnd} to find out more."
/> />
......
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 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';
...@@ -14,10 +15,13 @@ localVue.use(Vuex); ...@@ -14,10 +15,13 @@ localVue.use(Vuex);
describe('NpmInstallation', () => { describe('NpmInstallation', () => {
let wrapper; let wrapper;
const npmInstallationCommandLabel = 'npm i @Test/package';
const yarnInstallationCommandLabel = 'yarn add @Test/package';
const findCodeInstructions = () => wrapper.findAll(CodeInstructions); const findCodeInstructions = () => wrapper.findAll(CodeInstructions);
const findInstallationTitle = () => wrapper.findComponent(InstallationTitle); const findInstallationTitle = () => wrapper.findComponent(InstallationTitle);
function createComponent() { function createComponent({ data = {} } = {}) {
const store = new Vuex.Store({ const store = new Vuex.Store({
state: { state: {
packageEntity, packageEntity,
...@@ -32,6 +36,9 @@ describe('NpmInstallation', () => { ...@@ -32,6 +36,9 @@ describe('NpmInstallation', () => {
wrapper = shallowMount(NpmInstallation, { wrapper = shallowMount(NpmInstallation, {
localVue, localVue,
store, store,
data() {
return data;
},
}); });
} }
...@@ -52,40 +59,61 @@ describe('NpmInstallation', () => { ...@@ -52,40 +59,61 @@ describe('NpmInstallation', () => {
expect(findInstallationTitle().exists()).toBe(true); expect(findInstallationTitle().exists()).toBe(true);
expect(findInstallationTitle().props()).toMatchObject({ expect(findInstallationTitle().props()).toMatchObject({
packageType: 'npm', packageType: 'npm',
options: [{ value: 'npm', label: 'Show NPM commands' }], options: [
{ value: 'npm', label: 'Show NPM commands' },
{ value: 'yarn', label: 'Show Yarn commands' },
],
}); });
}); });
it('on change event updates the instructions to show', async () => {
createComponent();
expect(findCodeInstructions().at(0).props('instruction')).toBe(npmInstallationCommandLabel);
findInstallationTitle().vm.$emit('change', 'yarn');
await nextTick();
expect(findCodeInstructions().at(0).props('instruction')).toBe(yarnInstallationCommandLabel);
});
}); });
describe('installation commands', () => { describe('npm', () => {
it('renders the correct npm command', () => { beforeEach(() => {
createComponent();
});
it('renders the correct installation command', () => {
expect(findCodeInstructions().at(0).props()).toMatchObject({ expect(findCodeInstructions().at(0).props()).toMatchObject({
instruction: 'npm i @Test/package', instruction: npmInstallationCommandLabel,
multiline: false, multiline: false,
trackingAction: TrackingActions.COPY_NPM_INSTALL_COMMAND, trackingAction: TrackingActions.COPY_NPM_INSTALL_COMMAND,
}); });
}); });
it('renders the correct yarn command', () => { it('renders the correct setup command', () => {
expect(findCodeInstructions().at(1).props()).toMatchObject({ expect(findCodeInstructions().at(1).props()).toMatchObject({
instruction: 'yarn add @Test/package', instruction: 'echo @Test:registry=undefined/ >> .npmrc',
multiline: false, multiline: false,
trackingAction: TrackingActions.COPY_YARN_INSTALL_COMMAND, trackingAction: TrackingActions.COPY_NPM_SETUP_COMMAND,
}); });
}); });
}); });
describe('setup commands', () => { describe('yarn', () => {
it('renders the correct npm command', () => { beforeEach(() => {
expect(findCodeInstructions().at(2).props()).toMatchObject({ createComponent({ data: { instructionType: 'yarn' } });
instruction: 'echo @Test:registry=undefined/ >> .npmrc', });
it('renders the correct setup command', () => {
expect(findCodeInstructions().at(0).props()).toMatchObject({
instruction: yarnInstallationCommandLabel,
multiline: false, multiline: false,
trackingAction: TrackingActions.COPY_NPM_SETUP_COMMAND, trackingAction: TrackingActions.COPY_YARN_INSTALL_COMMAND,
}); });
}); });
it('renders the correct yarn command', () => { it('renders the correct registry command', () => {
expect(findCodeInstructions().at(3).props()).toMatchObject({ expect(findCodeInstructions().at(1).props()).toMatchObject({
instruction: 'echo \\"@Test:registry\\" \\"undefined/\\" >> .yarnrc', instruction: 'echo \\"@Test:registry\\" \\"undefined/\\" >> .yarnrc',
multiline: false, multiline: false,
trackingAction: TrackingActions.COPY_YARN_SETUP_COMMAND, trackingAction: TrackingActions.COPY_YARN_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