Commit 96e4e1bb authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'ss/fix-mileston-token-filter' into 'master'

Add guard to milestone_token for sort

See merge request gitlab-org/gitlab!79068
parents c399d7ab ef1934af
...@@ -157,6 +157,7 @@ export default { ...@@ -157,6 +157,7 @@ export default {
symbol: '%', symbol: '%',
token: MilestoneToken, token: MilestoneToken,
unique: true, unique: true,
shouldSkipSort: true,
fetchMilestones: this.fetchMilestones, fetchMilestones: this.fetchMilestones,
}, },
{ {
......
...@@ -57,7 +57,12 @@ export default { ...@@ -57,7 +57,12 @@ export default {
.fetchMilestones(searchTerm) .fetchMilestones(searchTerm)
.then((response) => { .then((response) => {
const data = Array.isArray(response) ? response : response.data; const data = Array.isArray(response) ? response : response.data;
this.milestones = data.slice().sort(sortMilestonesByDueDate);
if (this.config.shouldSkipSort) {
this.milestones = data;
} else {
this.milestones = data.slice().sort(sortMilestonesByDueDate);
}
}) })
.catch(() => { .catch(() => {
createFlash({ message: __('There was a problem fetching milestones.') }); createFlash({ message: __('There was a problem fetching milestones.') });
......
...@@ -474,6 +474,7 @@ export const mockTokens = (fetchLabels, fetchAuthors, fetchMilestones, fetchIter ...@@ -474,6 +474,7 @@ export const mockTokens = (fetchLabels, fetchAuthors, fetchMilestones, fetchIter
symbol: '%', symbol: '%',
type: 'milestone', type: 'milestone',
token: MilestoneToken, token: MilestoneToken,
shouldSkipSort: true,
unique: true, unique: true,
fetchMilestones, fetchMilestones,
}, },
......
...@@ -612,6 +612,7 @@ export const mockTokens = (fetchLabels, fetchAuthors, fetchMilestones, isSignedI ...@@ -612,6 +612,7 @@ export const mockTokens = (fetchLabels, fetchAuthors, fetchMilestones, isSignedI
title: __('Milestone'), title: __('Milestone'),
symbol: '%', symbol: '%',
type: 'milestone', type: 'milestone',
shouldSkipSort: true,
token: MilestoneToken, token: MilestoneToken,
unique: true, unique: true,
fetchMilestones, fetchMilestones,
......
...@@ -32,7 +32,7 @@ const defaultStubs = { ...@@ -32,7 +32,7 @@ const defaultStubs = {
function createComponent(options = {}) { function createComponent(options = {}) {
const { const {
config = mockMilestoneToken, config = { ...mockMilestoneToken, shouldSkipSort: true },
value = { data: '' }, value = { data: '' },
active = false, active = false,
stubs = defaultStubs, stubs = defaultStubs,
...@@ -68,6 +68,27 @@ describe('MilestoneToken', () => { ...@@ -68,6 +68,27 @@ describe('MilestoneToken', () => {
describe('methods', () => { describe('methods', () => {
describe('fetchMilestones', () => { describe('fetchMilestones', () => {
describe('when config.shouldSkipSort is true', () => {
beforeEach(() => {
wrapper.vm.config.shouldSkipSort = true;
});
afterEach(() => {
wrapper.vm.config.shouldSkipSort = false;
});
it('does not call sortMilestonesByDueDate', async () => {
jest.spyOn(wrapper.vm.config, 'fetchMilestones').mockResolvedValue({
data: mockMilestones,
});
wrapper.vm.fetchMilestones();
await waitForPromises();
expect(sortMilestonesByDueDate).toHaveBeenCalledTimes(0);
});
});
it('calls `config.fetchMilestones` with provided searchTerm param', () => { it('calls `config.fetchMilestones` with provided searchTerm param', () => {
jest.spyOn(wrapper.vm.config, 'fetchMilestones'); jest.spyOn(wrapper.vm.config, 'fetchMilestones');
...@@ -77,10 +98,11 @@ describe('MilestoneToken', () => { ...@@ -77,10 +98,11 @@ describe('MilestoneToken', () => {
}); });
it('sets response to `milestones` when request is successful', () => { it('sets response to `milestones` when request is successful', () => {
wrapper.vm.config.shouldSkipSort = false;
jest.spyOn(wrapper.vm.config, 'fetchMilestones').mockResolvedValue({ jest.spyOn(wrapper.vm.config, 'fetchMilestones').mockResolvedValue({
data: mockMilestones, data: mockMilestones,
}); });
wrapper.vm.fetchMilestones(); wrapper.vm.fetchMilestones();
return waitForPromises().then(() => { return waitForPromises().then(() => {
......
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