Skip to content

Commit 2525a9d

Browse files
committed
Add tests to support multiple timestamp formats
1 parent 3d47def commit 2525a9d

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

tests/index-test.js

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ describe('displayRevisions plugin', function() {
164164
},
165165
revisions: [
166166
{ revision: "rev:abcdef", timestamp: 1438232435000, deployer: "My Hamster"},
167-
{ revision: "rev:defghi", timestamp: 1032123125000, deployer: "My Hamster", active: true},
168-
{ revision: "rev:jklmno", timestamp: 1032123128000, deployer: "My Hamster"},
167+
{ revision: "rev:defghi", timestamp: '2002-09-15T20:52:05.000Z', deployer: "My Hamster", active: true},
168+
{ revision: "rev:jklmno", timestamp: new Date(1032123128000), deployer: "My Hamster"},
169169
{ revision: "rev:qrstuv", timestamp: 1032123155000, deployer: "My Hamster"},
170170
{ revision: "rev:xyz123", timestamp: 1032123123000, deployer: "My Hamster"}
171171
]
@@ -198,7 +198,7 @@ describe('displayRevisions plugin', function() {
198198
assert.equal(messages.length, 0);
199199
});
200200

201-
it('transforms timestamps to human-readable dates (yyyy/MM/dd HH:mm:ss)', function() {
201+
it('transforms millisecond timestamps to human-readable dates (yyyy/MM/dd HH:mm:ss)', function() {
202202
plugin.displayRevisions(context);
203203
let expectedFormat = ('yyyy/MM/dd HH:mm:ss');
204204
let expectedDate = DateTime.fromMillis(1438232435000).toFormat(expectedFormat);
@@ -213,6 +213,36 @@ describe('displayRevisions plugin', function() {
213213
assert.equal(messages.length, 1);
214214
});
215215

216+
it('transforms ISO string timestamps to human-readable dates (yyyy/MM/dd HH:mm:ss)', function() {
217+
plugin.displayRevisions(context);
218+
let expectedFormat = ('yyyy/MM/dd HH:mm:ss');
219+
let expectedDate = DateTime.fromISO('2002-09-15T20:52:05.000Z').toFormat(expectedFormat);
220+
221+
let messages = mockUi.messages.reduce(function(previous, current) {
222+
if (current.indexOf(expectedDate) !== -1) {
223+
previous.push(current);
224+
}
225+
226+
return previous;
227+
}, []);
228+
assert.equal(messages.length, 1);
229+
});
230+
231+
it('transforms JS Date object timestamps to human-readable dates (yyyy/MM/dd HH:mm:ss)', function() {
232+
plugin.displayRevisions(context);
233+
let expectedFormat = ('yyyy/MM/dd HH:mm:ss');
234+
let expectedDate = DateTime.fromJSDate(new Date(1032123128000)).toFormat(expectedFormat);
235+
236+
let messages = mockUi.messages.reduce(function(previous, current) {
237+
if (current.indexOf(expectedDate) !== -1) {
238+
previous.push(current);
239+
}
240+
241+
return previous;
242+
}, []);
243+
assert.equal(messages.length, 1);
244+
});
245+
216246
it('highlights the active revision', function() {
217247
plugin.displayRevisions(context);
218248
let messages = mockUi.messages.reduce(function(previous, current) {

0 commit comments

Comments
 (0)