Commit 92287e52 authored by Eulyeon Ko's avatar Eulyeon Ko

Apply frontend maintainer suggestions

parent d069b4d3
...@@ -17,11 +17,7 @@ import { ListType } from '~/boards/constants'; ...@@ -17,11 +17,7 @@ import { ListType } from '~/boards/constants';
import { isScopedLabel } from '~/lib/utils/common_utils'; import { isScopedLabel } from '~/lib/utils/common_utils';
import { __ } from '~/locale'; import { __ } from '~/locale';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { import { groupByIterationCadences, getIterationPeriod } from 'ee/iterations/utils';
groupByIterationCadences,
getIterationTitle,
getIterationPeriod,
} from 'ee/iterations/utils';
import IterationTitle from 'ee/iterations/components/iteration_title.vue'; import IterationTitle from 'ee/iterations/components/iteration_title.vue';
export const listTypeInfo = { export const listTypeInfo = {
...@@ -245,7 +241,6 @@ export default { ...@@ -245,7 +241,6 @@ export default {
} }
}, },
getIterationTitle,
getIterationPeriod, getIterationPeriod,
}, },
}; };
...@@ -333,12 +328,7 @@ export default { ...@@ -333,12 +328,7 @@ export default {
data-testid="new-column-iteration-item" data-testid="new-column-iteration-item"
> >
{{ iteration.period }} {{ iteration.period }}
<iteration-title <iteration-title v-if="iteration.title" :title="iteration.title" />
v-if="getIterationTitle(iteration)"
data-testid="new-column-iteration-title"
>
{{ getIterationTitle(iteration) }}
</iteration-title>
</gl-form-radio> </gl-form-radio>
</gl-dropdown-text> </gl-dropdown-text>
</div> </div>
...@@ -381,12 +371,7 @@ export default { ...@@ -381,12 +371,7 @@ export default {
data-testid="new-column-iteration-item" data-testid="new-column-iteration-item"
> >
{{ getIterationPeriod(item) }} {{ getIterationPeriod(item) }}
<iteration-title <iteration-title v-if="item.title" :title="item.title" />
v-if="getIterationTitle(item)"
data-testid="new-column-iteration-title"
>
{{ getIterationTitle(item) }}
</iteration-title>
</div> </div>
<div v-else class="gl-display-inline-block"> <div v-else class="gl-display-inline-block">
{{ item.title }} {{ item.title }}
......
<script>
export default {
name: 'IterationTitle',
props: {
title: {
type: String,
required: true,
},
},
};
</script>
<template> <template>
<div class="gl-text-gray-400"> <div class="gl-text-gray-400">
<slot></slot> {{ title }}
</div> </div>
</template> </template>
...@@ -13,10 +13,6 @@ export function getIterationPeriod({ startDate, dueDate }) { ...@@ -13,10 +13,6 @@ export function getIterationPeriod({ startDate, dueDate }) {
return `${start} - ${due}`; return `${start} - ${due}`;
} }
export function getIterationTitle(iteration) {
return iteration?.title;
}
/** /**
* Group a list of iterations by cadence. * Group a list of iterations by cadence.
* *
......
...@@ -9,11 +9,7 @@ import { ...@@ -9,11 +9,7 @@ import {
GlLoadingIcon, GlLoadingIcon,
} from '@gitlab/ui'; } from '@gitlab/ui';
import IterationTitle from 'ee/iterations/components/iteration_title.vue'; import IterationTitle from 'ee/iterations/components/iteration_title.vue';
import { import { groupByIterationCadences, getIterationPeriod } from 'ee/iterations/utils';
groupByIterationCadences,
getIterationPeriod,
getIterationTitle,
} from 'ee/iterations/utils';
import { __ } from '~/locale'; import { __ } from '~/locale';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { iterationSelectTextMap, iterationDisplayState } from '../constants'; import { iterationSelectTextMap, iterationDisplayState } from '../constants';
...@@ -99,7 +95,6 @@ export default { ...@@ -99,7 +95,6 @@ export default {
this.shouldFetch = true; this.shouldFetch = true;
}, },
getIterationPeriod, getIterationPeriod,
getIterationTitle,
}, },
}; };
</script> </script>
...@@ -128,9 +123,7 @@ export default { ...@@ -128,9 +123,7 @@ export default {
@click="onClick(iterationItem)" @click="onClick(iterationItem)"
> >
{{ getIterationPeriod(iterationItem) }} {{ getIterationPeriod(iterationItem) }}
<iteration-title v-if="getIterationTitle(iterationItem)"> <iteration-title v-if="iterationItem.title" :title="iterationItem.title" />
{{ getIterationTitle(iterationItem) }}
</iteration-title>
</gl-dropdown-item> </gl-dropdown-item>
</template> </template>
<template v-else> <template v-else>
...@@ -147,9 +140,7 @@ export default { ...@@ -147,9 +140,7 @@ export default {
@click="onClick(iterationItem)" @click="onClick(iterationItem)"
> >
{{ iterationItem.period }} {{ iterationItem.period }}
<iteration-title v-if="getIterationTitle(iterationItem)"> <iteration-title v-if="iterationItem.title" :title="iterationItem.title" />
{{ getIterationTitle(iterationItem) }}
</iteration-title>
</gl-dropdown-item> </gl-dropdown-item>
</template> </template>
</template> </template>
......
...@@ -8,11 +8,7 @@ import { ...@@ -8,11 +8,7 @@ import {
} from '@gitlab/ui'; } from '@gitlab/ui';
import SidebarDropdownWidget from 'ee/sidebar/components/sidebar_dropdown_widget.vue'; import SidebarDropdownWidget from 'ee/sidebar/components/sidebar_dropdown_widget.vue';
import IterationTitle from 'ee/iterations/components/iteration_title.vue'; import IterationTitle from 'ee/iterations/components/iteration_title.vue';
import { import { getIterationPeriod, groupByIterationCadences } from 'ee/iterations/utils';
getIterationPeriod,
getIterationTitle,
groupByIterationCadences,
} from 'ee/iterations/utils';
import { IssuableType } from '~/issues/constants'; import { IssuableType } from '~/issues/constants';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { IssuableAttributeType } from '../constants'; import { IssuableAttributeType } from '../constants';
...@@ -56,7 +52,6 @@ export default { ...@@ -56,7 +52,6 @@ export default {
}, },
groupByIterationCadences, groupByIterationCadences,
getIterationPeriod, getIterationPeriod,
getIterationTitle,
}, },
}; };
</script> </script>
...@@ -82,9 +77,7 @@ export default { ...@@ -82,9 +77,7 @@ export default {
<gl-icon name="iteration" class="gl-mr-1" /> <gl-icon name="iteration" class="gl-mr-1" />
{{ getIterationPeriod(currentAttribute) }} {{ getIterationPeriod(currentAttribute) }}
</div> </div>
<iteration-title v-if="getIterationTitle(currentAttribute)">{{ <iteration-title v-if="currentAttribute.title" :title="currentAttribute.title" />
getIterationTitle(currentAttribute)
}}</iteration-title>
</gl-link> </gl-link>
</template> </template>
<template #list="{ attributesList = [], isAttributeChecked, updateAttribute }"> <template #list="{ attributesList = [], isAttributeChecked, updateAttribute }">
...@@ -106,9 +99,7 @@ export default { ...@@ -106,9 +99,7 @@ export default {
@click="updateAttribute(iteration.id)" @click="updateAttribute(iteration.id)"
> >
{{ iteration.period }} {{ iteration.period }}
<iteration-title v-if="getIterationTitle(iteration)">{{ <iteration-title v-if="iteration.title" :title="iteration.title" />
getIterationTitle(iteration)
}}</iteration-title>
</gl-dropdown-item> </gl-dropdown-item>
</template> </template>
</template> </template>
......
...@@ -5,6 +5,7 @@ import Vuex from 'vuex'; ...@@ -5,6 +5,7 @@ import Vuex from 'vuex';
import BoardAddNewColumn, { listTypeInfo } from 'ee/boards/components/board_add_new_column.vue'; import BoardAddNewColumn, { listTypeInfo } from 'ee/boards/components/board_add_new_column.vue';
import { extendedWrapper } from 'helpers/vue_test_utils_helper'; import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import BoardAddNewColumnForm from '~/boards/components/board_add_new_column_form.vue'; import BoardAddNewColumnForm from '~/boards/components/board_add_new_column_form.vue';
import IterationTitle from 'ee/iterations/components/iteration_title.vue';
import { ListType } from '~/boards/constants'; import { ListType } from '~/boards/constants';
import defaultState from '~/boards/stores/state'; import defaultState from '~/boards/stores/state';
import { getIterationPeriod } from 'ee/iterations/utils'; import { getIterationPeriod } from 'ee/iterations/utils';
...@@ -47,6 +48,7 @@ describe('BoardAddNewColumn', () => { ...@@ -47,6 +48,7 @@ describe('BoardAddNewColumn', () => {
BoardAddNewColumnForm, BoardAddNewColumnForm,
GlFormRadio, GlFormRadio,
GlFormRadioGroup, GlFormRadioGroup,
IterationTitle,
}, },
data() { data() {
return { return {
...@@ -117,9 +119,7 @@ describe('BoardAddNewColumn', () => { ...@@ -117,9 +119,7 @@ describe('BoardAddNewColumn', () => {
const expectIterationWithoutTitle = () => { const expectIterationWithoutTitle = () => {
expect(findIterationItemAt(0).text()).toContain(getIterationPeriod(mockIterations[0])); expect(findIterationItemAt(0).text()).toContain(getIterationPeriod(mockIterations[0]));
expect(findIterationItemAt(0).find("[data-testid='new-column-iteration-title']").exists()).toBe( expect(findIterationItemAt(0).findComponent(IterationTitle).exists()).toBe(false);
false,
);
}; };
it('clicking cancel hides the form', () => { it('clicking cancel hides the form', () => {
......
import { shallowMount } from '@vue/test-utils';
import IterationTitle from 'ee/iterations/components/iteration_title.vue';
describe('Iterations title', () => {
let wrapper;
const createComponent = (propsData) => {
wrapper = shallowMount(IterationTitle, {
propsData,
});
};
afterEach(() => {
wrapper.destroy();
});
it('shows empty state', () => {
createComponent({ title: 'abc' });
expect(wrapper.html()).toHaveText('abc');
});
});
...@@ -13,6 +13,7 @@ import IterationDropdown from 'ee/sidebar/components/iteration_dropdown.vue'; ...@@ -13,6 +13,7 @@ import IterationDropdown from 'ee/sidebar/components/iteration_dropdown.vue';
import groupIterationsQuery from 'ee/sidebar/queries/iterations.query.graphql'; import groupIterationsQuery from 'ee/sidebar/queries/iterations.query.graphql';
import createMockApollo from 'helpers/mock_apollo_helper'; import createMockApollo from 'helpers/mock_apollo_helper';
import { getIterationPeriod } from 'ee/iterations/utils'; import { getIterationPeriod } from 'ee/iterations/utils';
import IterationTitle from 'ee/iterations/components/iteration_title.vue';
Vue.use(VueApollo); Vue.use(VueApollo);
...@@ -112,6 +113,9 @@ describe('IterationDropdown', () => { ...@@ -112,6 +113,9 @@ describe('IterationDropdown', () => {
propsData: { propsData: {
fullPath: TEST_FULL_PATH, fullPath: TEST_FULL_PATH,
}, },
stubs: {
IterationTitle,
},
provide: { provide: {
glFeatures: { glFeatures: {
iterationCadences, iterationCadences,
...@@ -171,18 +175,8 @@ describe('IterationDropdown', () => { ...@@ -171,18 +175,8 @@ describe('IterationDropdown', () => {
}); });
it('shows checkable dropdown items in unchecked state', () => { it('shows checkable dropdown items in unchecked state', () => {
expect(findDropdownItems().wrappers.map((x) => x.props('isCheckItem'))).toEqual([ expect(findDropdownItems().wrappers.every((x) => x.props('isCheckItem'))).toBe(true);
true, expect(findDropdownItems().wrappers.every((x) => x.props('isChecked'))).toBe(false);
true,
true,
true,
]);
expect(findDropdownItems().wrappers.map((x) => x.props('isChecked'))).toEqual([
false,
false,
false,
false,
]);
}); });
it('populates dropdown items with correct names', () => { it('populates dropdown items with correct names', () => {
...@@ -237,12 +231,7 @@ describe('IterationDropdown', () => { ...@@ -237,12 +231,7 @@ describe('IterationDropdown', () => {
}); });
it('shows item as unchecked', () => { it('shows item as unchecked', () => {
expect(findDropdownItems().wrappers.map((x) => x.props('isChecked'))).toEqual([ expect(findDropdownItems().wrappers.every((x) => x.props('isChecked'))).toBe(false);
false,
false,
false,
false,
]);
}); });
it('emits event', () => { it('emits event', () => {
......
...@@ -4,6 +4,7 @@ import Vue from 'vue'; ...@@ -4,6 +4,7 @@ import Vue from 'vue';
import IterationSidebarDropdownWidget from 'ee/sidebar/components/iteration_sidebar_dropdown_widget.vue'; import IterationSidebarDropdownWidget from 'ee/sidebar/components/iteration_sidebar_dropdown_widget.vue';
import createMockApollo from 'helpers/mock_apollo_helper'; import createMockApollo from 'helpers/mock_apollo_helper';
import { extendedWrapper } from 'helpers/vue_test_utils_helper'; import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import waitForPromises from 'helpers/wait_for_promises';
import { IssuableType } from '~/issues/constants'; import { IssuableType } from '~/issues/constants';
import groupIterationsQuery from 'ee/sidebar/queries/group_iterations.query.graphql'; import groupIterationsQuery from 'ee/sidebar/queries/group_iterations.query.graphql';
import projectIssueIterationQuery from 'ee/sidebar/queries/project_issue_iteration.query.graphql'; import projectIssueIterationQuery from 'ee/sidebar/queries/project_issue_iteration.query.graphql';
...@@ -17,7 +18,7 @@ import { ...@@ -17,7 +18,7 @@ import {
mockCurrentIterationResponse1, mockCurrentIterationResponse1,
mockCurrentIterationResponse2, mockCurrentIterationResponse2,
} from '../mock_data'; } from '../mock_data';
import { waitForApollo, clickEdit, search } from '../helpers'; import { clickEdit } from '../helpers';
Vue.use(VueApollo); Vue.use(VueApollo);
...@@ -57,7 +58,8 @@ describe('IterationSidebarDropdownWidget', () => { ...@@ -57,7 +58,8 @@ describe('IterationSidebarDropdownWidget', () => {
}), }),
); );
await waitForApollo(); jest.runOnlyPendingTimers();
await waitForPromises();
}; };
afterEach(() => { afterEach(() => {
...@@ -87,7 +89,6 @@ describe('IterationSidebarDropdownWidget', () => { ...@@ -87,7 +89,6 @@ describe('IterationSidebarDropdownWidget', () => {
it('renders iterations', async () => { it('renders iterations', async () => {
await createComponentWithApollo(); await createComponentWithApollo();
await clickEdit(wrapper); await clickEdit(wrapper);
await search(wrapper, 'iteration');
// mockIteration1 has no title // mockIteration1 has no title
expect(findIterationItemsTextAt(0)).toContain(getIterationPeriod(mockIteration1)); expect(findIterationItemsTextAt(0)).toContain(getIterationPeriod(mockIteration1));
...@@ -128,7 +129,6 @@ describe('IterationSidebarDropdownWidget', () => { ...@@ -128,7 +129,6 @@ describe('IterationSidebarDropdownWidget', () => {
it('renders iterations with cadence names', async () => { it('renders iterations with cadence names', async () => {
await createComponentWithApollo({ iterationCadences: true }); await createComponentWithApollo({ iterationCadences: true });
await clickEdit(wrapper); await clickEdit(wrapper);
await search(wrapper, 'iteration');
// mockIteration1 has no title // mockIteration1 has no title
expect(findIterationCadenceTitleAt(0)).toContain(mockIteration1.iterationCadence.title); expect(findIterationCadenceTitleAt(0)).toContain(mockIteration1.iterationCadence.title);
......
...@@ -7,7 +7,7 @@ import { ...@@ -7,7 +7,7 @@ import {
} from '@gitlab/ui'; } from '@gitlab/ui';
import * as Sentry from '@sentry/browser'; import * as Sentry from '@sentry/browser';
import { mount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import Vue, { nextTick } from 'vue'; import Vue from 'vue';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import SidebarDropdownWidget from 'ee/sidebar/components/sidebar_dropdown_widget.vue'; import SidebarDropdownWidget from 'ee/sidebar/components/sidebar_dropdown_widget.vue';
import { IssuableAttributeType, issuableAttributesQueries } from 'ee/sidebar/constants'; import { IssuableAttributeType, issuableAttributesQueries } from 'ee/sidebar/constants';
...@@ -16,10 +16,11 @@ import projectIssueEpicMutation from 'ee/sidebar/queries/project_issue_epic.muta ...@@ -16,10 +16,11 @@ import projectIssueEpicMutation from 'ee/sidebar/queries/project_issue_epic.muta
import projectIssueEpicQuery from 'ee/sidebar/queries/project_issue_epic.query.graphql'; import projectIssueEpicQuery from 'ee/sidebar/queries/project_issue_epic.query.graphql';
import createMockApollo from 'helpers/mock_apollo_helper'; import createMockApollo from 'helpers/mock_apollo_helper';
import { extendedWrapper } from 'helpers/vue_test_utils_helper'; import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import waitForPromises from 'helpers/wait_for_promises';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { IssuableType } from '~/issues/constants'; import { IssuableType } from '~/issues/constants';
import SidebarEditableItem from '~/sidebar/components/sidebar_editable_item.vue'; import SidebarEditableItem from '~/sidebar/components/sidebar_editable_item.vue';
import { waitForDropdown, waitForApollo, clickEdit, search } from '../helpers'; import { clickEdit, search } from '../helpers';
import { import {
mockIssue, mockIssue,
...@@ -51,7 +52,7 @@ describe('SidebarDropdownWidget', () => { ...@@ -51,7 +52,7 @@ describe('SidebarDropdownWidget', () => {
const toggleDropdown = async () => { const toggleDropdown = async () => {
wrapper.findComponent(SidebarEditableItem).vm.$emit('open'); wrapper.findComponent(SidebarEditableItem).vm.$emit('open');
await waitForDropdown(); await waitForPromises();
}; };
const createComponentWithApollo = async ({ const createComponentWithApollo = async ({
...@@ -81,7 +82,8 @@ describe('SidebarDropdownWidget', () => { ...@@ -81,7 +82,8 @@ describe('SidebarDropdownWidget', () => {
}), }),
); );
await waitForApollo(); jest.runOnlyPendingTimers();
await waitForPromises();
}; };
const createComponent = ({ const createComponent = ({
...@@ -257,7 +259,7 @@ describe('SidebarDropdownWidget', () => { ...@@ -257,7 +259,7 @@ describe('SidebarDropdownWidget', () => {
}); });
it('sends a groupEpics query with empty title and undefined in param', async () => { it('sends a groupEpics query with empty title and undefined in param', async () => {
await nextTick(); await waitForPromises();
// Account for debouncing // Account for debouncing
jest.runAllTimers(); jest.runAllTimers();
......
import { nextTick } from 'vue';
import { GlSearchBoxByType } from '@gitlab/ui'; import { GlSearchBoxByType } from '@gitlab/ui';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
import SidebarEditableItem from '~/sidebar/components/sidebar_editable_item.vue'; import SidebarEditableItem from '~/sidebar/components/sidebar_editable_item.vue';
...@@ -11,31 +10,15 @@ const findSearchBox = (wrapper) => wrapper.findComponent(GlSearchBoxByType); ...@@ -11,31 +10,15 @@ const findSearchBox = (wrapper) => wrapper.findComponent(GlSearchBoxByType);
export const search = async (wrapper, searchTerm) => { export const search = async (wrapper, searchTerm) => {
findSearchBox(wrapper).vm.$emit('input', searchTerm); findSearchBox(wrapper).vm.$emit('input', searchTerm);
await nextTick();
jest.runAllTimers(); // Account for debouncing
};
export const waitForDropdown = async () => {
// BDropdown first changes its `visible` property
// in a requestAnimationFrame callback.
// It then emits `shown` event in a watcher for `visible`
// Hence we need both of these:
await waitForPromises();
await nextTick();
};
export const waitForApollo = async () => {
jest.runOnlyPendingTimers();
await waitForPromises(); await waitForPromises();
jest.runAllTimers(); // Account for debouncing
}; };
// Used with createComponentWithApollo which uses 'mount' // Used with createComponentWithApollo which uses 'mount'
export const clickEdit = async (wrapper) => { export const clickEdit = async (wrapper) => {
await findEditButton(wrapper).trigger('click'); await findEditButton(wrapper).trigger('click');
await waitForDropdown(wrapper);
// We should wait for attributes list to be fetched. // We should wait for attributes list to be fetched.
await waitForApollo(); jest.runAllTimers();
await waitForPromises();
}; };
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