Commit 571b56cf authored by Kushal Pandya's avatar Kushal Pandya

Update template, cleanup methods

parent 30dfe711
<script> <script>
import { monthInWords } from '~/lib/utils/datetime_utility'; import { monthInWords } from '~/lib/utils/datetime_utility';
import { EPIC_DETAILS_CELL_WIDTH, TIMELINE_CELL_MIN_WIDTH } from '../constants';
import timelineHeaderSubItem from './timeline_header_sub_item.vue'; import timelineHeaderSubItem from './timeline_header_sub_item.vue';
export default { export default {
...@@ -22,7 +20,7 @@ ...@@ -22,7 +20,7 @@
type: Array, type: Array,
required: true, required: true,
}, },
shellWidth: { itemWidth: {
type: Number, type: Number,
required: true, required: true,
}, },
...@@ -36,22 +34,10 @@ ...@@ -36,22 +34,10 @@
}; };
}, },
computed: { computed: {
thStyles() { itemStyles() {
const timeframeLength = this.timeframe.length; return {
width: `${this.itemWidth}px`,
// Calculate minimum width for single cell };
// based on total number of months in current timeframe
// and available shellWidth
const minWidth =
Math.ceil((this.shellWidth - EPIC_DETAILS_CELL_WIDTH) / timeframeLength);
// When shellWidth is too low, we need to obey global
// minimum cell width.
if (minWidth < TIMELINE_CELL_MIN_WIDTH) {
return `min-width: ${TIMELINE_CELL_MIN_WIDTH}px;`;
}
return `min-width: ${minWidth}px;`;
}, },
timelineHeaderLabel() { timelineHeaderLabel() {
const year = this.timeframeItem.getFullYear(); const year = this.timeframeItem.getFullYear();
...@@ -97,9 +83,9 @@ ...@@ -97,9 +83,9 @@
</script> </script>
<template> <template>
<th <span
class="timeline-header-item" class="timeline-header-item"
:style="thStyles" :style="itemStyles"
> >
<div <div
class="item-label" class="item-label"
...@@ -111,5 +97,5 @@ ...@@ -111,5 +97,5 @@
:timeframe-item="timeframeItem" :timeframe-item="timeframeItem"
:current-date="currentDate" :current-date="currentDate"
/> />
</th> </span>
</template> </template>
import Vue from 'vue'; import Vue from 'vue';
import timelineHeaderItemComponent from 'ee/roadmap/components/timeline_header_item.vue'; import timelineHeaderItemComponent from 'ee/roadmap/components/timeline_header_item.vue';
import { TIMELINE_CELL_MIN_WIDTH } from 'ee/roadmap/constants';
import mountComponent from 'spec/helpers/vue_mount_component_helper'; import mountComponent from 'spec/helpers/vue_mount_component_helper';
import { mockTimeframe, mockShellWidth } from '../mock_data'; import { mockTimeframe, mockShellWidth, mockItemWidth } from '../mock_data';
const mockTimeframeIndex = 0; const mockTimeframeIndex = 0;
...@@ -13,6 +12,7 @@ const createComponent = ({ ...@@ -13,6 +12,7 @@ const createComponent = ({
timeframeItem = mockTimeframe[mockTimeframeIndex], timeframeItem = mockTimeframe[mockTimeframeIndex],
timeframe = mockTimeframe, timeframe = mockTimeframe,
shellWidth = mockShellWidth, shellWidth = mockShellWidth,
itemWidth = mockItemWidth,
}) => { }) => {
const Component = Vue.extend(timelineHeaderItemComponent); const Component = Vue.extend(timelineHeaderItemComponent);
...@@ -21,6 +21,7 @@ const createComponent = ({ ...@@ -21,6 +21,7 @@ const createComponent = ({
timeframeItem, timeframeItem,
timeframe, timeframe,
shellWidth, shellWidth,
itemWidth,
}); });
}; };
...@@ -42,15 +43,10 @@ describe('TimelineHeaderItemComponent', () => { ...@@ -42,15 +43,10 @@ describe('TimelineHeaderItemComponent', () => {
}); });
describe('computed', () => { describe('computed', () => {
describe('thStyles', () => { describe('itemStyles', () => {
it('returns style string for th element based on shellWidth, timeframe length and Epic details cell width', () => { it('returns style object for container element based on value of `itemWidth` prop', () => {
vm = createComponent({}); vm = createComponent({});
expect(vm.thStyles).toBe('min-width: 280px;'); expect(vm.itemStyles.width).toBe('180px');
});
it('returns style string for th element with minimum permissible width when calculated width is lower defined minimum width', () => {
vm = createComponent({ shellWidth: 1000 });
expect(vm.thStyles).toBe(`min-width: ${TIMELINE_CELL_MIN_WIDTH}px;`);
}); });
}); });
......
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