Commit 31b71252 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '333236-fix-collapsing-card-quirck' into 'master'

Fix card jumping content on collapse

See merge request gitlab-org/gitlab!66562
parents 85ed1494 f244d7b6
...@@ -70,6 +70,7 @@ export default { ...@@ -70,6 +70,7 @@ export default {
data() { data() {
return { return {
isPolicyVisible: this.index === 0, isPolicyVisible: this.index === 0,
bodyClass: '',
}; };
}, },
computed: { computed: {
...@@ -94,7 +95,7 @@ export default { ...@@ -94,7 +95,7 @@ export default {
<gl-card <gl-card
class="gl-mt-5" class="gl-mt-5"
:class="{ 'gl-border-bottom-0': !isPolicyVisible }" :class="{ 'gl-border-bottom-0': !isPolicyVisible }"
:body-class="{ 'gl-p-0': !isPolicyVisible }" :body-class="bodyClass"
:header-class="{ 'gl-py-3': true, 'gl-rounded-base': !isPolicyVisible }" :header-class="{ 'gl-py-3': true, 'gl-rounded-base': !isPolicyVisible }"
> >
<template #header> <template #header>
...@@ -129,7 +130,11 @@ export default { ...@@ -129,7 +130,11 @@ export default {
</gl-button-group> </gl-button-group>
</div> </div>
</template> </template>
<gl-collapse :visible="isPolicyVisible"> <gl-collapse
:visible="isPolicyVisible"
@hidden="bodyClass = 'gl-p-0'"
@show="bodyClass = 'gl-p-5'"
>
<p v-if="policy.description" class="gl-text-gray-500 gl-mb-5"> <p v-if="policy.description" class="gl-text-gray-500 gl-mb-5">
{{ policy.description }} {{ policy.description }}
</p> </p>
......
...@@ -125,6 +125,7 @@ export default { ...@@ -125,6 +125,7 @@ export default {
rotations: this.schedule.rotations.nodes, rotations: this.schedule.rotations.nodes,
rotationToUpdate: {}, rotationToUpdate: {},
scheduleVisible: this.scheduleIndex === 0, scheduleVisible: this.scheduleIndex === 0,
bodyClass: this.scheduleIndex === 0 ? 'gl-p-5' : 'gl-p-0',
}; };
}, },
computed: { computed: {
...@@ -236,7 +237,7 @@ export default { ...@@ -236,7 +237,7 @@ export default {
<gl-card <gl-card
class="gl-mt-5" class="gl-mt-5"
:class="{ 'gl-border-bottom-0': !scheduleVisible }" :class="{ 'gl-border-bottom-0': !scheduleVisible }"
:body-class="{ 'gl-p-0': !scheduleVisible }" :body-class="bodyClass"
:header-class="{ 'gl-py-3': true, 'gl-rounded-small': !scheduleVisible }" :header-class="{ 'gl-py-3': true, 'gl-rounded-small': !scheduleVisible }"
> >
<template #header> <template #header>
...@@ -270,7 +271,11 @@ export default { ...@@ -270,7 +271,11 @@ export default {
</gl-button-group> </gl-button-group>
</div> </div>
</template> </template>
<gl-collapse :visible="scheduleVisible"> <gl-collapse
:visible="scheduleVisible"
@hidden="bodyClass = 'gl-p-0'"
@show="bodyClass = 'gl-p-5'"
>
<p class="gl-text-gray-500 gl-mb-5" data-testid="scheduleBody"> <p class="gl-text-gray-500 gl-mb-5" data-testid="scheduleBody">
{{ scheduleInfo }} {{ scheduleInfo }}
</p> </p>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
exports[`EscalationPolicy renders a policy with rules 1`] = ` exports[`EscalationPolicy renders a policy with rules 1`] = `
<div> <div>
<gl-card-stub <gl-card-stub
bodyclass="[object Object]" bodyclass=""
class="gl-mt-5" class="gl-mt-5"
footerclass="" footerclass=""
headerclass="[object Object]" headerclass="[object Object]"
......
import { GlSprintf, GlIcon } from '@gitlab/ui'; import { GlSprintf, GlIcon, GlCard, GlCollapse } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { cloneDeep } from 'lodash'; import { cloneDeep } from 'lodash';
import { nextTick } from 'vue';
import EditEscalationPolicyModal from 'ee/escalation_policies/components/add_edit_escalation_policy_modal.vue'; import EditEscalationPolicyModal from 'ee/escalation_policies/components/add_edit_escalation_policy_modal.vue';
import DeleteEscalationPolicyModal from 'ee/escalation_policies/components/delete_escalation_policy_modal.vue'; import DeleteEscalationPolicyModal from 'ee/escalation_policies/components/delete_escalation_policy_modal.vue';
import EscalationPolicy, { i18n } from 'ee/escalation_policies/components/escalation_policy.vue'; import EscalationPolicy, { i18n } from 'ee/escalation_policies/components/escalation_policy.vue';
...@@ -39,6 +40,8 @@ describe('EscalationPolicy', () => { ...@@ -39,6 +40,8 @@ describe('EscalationPolicy', () => {
const findDeleteModal = () => wrapper.findComponent(DeleteEscalationPolicyModal); const findDeleteModal = () => wrapper.findComponent(DeleteEscalationPolicyModal);
const findEditModal = () => wrapper.findComponent(EditEscalationPolicyModal); const findEditModal = () => wrapper.findComponent(EditEscalationPolicyModal);
const findWarningIcon = () => wrapper.findComponent(GlIcon); const findWarningIcon = () => wrapper.findComponent(GlIcon);
const findGlCard = () => wrapper.findComponent(GlCard);
const findGlCollapse = () => wrapper.findComponent(GlCollapse);
it('renders a policy with rules', () => { it('renders a policy with rules', () => {
expect(wrapper.element).toMatchSnapshot(); expect(wrapper.element).toMatchSnapshot();
...@@ -78,4 +81,18 @@ describe('EscalationPolicy', () => { ...@@ -78,4 +81,18 @@ describe('EscalationPolicy', () => {
}); });
}); });
}); });
describe('Card collapsing behavior', () => {
it('adds content body padding when it is expanded', async () => {
findGlCollapse().vm.$emit('show');
await nextTick();
expect(findGlCard().props('bodyClass')).toBe('gl-p-5');
});
it('removes content body padding when it is collapsed', async () => {
findGlCollapse().vm.$emit('hidden');
await nextTick();
expect(findGlCard().props('bodyClass')).toBe('gl-p-0');
});
});
}); });
...@@ -102,6 +102,7 @@ describe('On-call schedule', () => { ...@@ -102,6 +102,7 @@ describe('On-call schedule', () => {
const findLoadPreviousTimeframeBtn = () => wrapper.findByTestId('previous-timeframe-btn'); const findLoadPreviousTimeframeBtn = () => wrapper.findByTestId('previous-timeframe-btn');
const findLoadNextTimeframeBtn = () => wrapper.findByTestId('next-timeframe-btn'); const findLoadNextTimeframeBtn = () => wrapper.findByTestId('next-timeframe-btn');
const findCollapsible = () => wrapper.findComponent(GlCollapse); const findCollapsible = () => wrapper.findComponent(GlCollapse);
const findGlCard = () => wrapper.findComponent(GlCard);
const findCollapsibleIcon = () => wrapper.findComponent(GlIcon); const findCollapsibleIcon = () => wrapper.findComponent(GlIcon);
it('shows schedule title', () => { it('shows schedule title', () => {
...@@ -256,6 +257,20 @@ describe('On-call schedule', () => { ...@@ -256,6 +257,20 @@ describe('On-call schedule', () => {
}); });
}); });
describe('Card collapsing behavior', () => {
it('adds content body padding when it is expanded', async () => {
findCollapsible().vm.$emit('show');
await nextTick();
expect(findGlCard().props('bodyClass')).toBe('gl-p-5');
});
it('removes content body padding when it is collapsed', async () => {
findCollapsible().vm.$emit('hidden');
await nextTick();
expect(findGlCard().props('bodyClass')).toBe('gl-p-0');
});
});
describe('with Apollo mock', () => { describe('with Apollo mock', () => {
it('renders rotations list from API response when resolved', async () => { it('renders rotations list from API response when resolved', async () => {
createComponent(); createComponent();
......
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