Commit 3326fe4d authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera Committed by Olena Horal-Koretska

Add unit test for group in composer install command

parent 3e517406
...@@ -31,34 +31,32 @@ export default { ...@@ -31,34 +31,32 @@ export default {
</script> </script>
<template> <template>
<div> <div v-if="groupExists" data-testid="root-node">
<div v-if="groupExists"> <h3 class="gl-font-lg">{{ __('Installation') }}</h3>
<h3 class="gl-font-lg">{{ __('Installation') }}</h3>
<code-instruction <code-instruction
: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.trackingActions.COPY_COMPOSER_REGISTRY_INCLUDE_COMMAND"
:tracking-label="$options.TrackingLabels.CODE_INSTRUCTION" :tracking-label="$options.TrackingLabels.CODE_INSTRUCTION"
data-testid="registry-include" data-testid="registry-include"
/> />
<code-instruction <code-instruction
: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.trackingActions.COPY_COMPOSER_PACKAGE_INCLUDE_COMMAND"
:tracking-label="$options.TrackingLabels.CODE_INSTRUCTION" :tracking-label="$options.TrackingLabels.CODE_INSTRUCTION"
data-testid="package-include" data-testid="package-include"
/> />
<span data-testid="help-text"> <span data-testid="help-text">
<gl-sprintf :message="$options.i18n.infoLine"> <gl-sprintf :message="$options.i18n.infoLine">
<template #link="{ content }"> <template #link="{ content }">
<gl-link :href="composerHelpPath" target="_blank">{{ content }}</gl-link> <gl-link :href="composerHelpPath" target="_blank">{{ content }}</gl-link>
</template> </template>
</gl-sprintf> </gl-sprintf>
</span> </span>
</div>
</div> </div>
</template> </template>
...@@ -12,24 +12,23 @@ localVue.use(Vuex); ...@@ -12,24 +12,23 @@ localVue.use(Vuex);
describe('ComposerInstallation', () => { describe('ComposerInstallation', () => {
let wrapper; let wrapper;
let store;
const composerRegistryIncludeStr = 'foo/registry'; const composerRegistryIncludeStr = 'foo/registry';
const composerPackageIncludeStr = 'foo/package'; const composerPackageIncludeStr = 'foo/package';
const groupExists = true;
const store = new Vuex.Store({
state: {
packageEntity,
composerHelpPath,
groupExists,
},
getters: {
composerRegistryInclude: () => composerRegistryIncludeStr,
composerPackageInclude: () => composerPackageIncludeStr,
groupExists: () => groupExists,
},
});
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 findRegistryInclude = () => wrapper.find('[data-testid="registry-include"]'); const findRegistryInclude = () => wrapper.find('[data-testid="registry-include"]');
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"]');
...@@ -45,15 +44,16 @@ describe('ComposerInstallation', () => { ...@@ -45,15 +44,16 @@ describe('ComposerInstallation', () => {
}); });
} }
beforeEach(() => {
createComponent();
});
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
}); });
describe('registry include command', () => { describe('registry include command', () => {
beforeEach(() => {
createStore();
createComponent();
});
it('uses code_instructions', () => { it('uses code_instructions', () => {
const registryIncludeCommand = findRegistryInclude(); const registryIncludeCommand = findRegistryInclude();
expect(registryIncludeCommand.exists()).toBe(true); expect(registryIncludeCommand.exists()).toBe(true);
...@@ -70,6 +70,11 @@ describe('ComposerInstallation', () => { ...@@ -70,6 +70,11 @@ describe('ComposerInstallation', () => {
}); });
describe('package include command', () => { describe('package include command', () => {
beforeEach(() => {
createStore();
createComponent();
});
it('uses code_instructions', () => { it('uses code_instructions', () => {
const registryIncludeCommand = findPackageInclude(); const registryIncludeCommand = findPackageInclude();
expect(registryIncludeCommand.exists()).toBe(true); expect(registryIncludeCommand.exists()).toBe(true);
...@@ -94,4 +99,20 @@ describe('ComposerInstallation', () => { ...@@ -94,4 +99,20 @@ describe('ComposerInstallation', () => {
}); });
}); });
}); });
describe('root node', () => {
it('is normally rendered', () => {
createStore();
createComponent();
expect(findRootNode().exists()).toBe(true);
});
it('is not rendered when the group does not exist', () => {
createStore(false);
createComponent();
expect(findRootNode().exists()).toBe(false);
});
});
}); });
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