Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
474a0edd
Commit
474a0edd
authored
Feb 03, 2018
by
Kushal Pandya
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update tests for date helper functions
parent
74f6ef9f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
0 deletions
+64
-0
spec/javascripts/datetime_utility_spec.js
spec/javascripts/datetime_utility_spec.js
+64
-0
No files found.
spec/javascripts/datetime_utility_spec.js
View file @
474a0edd
...
@@ -105,4 +105,68 @@ describe('dateInWords', () => {
...
@@ -105,4 +105,68 @@ describe('dateInWords', () => {
it
(
'
should return abbreviated month name
'
,
()
=>
{
it
(
'
should return abbreviated month name
'
,
()
=>
{
expect
(
datetimeUtility
.
dateInWords
(
date
,
true
)).
toEqual
(
'
Jul 1, 2016
'
);
expect
(
datetimeUtility
.
dateInWords
(
date
,
true
)).
toEqual
(
'
Jul 1, 2016
'
);
});
});
it
(
'
should return date in words without year
'
,
()
=>
{
expect
(
datetimeUtility
.
dateInWords
(
date
,
true
,
true
)).
toEqual
(
'
Jul 1
'
);
});
});
describe
(
'
monthInWords
'
,
()
=>
{
const
date
=
new
Date
(
'
2017-01-20
'
);
it
(
'
returns month name from provided date
'
,
()
=>
{
expect
(
datetimeUtility
.
monthInWords
(
date
)).
toBe
(
'
January
'
);
});
it
(
'
returns abbreviated month name from provided date
'
,
()
=>
{
expect
(
datetimeUtility
.
monthInWords
(
date
,
true
)).
toBe
(
'
Jan
'
);
});
});
describe
(
'
totalDaysInMonth
'
,
()
=>
{
it
(
'
returns number of days in a month for given date
'
,
()
=>
{
// 1st Feb, 2016 (leap year)
expect
(
datetimeUtility
.
totalDaysInMonth
(
new
Date
(
2016
,
1
,
1
))).
toBe
(
29
);
// 1st Feb, 2017
expect
(
datetimeUtility
.
totalDaysInMonth
(
new
Date
(
2017
,
1
,
1
))).
toBe
(
28
);
// 1st Jan, 2017
expect
(
datetimeUtility
.
totalDaysInMonth
(
new
Date
(
2017
,
0
,
1
))).
toBe
(
31
);
});
});
describe
(
'
getSundays
'
,
()
=>
{
it
(
'
returns array of dates representing all Sundays of the month
'
,
()
=>
{
// December, 2017 (it has 5 Sundays)
const
dateOfSundays
=
[
3
,
10
,
17
,
24
,
31
];
const
sundays
=
datetimeUtility
.
getSundays
(
new
Date
(
2017
,
11
,
1
));
expect
(
sundays
.
length
).
toBe
(
5
);
sundays
.
forEach
((
sunday
,
index
)
=>
{
expect
(
sunday
.
getDate
()).
toBe
(
dateOfSundays
[
index
]);
});
});
});
describe
(
'
getTimeframeWindow
'
,
()
=>
{
it
(
'
returns array of dates representing a timeframe based on provided length and date
'
,
()
=>
{
const
date
=
new
Date
(
2018
,
0
,
1
);
const
mockTimeframe
=
[
new
Date
(
2017
,
9
,
1
),
new
Date
(
2017
,
10
,
1
),
new
Date
(
2017
,
11
,
1
),
new
Date
(
2018
,
0
,
1
),
new
Date
(
2018
,
1
,
1
),
new
Date
(
2018
,
2
,
31
),
];
const
timeframe
=
datetimeUtility
.
getTimeframeWindow
(
6
,
date
);
expect
(
timeframe
.
length
).
toBe
(
6
);
timeframe
.
forEach
((
timeframeItem
,
index
)
=>
{
expect
(
timeframeItem
.
getFullYear
()
===
mockTimeframe
[
index
].
getFullYear
()).
toBeTruthy
();
expect
(
timeframeItem
.
getMonth
()
===
mockTimeframe
[
index
].
getMonth
()).
toBeTruthy
();
expect
(
timeframeItem
.
getDate
()
===
mockTimeframe
[
index
].
getDate
()).
toBeTruthy
();
});
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment