Commit 2df7a6e7 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch '229209-cluster-application-row-loading-button' into 'master'

Migrate loading buttons on cluster applications

Closes #229212 and #229209

See merge request gitlab-org/gitlab!39772
parents 0bd95086 5ff1c51b
<script> <script>
import { GlLink, GlModalDirective, GlSprintf } from '@gitlab/ui'; import { GlLink, GlModalDirective, GlSprintf, GlButton } from '@gitlab/ui';
import { s__, __, sprintf } from '~/locale'; import { s__, __, sprintf } from '~/locale';
import eventHub from '../event_hub'; import eventHub from '../event_hub';
import identicon from '../../vue_shared/components/identicon.vue'; import identicon from '../../vue_shared/components/identicon.vue';
import loadingButton from '../../vue_shared/components/loading_button.vue';
import UninstallApplicationButton from './uninstall_application_button.vue'; import UninstallApplicationButton from './uninstall_application_button.vue';
import UninstallApplicationConfirmationModal from './uninstall_application_confirmation_modal.vue'; import UninstallApplicationConfirmationModal from './uninstall_application_confirmation_modal.vue';
import UpdateApplicationConfirmationModal from './update_application_confirmation_modal.vue'; import UpdateApplicationConfirmationModal from './update_application_confirmation_modal.vue';
...@@ -12,7 +11,7 @@ import { APPLICATION_STATUS, ELASTIC_STACK } from '../constants'; ...@@ -12,7 +11,7 @@ import { APPLICATION_STATUS, ELASTIC_STACK } from '../constants';
export default { export default {
components: { components: {
loadingButton, GlButton,
identicon, identicon,
GlLink, GlLink,
GlSprintf, GlSprintf,
...@@ -390,16 +389,18 @@ export default { ...@@ -390,16 +389,18 @@ export default {
</div> </div>
<template v-if="updateAvailable || updateFailed || isUpdating"> <template v-if="updateAvailable || updateFailed || isUpdating">
<template v-if="updatingNeedsConfirmation"> <template v-if="updatingNeedsConfirmation">
<loading-button <gl-button
v-gl-modal-directive="updateModalId" v-gl-modal-directive="updateModalId"
class="btn btn-primary js-cluster-application-update-button mt-2" class="js-cluster-application-update-button mt-2"
variant="info"
category="primary"
:loading="isUpdating" :loading="isUpdating"
:disabled="isUpdating" :disabled="isUpdating"
:label="updateButtonLabel"
data-qa-selector="update_button_with_confirmation" data-qa-selector="update_button_with_confirmation"
:data-qa-application="id" :data-qa-application="id"
/> >
{{ updateButtonLabel }}
</gl-button>
<update-application-confirmation-modal <update-application-confirmation-modal
:application="id" :application="id"
:application-title="title" :application-title="title"
...@@ -407,16 +408,19 @@ export default { ...@@ -407,16 +408,19 @@ export default {
/> />
</template> </template>
<loading-button <gl-button
v-else v-else
class="btn btn-primary js-cluster-application-update-button mt-2" class="js-cluster-application-update-button mt-2"
variant="info"
category="primary"
:loading="isUpdating" :loading="isUpdating"
:disabled="isUpdating" :disabled="isUpdating"
:label="updateButtonLabel"
data-qa-selector="update_button" data-qa-selector="update_button"
:data-qa-application="id" :data-qa-application="id"
@click="updateConfirmed" @click="updateConfirmed"
/> >
{{ updateButtonLabel }}
</gl-button>
</template> </template>
</div> </div>
</div> </div>
...@@ -431,16 +435,18 @@ export default { ...@@ -431,16 +435,18 @@ export default {
}}</a> }}</a>
</div> </div>
<div class="btn-group table-action-buttons"> <div class="btn-group table-action-buttons">
<loading-button <gl-button
v-if="displayInstallButton" v-if="displayInstallButton"
:loading="installButtonLoading" :loading="installButtonLoading"
:disabled="disabled || installButtonDisabled" :disabled="disabled || installButtonDisabled"
:label="installButtonLabel"
class="js-cluster-application-install-button" class="js-cluster-application-install-button"
variant="default"
data-qa-selector="install_button" data-qa-selector="install_button"
:data-qa-application="id" :data-qa-application="id"
@click="installClicked" @click="installClicked"
/> >
{{ installButtonLabel }}
</gl-button>
<uninstall-application-button <uninstall-application-button
v-if="displayUninstallButton" v-if="displayUninstallButton"
v-gl-modal-directive="uninstallModalId" v-gl-modal-directive="uninstallModalId"
......
<script> <script>
import LoadingButton from '~/vue_shared/components/loading_button.vue'; import { GlButton } from '@gitlab/ui';
import { APPLICATION_STATUS } from '~/clusters/constants'; import { APPLICATION_STATUS } from '~/clusters/constants';
import { __ } from '~/locale'; import { __ } from '~/locale';
...@@ -7,7 +7,7 @@ const { UPDATING, UNINSTALLING } = APPLICATION_STATUS; ...@@ -7,7 +7,7 @@ const { UPDATING, UNINSTALLING } = APPLICATION_STATUS;
export default { export default {
components: { components: {
LoadingButton, GlButton,
}, },
props: { props: {
status: { status: {
...@@ -30,5 +30,7 @@ export default { ...@@ -30,5 +30,7 @@ export default {
</script> </script>
<template> <template>
<loading-button :label="label" :disabled="disabled" :loading="loading" /> <gl-button :disabled="disabled" variant="default" :loading="loading">
{{ label }}
</gl-button>
</template> </template>
...@@ -48,7 +48,7 @@ describe('Application Row', () => { ...@@ -48,7 +48,7 @@ describe('Application Row', () => {
describe('Install button', () => { describe('Install button', () => {
const button = () => wrapper.find('.js-cluster-application-install-button'); const button = () => wrapper.find('.js-cluster-application-install-button');
const checkButtonState = (label, loading, disabled) => { const checkButtonState = (label, loading, disabled) => {
expect(button().props('label')).toEqual(label); expect(button().text()).toEqual(label);
expect(button().props('loading')).toEqual(loading); expect(button().props('loading')).toEqual(loading);
expect(button().props('disabled')).toEqual(disabled); expect(button().props('disabled')).toEqual(disabled);
}; };
...@@ -56,7 +56,7 @@ describe('Application Row', () => { ...@@ -56,7 +56,7 @@ describe('Application Row', () => {
it('has indeterminate state on page load', () => { it('has indeterminate state on page load', () => {
mountComponent({ status: null }); mountComponent({ status: null });
expect(button().props('label')).toBeUndefined(); expect(button().text()).toBe('');
}); });
it('has install button', () => { it('has install button', () => {
...@@ -225,7 +225,7 @@ describe('Application Row', () => { ...@@ -225,7 +225,7 @@ describe('Application Row', () => {
mountComponent({ updateAvailable: true }); mountComponent({ updateAvailable: true });
expect(button().exists()).toBe(true); expect(button().exists()).toBe(true);
expect(button().props('label')).toContain('Update'); expect(button().text()).toContain('Update');
}); });
it('has enabled "Retry update" when update process fails', () => { it('has enabled "Retry update" when update process fails', () => {
...@@ -235,14 +235,14 @@ describe('Application Row', () => { ...@@ -235,14 +235,14 @@ describe('Application Row', () => {
}); });
expect(button().exists()).toBe(true); expect(button().exists()).toBe(true);
expect(button().props('label')).toContain('Retry update'); expect(button().text()).toContain('Retry update');
}); });
it('has disabled "Updating" when APPLICATION_STATUS.UPDATING', () => { it('has disabled "Updating" when APPLICATION_STATUS.UPDATING', () => {
mountComponent({ status: APPLICATION_STATUS.UPDATING }); mountComponent({ status: APPLICATION_STATUS.UPDATING });
expect(button().exists()).toBe(true); expect(button().exists()).toBe(true);
expect(button().props('label')).toContain('Updating'); expect(button().text()).toContain('Updating');
}); });
it('clicking update button emits event', () => { it('clicking update button emits event', () => {
......
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { GlButton } from '@gitlab/ui';
import UninstallApplicationButton from '~/clusters/components/uninstall_application_button.vue'; import UninstallApplicationButton from '~/clusters/components/uninstall_application_button.vue';
import LoadingButton from '~/vue_shared/components/loading_button.vue';
import { APPLICATION_STATUS } from '~/clusters/constants'; import { APPLICATION_STATUS } from '~/clusters/constants';
const { INSTALLED, UPDATING, UNINSTALLING } = APPLICATION_STATUS; const { INSTALLED, UPDATING, UNINSTALLING } = APPLICATION_STATUS;
...@@ -19,14 +19,21 @@ describe('UninstallApplicationButton', () => { ...@@ -19,14 +19,21 @@ describe('UninstallApplicationButton', () => {
}); });
describe.each` describe.each`
status | loading | disabled | label status | loading | disabled | text
${INSTALLED} | ${false} | ${false} | ${'Uninstall'} ${INSTALLED} | ${false} | ${false} | ${'Uninstall'}
${UPDATING} | ${false} | ${true} | ${'Uninstall'} ${UPDATING} | ${false} | ${true} | ${'Uninstall'}
${UNINSTALLING} | ${true} | ${true} | ${'Uninstalling'} ${UNINSTALLING} | ${true} | ${true} | ${'Uninstalling'}
`('when app status is $status', ({ loading, disabled, status, label }) => { `('when app status is $status', ({ loading, disabled, status, text }) => {
it(`renders a loading=${loading}, disabled=${disabled} button with label="${label}"`, () => { beforeAll(() => {
createComponent({ status }); createComponent({ status });
expect(wrapper.find(LoadingButton).props()).toMatchObject({ loading, disabled, label }); });
it(`renders a button with loading=${loading} and disabled=${disabled}`, () => {
expect(wrapper.find(GlButton).props()).toMatchObject({ loading, disabled });
});
it(`renders a button with text="${text}"`, () => {
expect(wrapper.find(GlButton).text()).toBe(text);
}); });
}); });
}); });
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