Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
b2f7c2e0
Commit
b2f7c2e0
authored
Jun 07, 2018
by
Kushal Pandya
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Roadmap WeeksHeaderItem Component
parent
1b8a2fca
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
191 additions
and
0 deletions
+191
-0
ee/app/assets/javascripts/roadmap/components/preset_weeks/weeks_header_item.vue
...pts/roadmap/components/preset_weeks/weeks_header_item.vue
+81
-0
spec/javascripts/roadmap/components/preset_weeks/weeks_header_item_spec.js
...roadmap/components/preset_weeks/weeks_header_item_spec.js
+110
-0
No files found.
ee/app/assets/javascripts/roadmap/components/preset_weeks/weeks_header_item.vue
0 → 100644
View file @
b2f7c2e0
<
script
>
import
{
monthInWords
}
from
'
~/lib/utils/datetime_utility
'
;
import
WeeksHeaderSubItem
from
'
./weeks_header_sub_item.vue
'
;
export
default
{
components
:
{
WeeksHeaderSubItem
,
},
props
:
{
timeframeIndex
:
{
type
:
Number
,
required
:
true
,
},
timeframeItem
:
{
type
:
Date
,
required
:
true
,
},
timeframe
:
{
type
:
Array
,
required
:
true
,
},
itemWidth
:
{
type
:
Number
,
required
:
true
,
},
},
data
()
{
const
currentDate
=
new
Date
();
currentDate
.
setHours
(
0
,
0
,
0
,
0
);
const
lastDayOfCurrentWeek
=
new
Date
(
this
.
timeframeItem
.
getTime
());
lastDayOfCurrentWeek
.
setDate
(
lastDayOfCurrentWeek
.
getDate
()
+
7
);
return
{
currentDate
,
lastDayOfCurrentWeek
,
};
},
computed
:
{
itemStyles
()
{
return
{
width
:
`
${
this
.
itemWidth
}
px`
,
};
},
timelineHeaderLabel
()
{
if
(
this
.
timeframeIndex
===
0
)
{
return
`
${
this
.
timeframeItem
.
getFullYear
()}
${
monthInWords
(
this
.
timeframeItem
,
true
)}
${
this
.
timeframeItem
.
getDate
()}
`
;
}
return
`
${
monthInWords
(
this
.
timeframeItem
,
true
)}
${
this
.
timeframeItem
.
getDate
()}
`
;
},
timelineHeaderClass
()
{
if
(
this
.
currentDate
>=
this
.
timeframeItem
&&
this
.
currentDate
<=
this
.
lastDayOfCurrentWeek
)
{
return
'
label-dark label-bold
'
;
}
else
if
(
this
.
currentDate
<
this
.
lastDayOfCurrentWeek
)
{
return
'
label-dark
'
;
}
return
''
;
},
},
};
</
script
>
<
template
>
<span
class=
"timeline-header-item"
:style=
"itemStyles"
>
<div
class=
"item-label"
:class=
"timelineHeaderClass"
>
{{
timelineHeaderLabel
}}
</div>
<weeks-header-sub-item
:timeframe-item=
"timeframeItem"
:current-date=
"currentDate"
/>
</span>
</
template
>
spec/javascripts/roadmap/components/preset_weeks/weeks_header_item_spec.js
0 → 100644
View file @
b2f7c2e0
import
Vue
from
'
vue
'
;
import
WeeksHeaderItemComponent
from
'
ee/roadmap/components/preset_weeks/weeks_header_item.vue
'
;
import
mountComponent
from
'
spec/helpers/vue_mount_component_helper
'
;
import
{
mockTimeframeWeeks
,
mockShellWidth
,
mockItemWidth
}
from
'
../../mock_data
'
;
const
mockTimeframeIndex
=
0
;
const
createComponent
=
({
timeframeIndex
=
mockTimeframeIndex
,
timeframeItem
=
mockTimeframeWeeks
[
mockTimeframeIndex
],
timeframe
=
mockTimeframeWeeks
,
shellWidth
=
mockShellWidth
,
itemWidth
=
mockItemWidth
,
})
=>
{
const
Component
=
Vue
.
extend
(
WeeksHeaderItemComponent
);
return
mountComponent
(
Component
,
{
timeframeIndex
,
timeframeItem
,
timeframe
,
shellWidth
,
itemWidth
,
});
};
describe
(
'
WeeksHeaderItemComponent
'
,
()
=>
{
let
vm
;
afterEach
(()
=>
{
vm
.
$destroy
();
});
describe
(
'
data
'
,
()
=>
{
it
(
'
returns default data props
'
,
()
=>
{
vm
=
createComponent
({});
const
currentDate
=
new
Date
();
expect
(
vm
.
currentDate
.
getDate
()).
toBe
(
currentDate
.
getDate
());
expect
(
vm
.
lastDayOfCurrentWeek
.
getDate
()).
toBe
(
mockTimeframeWeeks
[
mockTimeframeIndex
].
getDate
()
+
7
,
);
});
});
describe
(
'
computed
'
,
()
=>
{
describe
(
'
itemStyles
'
,
()
=>
{
it
(
'
returns style object for container element based on value of `itemWidth` prop
'
,
()
=>
{
vm
=
createComponent
({});
expect
(
vm
.
itemStyles
.
width
).
toBe
(
'
180px
'
);
});
});
describe
(
'
timelineHeaderLabel
'
,
()
=>
{
it
(
'
returns string containing Year, Month and Date for current timeline header item
'
,
()
=>
{
vm
=
createComponent
({});
expect
(
vm
.
timelineHeaderLabel
).
toBe
(
'
2017 Dec 24
'
);
});
it
(
'
returns string containing only Month and Date for current timeline header item when previous header contained Year
'
,
()
=>
{
vm
=
createComponent
({
timeframeIndex
:
mockTimeframeIndex
+
1
,
timeframeItem
:
mockTimeframeWeeks
[
mockTimeframeIndex
+
1
],
});
expect
(
vm
.
timelineHeaderLabel
).
toBe
(
'
Dec 31
'
);
});
});
describe
(
'
timelineHeaderClass
'
,
()
=>
{
it
(
'
returns empty string when timeframeItem week is less than current week
'
,
()
=>
{
vm
=
createComponent
({});
expect
(
vm
.
timelineHeaderClass
).
toBe
(
''
);
});
it
(
'
returns string containing `label-dark label-bold` when current week is same as timeframeItem week
'
,
()
=>
{
vm
=
createComponent
({});
vm
.
currentDate
=
mockTimeframeWeeks
[
mockTimeframeIndex
];
expect
(
vm
.
timelineHeaderClass
).
toBe
(
'
label-dark label-bold
'
);
});
it
(
'
returns string containing `label-dark` when current week is less than timeframeItem week
'
,
()
=>
{
const
timeframeIndex
=
2
;
const
timeframeItem
=
mockTimeframeWeeks
[
timeframeIndex
];
vm
=
createComponent
({
timeframeIndex
,
timeframeItem
,
});
vm
.
currentDate
=
mockTimeframeWeeks
[
0
];
expect
(
vm
.
timelineHeaderClass
).
toBe
(
'
label-dark
'
);
});
});
});
describe
(
'
template
'
,
()
=>
{
beforeEach
(()
=>
{
vm
=
createComponent
({});
});
it
(
'
renders component container element with class `timeline-header-item`
'
,
()
=>
{
expect
(
vm
.
$el
.
classList
.
contains
(
'
timeline-header-item
'
)).
toBeTruthy
();
});
it
(
'
renders item label element class `item-label` and value as `timelineHeaderLabel`
'
,
()
=>
{
const
itemLabelEl
=
vm
.
$el
.
querySelector
(
'
.item-label
'
);
expect
(
itemLabelEl
).
not
.
toBeNull
();
expect
(
itemLabelEl
.
innerText
.
trim
()).
toBe
(
'
2017 Dec 24
'
);
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment