Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-12-20 16:37:47 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-12-20 16:37:47 +0300
commitaee0a117a889461ce8ced6fcf73207fe017f1d99 (patch)
tree891d9ef189227a8445d83f35c1b0fc99573f4380 /spec/frontend/milestones/utils_spec.js
parent8d46af3258650d305f53b819eabf7ab18d22f59e (diff)
Add latest changes from gitlab-org/gitlab@14-6-stable-eev14.6.0-rc42
Diffstat (limited to 'spec/frontend/milestones/utils_spec.js')
-rw-r--r--spec/frontend/milestones/utils_spec.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/spec/frontend/milestones/utils_spec.js b/spec/frontend/milestones/utils_spec.js
new file mode 100644
index 00000000000..82e31c98398
--- /dev/null
+++ b/spec/frontend/milestones/utils_spec.js
@@ -0,0 +1,47 @@
+import { useFakeDate } from 'helpers/fake_date';
+import { sortMilestonesByDueDate } from '~/milestones/utils';
+
+describe('sortMilestonesByDueDate', () => {
+ useFakeDate(2021, 6, 22);
+ const mockMilestones = [
+ {
+ id: 2,
+ },
+ {
+ id: 1,
+ dueDate: '2021-01-01',
+ },
+ {
+ id: 4,
+ dueDate: '2021-02-01',
+ expired: true,
+ },
+ {
+ id: 3,
+ dueDate: `2021-08-01`,
+ },
+ ];
+
+ describe('sorts milestones', () => {
+ it('expired milestones are kept at the bottom of the list', () => {
+ const sortedMilestones = [...mockMilestones].sort(sortMilestonesByDueDate);
+
+ expect(sortedMilestones[2].id).toBe(mockMilestones[1].id); // milestone with id `1` is expired
+ expect(sortedMilestones[3].id).toBe(mockMilestones[2].id); // milestone with id `4` is expired
+ });
+
+ it('milestones with closest due date are kept at the top of the list', () => {
+ const sortedMilestones = [...mockMilestones].sort(sortMilestonesByDueDate);
+
+ // milestone with id `3` & 2021-08-01 is closest to current date i.e. 2021-07-22
+ expect(sortedMilestones[0].id).toBe(mockMilestones[3].id);
+ });
+
+ it('milestones with no due date are kept between milestones with closest due date and expired milestones', () => {
+ const sortedMilestones = [...mockMilestones].sort(sortMilestonesByDueDate);
+
+ // milestone with id `2` has no due date
+ expect(sortedMilestones[1].id).toBe(mockMilestones[0].id);
+ });
+ });
+});