Commit 4b1e65aa authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch '326018-handle-missing-instruction-error' into 'master'

Improve error handling of runner instructions

See merge request gitlab-org/gitlab!57588
parents a87fb437 e4dccc42
...@@ -9,6 +9,7 @@ import { ...@@ -9,6 +9,7 @@ import {
GlDropdownItem, GlDropdownItem,
GlIcon, GlIcon,
} from '@gitlab/ui'; } from '@gitlab/ui';
import { isEmpty } from 'lodash';
import { __, s__ } from '~/locale'; import { __, s__ } from '~/locale';
import ModalCopyButton from '~/vue_shared/components/modal_copy_button.vue'; import ModalCopyButton from '~/vue_shared/components/modal_copy_button.vue';
import { import {
...@@ -79,7 +80,7 @@ export default { ...@@ -79,7 +80,7 @@ export default {
return Object.keys(this.selectedPlatform).length > 0; return Object.keys(this.selectedPlatform).length > 0;
}, },
instructionsEmpty() { instructionsEmpty() {
return Object.keys(this.instructions).length === 0; return isEmpty(this.instructions);
}, },
groupId() { groupId() {
return this.group?.id ?? ''; return this.group?.id ?? '';
...@@ -212,10 +213,7 @@ export default { ...@@ -212,10 +213,7 @@ export default {
<pre <pre
class="gl-bg-gray gl-flex-fill-1 gl-white-space-pre-line" class="gl-bg-gray gl-flex-fill-1 gl-white-space-pre-line"
data-testid="binary-instructions" data-testid="binary-instructions"
> >{{ instructions.installInstructions }}</pre
{{ instructions.installInstructions }}
</pre
> >
<modal-copy-button <modal-copy-button
:title="$options.i18n.copyInstructions" :title="$options.i18n.copyInstructions"
......
...@@ -19,5 +19,5 @@ ...@@ -19,5 +19,5 @@
type: 'group', type: 'group',
reset_token_url: reset_registration_token_group_settings_ci_cd_path, reset_token_url: reset_registration_token_group_settings_ci_cd_path,
project_path: '', project_path: '',
group_path: @group.path } group_path: @group.full_path }
%br %br
---
title: Display error message when runner installation instructions modal cannot be
loaded correctly
merge_request: 57588
author:
type: fixed
import { GlAlert } from '@gitlab/ui';
import { shallowMount, createLocalVue } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import createMockApollo from 'helpers/mock_apollo_helper'; import createMockApollo from 'helpers/mock_apollo_helper';
...@@ -14,7 +15,10 @@ localVue.use(VueApollo); ...@@ -14,7 +15,10 @@ localVue.use(VueApollo);
describe('RunnerInstructions component', () => { describe('RunnerInstructions component', () => {
let wrapper; let wrapper;
let fakeApollo; let fakeApollo;
let runnerPlatformsHandler;
let runnerSetupInstructionsHandler;
const findAlert = () => wrapper.findComponent(GlAlert);
const findModalButton = () => wrapper.find('[data-testid="show-modal-button"]'); const findModalButton = () => wrapper.find('[data-testid="show-modal-button"]');
const findPlatformButtons = () => wrapper.findAll('[data-testid="platform-button"]'); const findPlatformButtons = () => wrapper.findAll('[data-testid="platform-button"]');
const findArchitectureDropdownItems = () => const findArchitectureDropdownItems = () =>
...@@ -22,10 +26,10 @@ describe('RunnerInstructions component', () => { ...@@ -22,10 +26,10 @@ describe('RunnerInstructions component', () => {
const findBinaryInstructionsSection = () => wrapper.find('[data-testid="binary-instructions"]'); const findBinaryInstructionsSection = () => wrapper.find('[data-testid="binary-instructions"]');
const findRunnerInstructionsSection = () => wrapper.find('[data-testid="runner-instructions"]'); const findRunnerInstructionsSection = () => wrapper.find('[data-testid="runner-instructions"]');
beforeEach(async () => { const createComponent = () => {
const requestHandlers = [ const requestHandlers = [
[getRunnerPlatforms, jest.fn().mockResolvedValue(mockGraphqlRunnerPlatforms)], [getRunnerPlatforms, runnerPlatformsHandler],
[getRunnerSetupInstructions, jest.fn().mockResolvedValue(mockGraphqlInstructions)], [getRunnerSetupInstructions, runnerSetupInstructionsHandler],
]; ];
fakeApollo = createMockApollo(requestHandlers); fakeApollo = createMockApollo(requestHandlers);
...@@ -37,6 +41,13 @@ describe('RunnerInstructions component', () => { ...@@ -37,6 +41,13 @@ describe('RunnerInstructions component', () => {
localVue, localVue,
apolloProvider: fakeApollo, apolloProvider: fakeApollo,
}); });
};
beforeEach(async () => {
runnerPlatformsHandler = jest.fn().mockResolvedValue(mockGraphqlRunnerPlatforms);
runnerSetupInstructionsHandler = jest.fn().mockResolvedValue(mockGraphqlInstructions);
createComponent();
await wrapper.vm.$nextTick(); await wrapper.vm.$nextTick();
}); });
...@@ -46,6 +57,10 @@ describe('RunnerInstructions component', () => { ...@@ -46,6 +57,10 @@ describe('RunnerInstructions component', () => {
wrapper = null; wrapper = null;
}); });
it('should not show alert', () => {
expect(findAlert().exists()).toBe(false);
});
it('should show the "Show Runner installation instructions" button', () => { it('should show the "Show Runner installation instructions" button', () => {
const button = findModalButton(); const button = findModalButton();
...@@ -110,4 +125,23 @@ describe('RunnerInstructions component', () => { ...@@ -110,4 +125,23 @@ describe('RunnerInstructions component', () => {
expect(runner.text()).toMatch(mockGraphqlInstructions.data.runnerSetup.registerInstructions); expect(runner.text()).toMatch(mockGraphqlInstructions.data.runnerSetup.registerInstructions);
}); });
describe('when instructions cannot be loaded', () => {
beforeEach(async () => {
runnerSetupInstructionsHandler.mockRejectedValue();
createComponent();
await wrapper.vm.$nextTick();
});
it('should show alert', () => {
expect(findAlert().exists()).toBe(true);
});
it('should not show instructions', () => {
expect(findBinaryInstructionsSection().exists()).toBe(false);
expect(findRunnerInstructionsSection().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