Commit ef1934af authored by sstern's avatar sstern

Add guard to milestone_token for sort

parent 9667a0aa
......@@ -157,6 +157,7 @@ export default {
symbol: '%',
token: MilestoneToken,
unique: true,
shouldSkipSort: true,
fetchMilestones: this.fetchMilestones,
},
{
......
......@@ -57,7 +57,12 @@ export default {
.fetchMilestones(searchTerm)
.then((response) => {
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(() => {
createFlash({ message: __('There was a problem fetching milestones.') });
......
......@@ -474,6 +474,7 @@ export const mockTokens = (fetchLabels, fetchAuthors, fetchMilestones, fetchIter
symbol: '%',
type: 'milestone',
token: MilestoneToken,
shouldSkipSort: true,
unique: true,
fetchMilestones,
},
......
......@@ -612,6 +612,7 @@ export const mockTokens = (fetchLabels, fetchAuthors, fetchMilestones, isSignedI
title: __('Milestone'),
symbol: '%',
type: 'milestone',
shouldSkipSort: true,
token: MilestoneToken,
unique: true,
fetchMilestones,
......
......@@ -32,7 +32,7 @@ const defaultStubs = {
function createComponent(options = {}) {
const {
config = mockMilestoneToken,
config = { ...mockMilestoneToken, shouldSkipSort: true },
value = { data: '' },
active = false,
stubs = defaultStubs,
......@@ -68,6 +68,27 @@ describe('MilestoneToken', () => {
describe('methods', () => {
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', () => {
jest.spyOn(wrapper.vm.config, 'fetchMilestones');
......@@ -77,10 +98,11 @@ describe('MilestoneToken', () => {
});
it('sets response to `milestones` when request is successful', () => {
wrapper.vm.config.shouldSkipSort = false;
jest.spyOn(wrapper.vm.config, 'fetchMilestones').mockResolvedValue({
data: mockMilestones,
});
wrapper.vm.fetchMilestones();
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