Skip to content
代码片段 群组 项目
未验证 提交 da7bc2cf 编辑于 作者: Miguel Rincon's avatar Miguel Rincon 提交者: GitLab
浏览文件

Merge branch '521338-your-work-projects-fails-when-an-unknown-sort-is-used' into 'master'

Fix error when invalid sort is used on `Your work` -> `Projects`

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/182758



Merged-by: default avatarMiguel Rincon <mrincon@gitlab.com>
Approved-by: default avatarMiguel Rincon <mrincon@gitlab.com>
Co-authored-by: default avatarPeter Hegman <phegman@gitlab.com>
No related branches found
No related tags found
无相关合并请求
...@@ -129,11 +129,20 @@ export default { ...@@ -129,11 +129,20 @@ export default {
return this.$route.query.sort; return this.$route.query.sort;
}, },
sort() { sort() {
if (this.sortQuery) { const sortOptionValues = SORT_OPTIONS.flatMap(({ value }) => [
`${value}_${SORT_DIRECTION_ASC}`,
`${value}_${SORT_DIRECTION_DESC}`,
]);
if (this.sortQuery && sortOptionValues.includes(this.sortQuery)) {
return this.sortQuery; return this.sortQuery;
} }
return this.initialSort || `${SORT_OPTION_UPDATED.value}_${SORT_DIRECTION_ASC}`; if (sortOptionValues.includes(this.initialSort)) {
return this.initialSort;
}
return `${SORT_OPTION_UPDATED.value}_${SORT_DIRECTION_ASC}`;
}, },
activeSortOption() { activeSortOption() {
return SORT_OPTIONS.find((sortItem) => this.sort.includes(sortItem.value)); return SORT_OPTIONS.find((sortItem) => this.sort.includes(sortItem.value));
......
...@@ -83,6 +83,7 @@ describe('YourWorkProjectsApp', () => { ...@@ -83,6 +83,7 @@ describe('YourWorkProjectsApp', () => {
}); });
const createComponent = async ({ const createComponent = async ({
provide = {},
projectsCountHandler = successHandler, projectsCountHandler = successHandler,
userPreferencesUpdateHandler = userPreferencesUpdateSuccessHandler, userPreferencesUpdateHandler = userPreferencesUpdateSuccessHandler,
route = defaultRoute, route = defaultRoute,
...@@ -100,7 +101,7 @@ describe('YourWorkProjectsApp', () => { ...@@ -100,7 +101,7 @@ describe('YourWorkProjectsApp', () => {
stubs: { stubs: {
TabView: stubComponent(TabView), TabView: stubComponent(TabView),
}, },
provide: defaultProvide, provide: { ...defaultProvide, ...provide },
}); });
}; };
...@@ -355,6 +356,45 @@ describe('YourWorkProjectsApp', () => { ...@@ -355,6 +356,45 @@ describe('YourWorkProjectsApp', () => {
}); });
}); });
describe('when sort query param is invalid', () => {
beforeEach(async () => {
await createComponent({
route: {
...defaultRoute,
query: {
sort: 'foo_bar',
},
},
});
});
it('falls back to initial sort', () => {
expect(findTabView().props()).toMatchObject({
sort: `${SORT_OPTION_CREATED.value}_${SORT_DIRECTION_DESC}`,
});
});
});
describe('when sort query param and initial sort are invalid', () => {
beforeEach(async () => {
await createComponent({
provide: { initialSort: 'foo_bar' },
route: {
...defaultRoute,
query: {
sort: 'foo_bar',
},
},
});
});
it('falls back to updated in ascending order', () => {
expect(findTabView().props()).toMatchObject({
sort: `${SORT_OPTION_UPDATED.value}_${SORT_DIRECTION_ASC}`,
});
});
});
describe('onTabUpdate', () => { describe('onTabUpdate', () => {
describe('when tab is already active', () => { describe('when tab is already active', () => {
beforeEach(async () => { beforeEach(async () => {
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册