Commit d0ade1af authored by Filipa Lacerda's avatar Filipa Lacerda

Extracts collapsible logic to a component

Allows to render collapsible nested sections
 Please enter the commit message for your changes. Lines starting
parent ab690af8
<script>
import LogLine from './line.vue';
import LogLineHeader from './line_header.vue';
export default {
name: 'CollpasibleLogSection',
components: {
LogLine,
LogLineHeader,
},
props: {
section: {
type: Object,
required: true,
},
traceEndpoint: {
type: String,
required: true,
},
},
methods: {
handleOnClickCollapsibleLine(section) {
this.$emit('handleOnClickCollapsibleLine', section);
},
},
};
</script>
<template>
<div>
<log-line-header
:line="section.line"
:duration="section.line.section_duration"
:path="traceEndpoint"
:is-closed="section.isClosed"
@toggleLine="handleOnClickCollapsibleLine(section)"
/>
<template v-if="!section.isClosed">
<template v-for="line in section.lines">
<collpasible-log-section
v-if="line.isHeader"
:key="`collapsible-nested-${line.offset}`"
:section="line"
:trace-endpoint="traceEndpoint"
@handleOnClickCollapsibleLine="handleOnClickCollapsibleLine"
/>
<log-line v-else :key="line.offset" :line="line" :path="traceEndpoint" />
</template>
</template>
</div>
</template>
<script>
import { mapState, mapActions } from 'vuex';
import CollpasibleLogSection from './collapsible_section.vue';
import LogLine from './line.vue';
import LogLineHeader from './line_header.vue';
export default {
components: {
CollpasibleLogSection,
LogLine,
LogLineHeader,
},
computed: {
...mapState(['traceEndpoint', 'trace', 'isTraceComplete']),
......@@ -22,24 +22,13 @@ export default {
<template>
<code class="job-log d-block">
<template v-for="(section, index) in trace">
<template v-if="section.isHeader">
<log-line-header
:key="`collapsible-${index}`"
:line="section.line"
:duration="section.section_duration"
:path="traceEndpoint"
:is-closed="section.isClosed"
@toggleLine="handleOnClickCollapsibleLine(section)"
/>
<template v-if="!section.isClosed">
<log-line
v-for="line in section.lines"
:key="line.offset"
:line="line"
:path="traceEndpoint"
/>
</template>
</template>
<collpasible-log-section
v-if="section.isHeader"
:key="`collapsible-${index}`"
:section="section"
:trace-endpoint="traceEndpoint"
@handleOnClickCollapsibleLine="handleOnClickCollapsibleLine"
/>
<log-line v-else :key="section.offset" :line="section" :path="traceEndpoint" />
</template>
......
......@@ -28,6 +28,7 @@
@import 'framework/issue_box';
@import 'framework/lists';
@import 'framework/logo';
@import 'framework/job_log';
@import 'framework/markdown_area';
@import 'framework/media_object';
@import 'framework/modal';
......
import { mount } from '@vue/test-utils';
import CollpasibleSection from '~/jobs/components/log/collapsible_section.vue';
import { nestedSectionOpened, nestedSectionClosed } from './mock_data';
describe('Job Log Collapsible Section', () => {
let wrapper;
const traceEndpoint = 'jobs/335';
const createComponent = (props = {}) => {
wrapper = mount(CollpasibleSection, {
sync: true,
propsData: {
...props,
},
});
};
beforeEach(() => {});
afterEach(() => {
wrapper.destroy();
});
describe('with closed nested section', () => {
beforeEach(() => {
createComponent({
section: nestedSectionClosed,
traceEndpoint,
});
});
it('renders clickable header line', () => {
expect(wrapper.find('.collapsible-line').attributes('role')).toBe('button');
});
});
describe('with opened nested section', () => {
beforeEach(() => {
createComponent({
section: nestedSectionOpened,
traceEndpoint,
});
});
it('renders all sections opened', () => {
expect(wrapper.findAll('.collapsible-line').length).toBe(2);
});
});
it('emits handleOnClickCollapsibleLine on click', () => {
createComponent({
section: nestedSectionOpened,
traceEndpoint,
});
wrapper.find('.collapsible-line').trigger('click');
expect(wrapper.emitted('handleOnClickCollapsibleLine').length).toBe(1);
});
});
......@@ -150,3 +150,73 @@ export const collapsibleTraceIncremental = [
sections: ['section'],
},
];
export const nestedSectionClosed = {
offset: 5,
section_header: true,
isHeader: true,
isClosed: true,
line: {
content: [{ text: 'foo' }],
sections: ['prepare-script'],
lineNumber: 1,
},
section_duration: '00:03',
lines: [
{
section_header: true,
section_duration: '00:02',
isHeader: true,
isClosed: true,
line: {
offset: 52,
content: [{ text: 'bar' }],
sections: ['prepare-script', 'prepare-script-nested'],
lineNumber: 2,
},
lines: [
{
offset: 80,
content: [{ text: 'this is a collapsible nested section' }],
sections: ['prepare-script', 'prepare-script-nested'],
lineNumber: 3,
},
],
},
],
};
export const nestedSectionOpened = {
offset: 5,
section_header: true,
isHeader: true,
isClosed: false,
line: {
content: [{ text: 'foo' }],
sections: ['prepare-script'],
lineNumber: 1,
},
section_duration: '00:03',
lines: [
{
section_header: true,
section_duration: '00:02',
isHeader: true,
isClosed: false,
line: {
offset: 52,
content: [{ text: 'bar' }],
sections: ['prepare-script', 'prepare-script-nested'],
lineNumber: 2,
},
lines: [
{
offset: 80,
content: [{ text: 'this is a collapsible nested section' }],
sections: ['prepare-script', 'prepare-script-nested'],
lineNumber: 3,
},
],
},
],
};
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