Commit ca258a57 authored by Vitaly Slobodin's avatar Vitaly Slobodin

Emit events in Vue with single arg instead of multiple

parent 0f763bf8
...@@ -106,13 +106,13 @@ export default { ...@@ -106,13 +106,13 @@ export default {
* 3. In case of prepending timeframe, * 3. In case of prepending timeframe,
* reset scroll-position (due to DOM prepend). * reset scroll-position (due to DOM prepend).
*/ */
processExtendedTimeline({ extendType = EXTEND_AS.PREPEND, roadmapTimelineEl, itemsCount = 0 }) { processExtendedTimeline({ extendAs = EXTEND_AS.PREPEND, roadmapTimelineEl, itemsCount = 0 }) {
// Re-render timeline bars with updated timeline // Re-render timeline bars with updated timeline
eventHub.$emit('refreshTimeline', { eventHub.$emit('refreshTimeline', {
todayBarReady: extendType === EXTEND_AS.PREPEND, todayBarReady: extendAs === EXTEND_AS.PREPEND,
}); });
if (extendType === EXTEND_AS.PREPEND) { if (extendAs === EXTEND_AS.PREPEND) {
// When DOM is prepended with elements // When DOM is prepended with elements
// we compensate the scrolling for added elements' width // we compensate the scrolling for added elements' width
roadmapTimelineEl.parentElement.scrollBy( roadmapTimelineEl.parentElement.scrollBy(
...@@ -121,8 +121,8 @@ export default { ...@@ -121,8 +121,8 @@ export default {
); );
} }
}, },
handleScrollToExtend(roadmapTimelineEl, extendType = EXTEND_AS.PREPEND) { handleScrollToExtend({ el: roadmapTimelineEl, extendAs = EXTEND_AS.PREPEND }) {
this.extendTimeframe({ extendAs: extendType }); this.extendTimeframe({ extendAs });
this.refreshEpicDates(); this.refreshEpicDates();
this.refreshMilestoneDates(); this.refreshMilestoneDates();
...@@ -135,7 +135,7 @@ export default { ...@@ -135,7 +135,7 @@ export default {
// Re-render timeline bars with updated timeline // Re-render timeline bars with updated timeline
this.processExtendedTimeline({ this.processExtendedTimeline({
itemsCount: this.extendedTimeframe ? this.extendedTimeframe.length : 0, itemsCount: this.extendedTimeframe ? this.extendedTimeframe.length : 0,
extendType, extendAs,
roadmapTimelineEl, roadmapTimelineEl,
}); });
}); });
...@@ -164,9 +164,8 @@ export default { ...@@ -164,9 +164,8 @@ export default {
primary-button-link="https://docs.gitlab.com/ee/user/group/roadmap/" primary-button-link="https://docs.gitlab.com/ee/user/group/roadmap/"
data-testid="epics_limit_callout" data-testid="epics_limit_callout"
@dismiss="dismissTooManyEpicsWarning" @dismiss="dismissTooManyEpicsWarning"
>{{ $options.i18n.warningBody }}</gl-alert
> >
{{ $options.i18n.warningBody }}
</gl-alert>
<div :class="{ 'overflow-reset': epicsFetchResultEmpty }" class="roadmap-container"> <div :class="{ 'overflow-reset': epicsFetchResultEmpty }" class="roadmap-container">
<gl-loading-icon v-if="epicsFetchInProgress" class="gl-mt-5" size="md" /> <gl-loading-icon v-if="epicsFetchInProgress" class="gl-mt-5" size="md" />
<epics-list-empty <epics-list-empty
......
...@@ -76,10 +76,16 @@ export default { ...@@ -76,10 +76,16 @@ export default {
// If timeline was scrolled to start // If timeline was scrolled to start
if (isInViewport(timelineEdgeStartEl, { left: this.timeframeStartOffset })) { if (isInViewport(timelineEdgeStartEl, { left: this.timeframeStartOffset })) {
this.$emit('onScrollToStart', this.$refs.roadmapTimeline.$el, EXTEND_AS.PREPEND); this.$emit('onScrollToStart', {
el: this.$refs.roadmapTimeline.$el,
extendAs: EXTEND_AS.PREPEND,
});
} else if (isInViewport(timelineEdgeEndEl)) { } else if (isInViewport(timelineEdgeEndEl)) {
// If timeline was scrolled to end // If timeline was scrolled to end
this.$emit('onScrollToEnd', this.$refs.roadmapTimeline.$el, EXTEND_AS.APPEND); this.$emit('onScrollToEnd', {
el: this.$refs.roadmapTimeline.$el,
extendAs: EXTEND_AS.APPEND,
});
} }
eventHub.$emit('epicsListScrolled', { scrollTop, scrollLeft, clientHeight, scrollHeight }); eventHub.$emit('epicsListScrolled', { scrollTop, scrollLeft, clientHeight, scrollHeight });
......
import { GlAlert, GlLoadingIcon } from '@gitlab/ui'; import { GlAlert, GlLoadingIcon } from '@gitlab/ui';
import { mount, shallowMount, createLocalVue } from '@vue/test-utils'; import { mount, shallowMount, createLocalVue } from '@vue/test-utils';
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
import { nextTick } from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
import EpicsListEmpty from 'ee/roadmap/components/epics_list_empty.vue'; import EpicsListEmpty from 'ee/roadmap/components/epics_list_empty.vue';
import RoadmapApp from 'ee/roadmap/components/roadmap_app.vue'; import RoadmapApp from 'ee/roadmap/components/roadmap_app.vue';
...@@ -212,27 +213,26 @@ describe('RoadmapApp', () => { ...@@ -212,27 +213,26 @@ describe('RoadmapApp', () => {
const extendType = EXTEND_AS.PREPEND; const extendType = EXTEND_AS.PREPEND;
wrapper.vm.handleScrollToExtend(roadmapTimelineEl, extendType); wrapper.vm.handleScrollToExtend({ el: roadmapTimelineEl, extendAs: extendType });
expect(wrapper.vm.extendTimeframe).toHaveBeenCalledWith({ extendAs: extendType }); expect(wrapper.vm.extendTimeframe).toHaveBeenCalledWith({ extendAs: extendType });
expect(wrapper.vm.refreshEpicDates).toHaveBeenCalled(); expect(wrapper.vm.refreshEpicDates).toHaveBeenCalled();
expect(wrapper.vm.refreshMilestoneDates).toHaveBeenCalled(); expect(wrapper.vm.refreshMilestoneDates).toHaveBeenCalled();
}); });
it('calls `fetchEpicsForTimeframe` with extended timeframe array', () => { it('calls `fetchEpicsForTimeframe` with extended timeframe array', async () => {
jest.spyOn(wrapper.vm, 'fetchEpicsForTimeframe').mockResolvedValue(); jest.spyOn(wrapper.vm, 'fetchEpicsForTimeframe').mockResolvedValue();
const extendType = EXTEND_AS.PREPEND; const extendType = EXTEND_AS.PREPEND;
wrapper.vm.handleScrollToExtend(roadmapTimelineEl, extendType); wrapper.vm.handleScrollToExtend({ el: roadmapTimelineEl, extendAs: extendType });
return wrapper.vm.$nextTick(() => { await nextTick();
expect(wrapper.vm.fetchEpicsForTimeframe).toHaveBeenCalledWith( expect(wrapper.vm.fetchEpicsForTimeframe).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
timeframe: wrapper.vm.extendedTimeframe, timeframe: wrapper.vm.extendedTimeframe,
}), }),
); );
});
}); });
}); });
......
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