Commit 16540aba authored by Michael Lunøe's avatar Michael Lunøe

Merge branch '334655-vue-shared-settings-block' into 'master'

Vue shared comonents settings block h4 expand

See merge request gitlab-org/gitlab!68707
parents 0e700b4f af66f1a6
...@@ -29,14 +29,29 @@ export default { ...@@ -29,14 +29,29 @@ export default {
return this.expanded ? __('Collapse') : __('Expand'); return this.expanded ? __('Collapse') : __('Expand');
}, },
}, },
methods: {
toggleSectionExpanded() {
this.sectionExpanded = !this.sectionExpanded;
},
},
}; };
</script> </script>
<template> <template>
<section class="settings" :class="{ 'no-animate': !slideAnimated, expanded }"> <section class="settings" :class="{ 'no-animate': !slideAnimated, expanded }">
<div class="settings-header"> <div class="settings-header">
<h4><slot name="title"></slot></h4> <h4>
<gl-button @click="sectionExpanded = !sectionExpanded"> <span
role="button"
tabindex="0"
class="gl-cursor-pointer"
data-testid="section-title"
@click="toggleSectionExpanded"
>
<slot name="title"></slot>
</span>
</h4>
<gl-button @click="toggleSectionExpanded">
{{ toggleText }} {{ toggleText }}
</gl-button> </gl-button>
<p> <p>
......
...@@ -8,9 +8,16 @@ exports[`Settings Block renders the correct markup 1`] = ` ...@@ -8,9 +8,16 @@ exports[`Settings Block renders the correct markup 1`] = `
class="settings-header" class="settings-header"
> >
<h4> <h4>
<div <span
data-testid="title-slot" class="gl-cursor-pointer"
/> data-testid="section-title"
role="button"
tabindex="0"
>
<div
data-testid="title-slot"
/>
</span>
</h4> </h4>
<gl-button-stub <gl-button-stub
......
...@@ -18,13 +18,13 @@ describe('Settings Block', () => { ...@@ -18,13 +18,13 @@ describe('Settings Block', () => {
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
wrapper = null;
}); });
const findDefaultSlot = () => wrapper.find('[data-testid="default-slot"]'); const findDefaultSlot = () => wrapper.find('[data-testid="default-slot"]');
const findTitleSlot = () => wrapper.find('[data-testid="title-slot"]'); const findTitleSlot = () => wrapper.find('[data-testid="title-slot"]');
const findDescriptionSlot = () => wrapper.find('[data-testid="description-slot"]'); const findDescriptionSlot = () => wrapper.find('[data-testid="description-slot"]');
const findExpandButton = () => wrapper.find(GlButton); const findExpandButton = () => wrapper.findComponent(GlButton);
const findSectionTitle = () => wrapper.find('[data-testid="section-title"]');
it('renders the correct markup', () => { it('renders the correct markup', () => {
mountComponent(); mountComponent();
...@@ -90,6 +90,18 @@ describe('Settings Block', () => { ...@@ -90,6 +90,18 @@ describe('Settings Block', () => {
expect(findExpandButton().text()).toBe('Collapse'); expect(findExpandButton().text()).toBe('Collapse');
}); });
it('adds expanded class when the section title is clicked', async () => {
mountComponent();
expect(wrapper.classes('expanded')).toBe(false);
expect(findExpandButton().text()).toBe('Expand');
await findSectionTitle().trigger('click');
expect(wrapper.classes('expanded')).toBe(true);
expect(findExpandButton().text()).toBe('Collapse');
});
it('is expanded when `defaultExpanded` is true no matter what', async () => { it('is expanded when `defaultExpanded` is true no matter what', async () => {
mountComponent({ defaultExpanded: true }); mountComponent({ defaultExpanded: true });
......
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