Commit 30dfe711 authored by Kushal Pandya's avatar Kushal Pandya

Update template, move shared code to SectionMixin

parent 5e8d48d8
<script> <script>
import eventHub from '../event_hub'; import eventHub from '../event_hub';
import { SCROLL_BAR_SIZE } from '../constants'; import SectionMixin from '../mixins/section_mixin';
import timelineHeaderItem from './timeline_header_item.vue'; import timelineHeaderItem from './timeline_header_item.vue';
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
components: { components: {
timelineHeaderItem, timelineHeaderItem,
}, },
mixins: [
SectionMixin,
],
props: { props: {
epics: { epics: {
type: Array, type: Array,
...@@ -22,20 +25,16 @@ ...@@ -22,20 +25,16 @@
type: Number, type: Number,
required: true, required: true,
}, },
listScrollable: {
type: Boolean,
required: true,
},
}, },
data() { data() {
return { return {
scrolledHeaderClass: '', scrolledHeaderClass: '',
}; };
}, },
computed: {
calcShellWidth() {
return this.shellWidth - SCROLL_BAR_SIZE;
},
theadStyles() {
return `width: ${this.calcShellWidth}px;`;
},
},
mounted() { mounted() {
eventHub.$on('epicsListScrolled', this.handleEpicsListScroll); eventHub.$on('epicsListScrolled', this.handleEpicsListScroll);
}, },
...@@ -43,30 +42,28 @@ ...@@ -43,30 +42,28 @@
eventHub.$off('epicsListScrolled', this.handleEpicsListScroll); eventHub.$off('epicsListScrolled', this.handleEpicsListScroll);
}, },
methods: { methods: {
handleEpicsListScroll(scrollTop) { handleEpicsListScroll({ scrollTop }) {
// Add class only when epics list is scrolled at 1% the height of header // Add class only when epics list is scrolled at 1% the height of header
this.scrolledHeaderClass = (scrollTop > this.$el.clientHeight / 100) ? 'scrolled-ahead' : ''; this.scrolledHeaderClass = (scrollTop > this.$el.clientHeight / 100) ? 'scroll-top-shadow' : '';
}, },
}, },
}; };
</script> </script>
<template> <template>
<thead <div
class="roadmap-timeline-section" class="roadmap-timeline-section clearfix"
:class="scrolledHeaderClass" :class="scrolledHeaderClass"
:style="theadStyles" :style="sectionContainerStyles"
> >
<tr> <span class="timeline-header-blank"></span>
<th class="timeline-header-blank"></th>
<timeline-header-item <timeline-header-item
v-for="(timeframeItem, index) in timeframe" v-for="(timeframeItem, index) in timeframe"
:key="index" :key="index"
:timeframe-index="index" :timeframe-index="index"
:timeframe-item="timeframeItem" :timeframe-item="timeframeItem"
:timeframe="timeframe" :timeframe="timeframe"
:shell-width="calcShellWidth" :item-width="sectionItemWidth"
/> />
</tr> </div>
</thead>
</template> </template>
...@@ -10,6 +10,7 @@ const createComponent = ({ ...@@ -10,6 +10,7 @@ const createComponent = ({
epics = [mockEpic], epics = [mockEpic],
timeframe = mockTimeframe, timeframe = mockTimeframe,
shellWidth = mockShellWidth, shellWidth = mockShellWidth,
listScrollable = false,
}) => { }) => {
const Component = Vue.extend(roadmapTimelineSectionComponent); const Component = Vue.extend(roadmapTimelineSectionComponent);
...@@ -17,6 +18,7 @@ const createComponent = ({ ...@@ -17,6 +18,7 @@ const createComponent = ({
epics, epics,
timeframe, timeframe,
shellWidth, shellWidth,
listScrollable,
}); });
}; };
...@@ -37,33 +39,16 @@ describe('RoadmapTimelineSectionComponent', () => { ...@@ -37,33 +39,16 @@ describe('RoadmapTimelineSectionComponent', () => {
}); });
}); });
describe('computed', () => {
describe('calcShellWidth', () => {
it('returns shellWidth by deducting Scrollbar size', () => {
// shellWidth is 2000 (as defined above in mockShellWidth)
// SCROLLBAR_SIZE is 15 (as defined in app's constants.js)
// Hence, calcShellWidth = shellWidth - SCROLLBAR_SIZE
expect(vm.calcShellWidth).toBe(1985);
});
});
describe('theadStyles', () => {
it('returns style string for thead based on calcShellWidth', () => {
expect(vm.theadStyles).toBe('width: 1985px;');
});
});
});
describe('methods', () => { describe('methods', () => {
describe('handleEpicsListScroll', () => { describe('handleEpicsListScroll', () => {
it('sets `scrolled-ahead` class on thead element based on provided scrollTop value', () => { it('sets `scrolled-ahead` class on thead element based on provided scrollTop value', () => {
// vm.$el.clientHeight is 0 during tests // vm.$el.clientHeight is 0 during tests
// hence any value greater than 0 should // hence any value greater than 0 should
// update scrolledHeaderClass prop // update scrolledHeaderClass prop
vm.handleEpicsListScroll(1); vm.handleEpicsListScroll({ scrollTop: 1 });
expect(vm.scrolledHeaderClass).toBe('scrolled-ahead'); expect(vm.scrolledHeaderClass).toBe('scroll-top-shadow');
vm.handleEpicsListScroll(0); vm.handleEpicsListScroll({ scrollTop: 0 });
expect(vm.scrolledHeaderClass).toBe(''); expect(vm.scrolledHeaderClass).toBe('');
}); });
}); });
......
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