From f7b9384d261beaa70994340eb83d6b77ac6535af Mon Sep 17 00:00:00 2001 From: Zara Gebru Date: Fri, 15 Apr 2016 11:27:01 +0200 Subject: Issue #678: added utility converting time passed and dynamically changing version timestamp --- web-ui/test/spec/helpers/view_helper.spec.js | 77 ++++++++++++++++++++++------ web-ui/test/spec/page/version.spec.js | 16 ++++++ 2 files changed, 77 insertions(+), 16 deletions(-) create mode 100644 web-ui/test/spec/page/version.spec.js (limited to 'web-ui/test/spec') diff --git a/web-ui/test/spec/helpers/view_helper.spec.js b/web-ui/test/spec/helpers/view_helper.spec.js index 19bef15f..5beba137 100644 --- a/web-ui/test/spec/helpers/view_helper.spec.js +++ b/web-ui/test/spec/helpers/view_helper.spec.js @@ -2,13 +2,13 @@ define(['helpers/view_helper'], function (viewHelper) { 'use strict'; var testData; - describe('view helper', function() { + describe('view helper', function () { beforeEach(function () { testData = Pixelated.testData(); }); - describe('quote email', function() { - it('should add > to body text', function() { + describe('quote email', function () { + it('should add > to body text', function () { testData.parsedMail.simpleTextPlain.textPlainBody = 'First Line\nSecond Line'; var quotedMail = viewHelper.quoteMail(testData.parsedMail.simpleTextPlain); @@ -16,7 +16,7 @@ define(['helpers/view_helper'], function (viewHelper) { expect(quotedMail).toContain('> First Line\n> Second Line'); }); - it('should add the mail sender information', function() { + it('should add the mail sender information', function () { testData.parsedMail.simpleTextPlain.textPlainBody = 'First Line\nSecond Line'; var quotedMail = viewHelper.quoteMail(testData.parsedMail.simpleTextPlain); @@ -25,25 +25,25 @@ define(['helpers/view_helper'], function (viewHelper) { }); }); - describe('formatDate', function() { + describe('formatDate', function () { var template; beforeEach(function () { template = Handlebars.compile('{{formatDate date}}'); }); - it('formats correctly a Date for today', function() { + it('formats correctly a Date for today', function () { var d = new Date(); var mailDate = new Date(d.getFullYear(), d.getMonth(), d.getDate(), 14, 2, 36); - var result = template({ date: mailDate.toISOString() }); + var result = template({date: mailDate.toISOString()}); expect(result).toEqual('14:02'); }); - it('formats correctly a Date for a specific day', function() { + it('formats correctly a Date for a specific day', function () { var mailDate = new Date(2013, 2, 13, 7, 56, 1); - var result = template({ date: mailDate.toISOString() }); + var result = template({date: mailDate.toISOString()}); // This expectation is weird for the month - JS Dates have date numbers be zero-indexed, thus the discrepancy // Specifically, the 2 in the constructor DOES match the 3 in the expectation below. @@ -51,31 +51,76 @@ define(['helpers/view_helper'], function (viewHelper) { }); }); - describe('formatSize', function() { + describe('formatSize', function () { var template; beforeEach(function () { template = Handlebars.compile('{{formatSize size}}'); }); - it('formats size to bytes', function() { + it('formats size to bytes', function () { var bytes = 42; - var result = template({ size: bytes }); + var result = template({size: bytes}); expect(result).toEqual('42.00 b'); }); - it('formats size to kilobytes', function() { + it('formats size to kilobytes', function () { var bytes = 4200; - var result = template({ size: bytes }); + var result = template({size: bytes}); expect(result).toEqual('4.10 Kb'); }); - it('formats size to megabytes', function() { + it('formats size to megabytes', function () { var bytes = 4200000; - var result = template({ size: bytes }); + var result = template({size: bytes}); expect(result).toEqual('4.01 Mb'); }); }); + describe('sinceDate', function () { + var template; + beforeEach(function () { + template = Handlebars.compile('{{sinceDate commitDate}}'); + var milliseconds_on_2016_04_08_16h_20m_00s = 1460126400000; + spyOn(Date, 'now').and.returnValue(milliseconds_on_2016_04_08_16h_20m_00s); + }); + + it('gives time passed since date in minutes', function () { + var twenty_minutes_ago = "2016-04-08T16:20:00+02:00"; + var result = template({commitDate: twenty_minutes_ago}); + expect(result).toEqual('20 minute(s)'); + }); + + it('gives time passed since date above 60 min and less than a day in hours when ', function () { + var two_hours_ago = "2016-04-08T14:20:00+02:00"; + var result = template({commitDate: two_hours_ago}); + expect(result).toEqual('2 hour(s)'); + }); + + it('gives time passed since date above one day and less than a week in hours when ', function () { + var one_day_ago = "2016-04-07T16:20:00+02:00"; + var result = template({commitDate: one_day_ago}); + expect(result).toEqual('1 day(s)'); + }); + + it('gives time passed since date above one week and less than a month in hours when ', function () { + var one_week_ago = "2016-03-30T16:20:00+02:00"; + var result = template({commitDate: one_week_ago}); + expect(result).toEqual('1 week(s)'); + }); + + it('gives time passed since date above one month and less than a year in hours when ', function () { + var three_month_ago = "2016-01-03T16:20:00+02:00"; + var result = template({commitDate: three_month_ago}); + expect(result).toEqual('3 month(s)'); + }); + + it('gives time passed since date more then one year ago', function () { + var two_years_ago = "2014-03-08T16:20:00+02:00"; + var result = template({commitDate: two_years_ago}); + expect(result).toEqual('2 year(s)'); + }); + }); + describe('format status classes', function () { it('formats all the status of the email to css classes', function () { var statuses = ['read', 'banana']; diff --git a/web-ui/test/spec/page/version.spec.js b/web-ui/test/spec/page/version.spec.js new file mode 100644 index 00000000..6c1c741f --- /dev/null +++ b/web-ui/test/spec/page/version.spec.js @@ -0,0 +1,16 @@ +describeComponent('page/version', function () { + 'use strict'; + beforeEach(function () { + this.setupComponent('
0.3.1-beta
'); + }); + + + describe('render version on the left nav bar', function () { + it('should render commit sha and comm', function () { + expect(this.$node.html()).toContain('version: '); + expect(this.$node.html()).toContain('ago'); + expect(this.$node.html()).not.toContain('NaN'); + }); + }); + +}); -- cgit v1.2.3