Browse Source
* added tests for filter.js, Added structure to test-directory In the gulpfile I changed some of the karma execution to ensure templates.js exists before the tests Also removed some StandardJS errors from filters.js * added tests to create at least 50% coverage for filters.js * Added test for full coverage of filters.js * fixed 2 side-cases * Removed duplicate test, improved test-titles and added outcome clarification for dateOrTimeFilter * Added test-init While running ``gulp test`` there were a lot of warnings concerning i18n: key not found This was because init.js was not run. Because some parts of init.js were not relevant, I created test-init.js, only containing the part concerning localization. Now the log is a lot cleaner when running ``gulp test`` * added 'use strict' to testing files * changed local vars to this. * improved clarity of mistery numbers * improved in-test structure * Improved shortUrl tests * removed unnecessary code * added cleanup to single testmaster
Bart
8 years ago
committed by
Igor Zhukov
33 changed files with 992 additions and 83 deletions
@ -0,0 +1,42 @@
@@ -0,0 +1,42 @@
|
||||
'use strict' |
||||
/* global ConfigStorage, Config */ |
||||
|
||||
;(function initTestApplication () { |
||||
ConfigStorage.get('layout_selected', 'i18n_locale', function (params) { |
||||
var locale = params[1] |
||||
var defaultLocale = 'en-us' |
||||
var bootReady = { |
||||
dom: false, |
||||
i18n_ng: false, |
||||
i18n_messages: false, |
||||
i18n_fallback: false |
||||
} |
||||
|
||||
if (!locale) { |
||||
locale = (navigator.language || '').toLowerCase() |
||||
locale = Config.I18n.aliases[locale] || locale |
||||
} |
||||
for (var i = 0; i < Config.I18n.supported.length; i++) { |
||||
if (Config.I18n.supported[i] === locale) { |
||||
Config.I18n.locale = locale |
||||
break |
||||
} |
||||
} |
||||
bootReady.i18n_ng = Config.I18n.locale === defaultLocale // Already included
|
||||
|
||||
$.getJSON('base/js/locales/' + Config.I18n.locale + '.json').success(function (json) { |
||||
Config.I18n.messages = json |
||||
bootReady.i18n_messages = true |
||||
if (Config.I18n.locale === defaultLocale) { // No fallback, leave empty object
|
||||
bootReady.i18n_fallback = true |
||||
} |
||||
}) |
||||
|
||||
if (Config.I18n.locale !== defaultLocale) { |
||||
$.getJSON('base/js/locales/' + defaultLocale + '.json').success(function (json) { |
||||
Config.I18n.fallback_messages = json |
||||
bootReady.i18n_fallback = true |
||||
}) |
||||
} |
||||
}) |
||||
})() |
@ -1,3 +1,4 @@
@@ -1,3 +1,4 @@
|
||||
'use strict' |
||||
/* global describe, it, inject, expect, beforeEach */ |
||||
|
||||
describe('AppFooterController', function () { |
@ -1,3 +1,4 @@
@@ -1,3 +1,4 @@
|
||||
'use strict' |
||||
/* global describe, it, inject, expect, beforeEach, jasmine */ |
||||
|
||||
describe('AppImPanelController', function () { |
@ -1,3 +1,4 @@
@@ -1,3 +1,4 @@
|
||||
'use strict' |
||||
/* global describe, it, inject, expect, beforeEach, xit */ |
||||
|
||||
describe('AppLangSelectController', function () { |
@ -1,3 +1,4 @@
@@ -1,3 +1,4 @@
|
||||
'use strict' |
||||
/* global describe, it, inject, expect, beforeEach */ |
||||
|
||||
describe('AppWelcomeController', function () { |
@ -1,3 +1,4 @@
@@ -1,3 +1,4 @@
|
||||
'use strict' |
||||
/* global describe, it, inject, expect, beforeEach, Config */ |
||||
|
||||
describe('ChangeLogModalController', function () { |
@ -1,3 +1,4 @@
@@ -1,3 +1,4 @@
|
||||
'use strict' |
||||
/* global describe, it, inject, expect, beforeEach, jasmine */ |
||||
|
||||
describe('DocumentModalController', function () { |
@ -1,3 +1,4 @@
@@ -1,3 +1,4 @@
|
||||
'use strict' |
||||
/* global describe, it, inject, expect, beforeEach, jasmine */ |
||||
|
||||
describe('EmbedModalController', function () { |
@ -1,3 +1,4 @@
@@ -1,3 +1,4 @@
|
||||
'use strict' |
||||
/* global describe, it, inject, expect, beforeEach */ |
||||
|
||||
describe('PeerSelectController', function () { |
@ -1,3 +1,4 @@
@@ -1,3 +1,4 @@
|
||||
'use strict' |
||||
/* global describe, it, inject, expect, beforeEach, jasmine */ |
||||
|
||||
describe('VideoModalController', function () { |
@ -1,3 +1,4 @@
@@ -1,3 +1,4 @@
|
||||
'use strict' |
||||
/* global describe, it, inject, expect, beforeEach */ |
||||
|
||||
describe('myHead directive', function () { |
@ -1,3 +1,4 @@
@@ -1,3 +1,4 @@
|
||||
'use strict' |
||||
/* global describe, it, inject, expect, beforeEach */ |
||||
|
||||
describe('myLangFooter directive', function () { |
@ -0,0 +1,72 @@
@@ -0,0 +1,72 @@
|
||||
'use strict' |
||||
/* global describe, it, inject, expect, beforeEach, tsNow*/ |
||||
|
||||
describe('dateOrTime filter', function () { |
||||
beforeEach(module('myApp.filters')) |
||||
|
||||
beforeEach(inject(function (_$filter_) { |
||||
this.$filter = _$filter_ |
||||
})) |
||||
|
||||
beforeEach(function () { |
||||
this.dateOrTimeFilter = this.$filter('dateOrTime') |
||||
|
||||
// https://stackoverflow.com/questions/4676195/why-do-i-need-to-multiply-unix-timestamps-by-1000-in-javascript
|
||||
this.miliSecondsToSeconds = 1000 |
||||
this.sevenDaysAgo = -3600 * 24 * 7 |
||||
this.thirteenHoursAgo = -3600 * 13 |
||||
}) |
||||
|
||||
it('can handle "zero"-values', function () { |
||||
var input = 0 |
||||
var expected = '' |
||||
var result = this.dateOrTimeFilter(input, false) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('can display the time based on timestamp', function () { |
||||
var input = tsNow(true) |
||||
// Outcome format expected: HH:MM AM/PM
|
||||
var expected = this.$filter('date')(input * this.miliSecondsToSeconds, 'shortTime') |
||||
var result = this.dateOrTimeFilter(input, false) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('can display the short date based on timestamp', function () { |
||||
var input = tsNow(true) |
||||
// Outcome format expected: (M or MM)/(D or DD)/YY
|
||||
var expected = this.$filter('date')((input + this.sevenDaysAgo) * this.miliSecondsToSeconds, 'shortDate') |
||||
var result = this.dateOrTimeFilter(input + this.sevenDaysAgo, false) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('can display the medium-size date based on timestamp', function () { |
||||
var input = tsNow(true) |
||||
// Outcome format expected: Month(3 letters) Day, Year
|
||||
var expected = this.$filter('date')((input + this.sevenDaysAgo) * this.miliSecondsToSeconds, 'mediumDate') |
||||
var result = this.dateOrTimeFilter(input + this.sevenDaysAgo, true) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('can display the day of the week (in short) based on timestamp', function () { |
||||
var input = tsNow(true) |
||||
// Outcome format expcected: Day of week in three letters (Mon, Tue, etc.)
|
||||
var expected = this.$filter('date')((input + this.thirteenHoursAgo) * this.miliSecondsToSeconds, 'EEE') |
||||
var result = this.dateOrTimeFilter(input + this.thirteenHoursAgo, false) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('can display the day of the week based on timestamp', function () { |
||||
var input = tsNow(true) |
||||
// Outcome format expcected: Day of week (Monday, Tuesday, etc.)
|
||||
var expected = this.$filter('date')((input + this.thirteenHoursAgo) * this.miliSecondsToSeconds, 'EEEE') |
||||
var result = this.dateOrTimeFilter(input + this.thirteenHoursAgo, true) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
}) |
@ -0,0 +1,60 @@
@@ -0,0 +1,60 @@
|
||||
'use strict' |
||||
/* global describe, it, inject, expect, beforeEach */ |
||||
|
||||
describe('duration filter', function () { |
||||
beforeEach(module('myApp.filters')) |
||||
|
||||
beforeEach(inject(function (_$filter_) { |
||||
this.$filter = _$filter_ |
||||
})) |
||||
|
||||
beforeEach(function () { |
||||
this.durationFilter = this.$filter('duration') |
||||
}) |
||||
|
||||
it('converts duration in seconds to a readable string', function () { |
||||
var input = 55 |
||||
var expected = '0:55' |
||||
var result = this.durationFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
|
||||
input = 147 |
||||
expected = '2:27' |
||||
result = this.durationFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('converts hours in seconds to readable string', function () { |
||||
var input = 7282 |
||||
var expected = '2:01:22' |
||||
var result = this.durationFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
|
||||
input = 4201 |
||||
expected = '1:10:01' |
||||
result = this.durationFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('returns "zero" when not a valid input was given', function () { |
||||
var input = 'not a number' |
||||
var expected = '0:00' |
||||
var result = this.durationFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
|
||||
input = {} |
||||
result = this.durationFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
|
||||
input = [] |
||||
result = this.durationFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
}) |
@ -0,0 +1,25 @@
@@ -0,0 +1,25 @@
|
||||
'use strict' |
||||
/* global describe, it, inject, expect, beforeEach */ |
||||
|
||||
describe('durationRemains filter', function () { |
||||
beforeEach(module('myApp.filters')) |
||||
|
||||
beforeEach(inject(function (_$filter_) { |
||||
this.$filter = _$filter_ |
||||
})) |
||||
|
||||
beforeEach(function () { |
||||
this.durationRemainsFilter = this.$filter('durationRemains') |
||||
}) |
||||
|
||||
it('creates a readable string based on time and total time', function () { |
||||
var totalTime = 120 // two minutes
|
||||
var currentTime = 100 |
||||
var expected = '-0:20' |
||||
var result = this.durationRemainsFilter(currentTime, totalTime) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
// Other behaviour is tested in durationFilterSpec.js
|
||||
}) |
@ -0,0 +1,75 @@
@@ -0,0 +1,75 @@
|
||||
'use strict' |
||||
/* global describe, it, inject, expect, beforeEach */ |
||||
|
||||
describe('formatShortNumber filter', function () { |
||||
beforeEach(module('myApp.filters')) |
||||
|
||||
beforeEach(inject(function (_$filter_) { |
||||
this.$filter = _$filter_ |
||||
})) |
||||
|
||||
beforeEach(function () { |
||||
this.formatShortNumberFilter = this.$filter('formatShortNumber') |
||||
}) |
||||
|
||||
it('converts zero or undefined', function () { |
||||
var input = 0 |
||||
var expected = '0' |
||||
var result = this.formatShortNumberFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
|
||||
input = undefined |
||||
result = this.formatShortNumberFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('converts numbers below 1000 to string with same value', function () { |
||||
var input = 127 |
||||
var expected = '127' |
||||
var result = this.formatShortNumberFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
|
||||
input = 999 |
||||
expected = '999' |
||||
result = this.formatShortNumberFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('converts numbers between 1000 and 900000 to string with shortened value', function () { |
||||
var input = 1276 |
||||
var expected = '1.3K' |
||||
var result = this.formatShortNumberFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
|
||||
input = 35444 |
||||
expected = '35K' |
||||
result = this.formatShortNumberFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
|
||||
input = 899999 |
||||
expected = '900K' |
||||
result = this.formatShortNumberFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('converts numbers above 900000 to string with shortened value', function () { |
||||
var input = 900000 |
||||
var expected = '0.9M' |
||||
var result = this.formatShortNumberFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
|
||||
input = 76785646867 |
||||
expected = '76786M' |
||||
result = this.formatShortNumberFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
}) |
@ -0,0 +1,76 @@
@@ -0,0 +1,76 @@
|
||||
'use strict' |
||||
/* global describe, it, inject, expect, beforeEach */ |
||||
|
||||
describe('formatSize filter', function () { |
||||
beforeEach(module('myApp.filters')) |
||||
|
||||
beforeEach(inject(function (_$filter_) { |
||||
this.$filter = _$filter_ |
||||
})) |
||||
|
||||
beforeEach(function () { |
||||
this.formatSizeFilter = this.$filter('formatSize') |
||||
}) |
||||
|
||||
it('converts zero', function () { |
||||
var input = 0 |
||||
var expected = '0' |
||||
var result = this.formatSizeFilter(input, false) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('converts sizes below 1024 to byte', function () { |
||||
var input = 234 |
||||
var expected = '234 b' |
||||
var result = this.formatSizeFilter(input, false) |
||||
|
||||
expect(result).toBe(expected) |
||||
|
||||
input = 1023 |
||||
expected = '1023 b' |
||||
result = this.formatSizeFilter(input, false) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('converts sizes between 1024 and 1048576 to KB', function () { |
||||
var input = 238994 |
||||
var expected = '233 KB' |
||||
var result = this.formatSizeFilter(input, false) |
||||
|
||||
expect(result).toBe(expected) |
||||
|
||||
input = 1048575 |
||||
expected = '1024 KB' |
||||
result = this.formatSizeFilter(input, false) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('converts sizes above 1048576 to MB', function () { |
||||
var input = 10485726 |
||||
var expected = '10 MB' |
||||
var result = this.formatSizeFilter(input, false) |
||||
|
||||
expect(result).toBe(expected) |
||||
|
||||
input = 1048572676967876 |
||||
expected = '999996830.9 MB' |
||||
result = this.formatSizeFilter(input, false) |
||||
|
||||
expect(result).toBe(expected) |
||||
|
||||
input = 10485726 |
||||
expected = '10.0 MB' |
||||
result = this.formatSizeFilter(input, true) |
||||
|
||||
expect(result).toBe(expected) |
||||
|
||||
input = 1048572676967876 |
||||
expected = '999996830.9 MB' |
||||
result = this.formatSizeFilter(input, true) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
}) |
@ -0,0 +1,41 @@
@@ -0,0 +1,41 @@
|
||||
'use strict' |
||||
/* global describe, it, inject, expect, beforeEach */ |
||||
|
||||
describe('formatSizeProgress filter', function () { |
||||
beforeEach(module('myApp.filters')) |
||||
|
||||
beforeEach(inject(function (_$filter_, ___) { |
||||
this.$filter = _$filter_ |
||||
this._ = ___ |
||||
})) |
||||
|
||||
beforeEach(function () { |
||||
this.formatSizeProgressFilter = this.$filter('formatSizeProgress') |
||||
}) |
||||
|
||||
it('can handle "zero"-input', function () { |
||||
var input = { total: 0 } |
||||
var expected = '' |
||||
var result = this.formatSizeProgressFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('can format progress with different scale of magnitude', function () { |
||||
var input = { total: 1024, done: 1023 } |
||||
var expected = this._('format_size_progress', {done: '1023 b', total: '1 KB'}) |
||||
var result = this.formatSizeProgressFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('can format progress with the same scale of size', function () { |
||||
var input = { total: 2048, done: 1024 } |
||||
var expected = this._('format_size_progress_mulitple', {done: '1', total: '2', parts: 'KB'}) |
||||
var result = this.formatSizeProgressFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
// Further testing for options is done in formatSizeFilterSpec.js
|
||||
}) |
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
'use strict' |
||||
/* global describe, it, inject, expect, beforeEach */ |
||||
|
||||
describe('myDate filter', function () { |
||||
beforeEach(module('myApp.filters')) |
||||
|
||||
beforeEach(inject(function (_$filter_) { |
||||
this.$filter = _$filter_ |
||||
})) |
||||
|
||||
beforeEach(function () { |
||||
this.myDateFilter = this.$filter('myDate') |
||||
}) |
||||
|
||||
it('can create a date based on timestamp', function () { |
||||
var input = 1222222222 |
||||
var expected = 'Wednesday, September 24, 2008' |
||||
var result = this.myDateFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('can recollect a date based on timestamp', function () { |
||||
var input = 12111114111 |
||||
var expected = 'Thursday, October 15, 2353' |
||||
var result1 = this.myDateFilter(input) |
||||
|
||||
expect(result1).toBe(expected) |
||||
|
||||
var result2 = this.myDateFilter(input) |
||||
|
||||
expect(result2).toBe(expected) |
||||
}) |
||||
}) |
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
'use strict' |
||||
/* global describe, it, inject, expect, beforeEach */ |
||||
|
||||
describe('nl2br filter', function () { |
||||
beforeEach(module('myApp.filters')) |
||||
|
||||
beforeEach(inject(function (_$filter_, ___) { |
||||
this.$filter = _$filter_ |
||||
})) |
||||
|
||||
beforeEach(function () { |
||||
this.nl2brFilter = this.$filter('nl2br') |
||||
}) |
||||
|
||||
it('replaces an enter by a break-tag', function () { |
||||
var input = 'Line one \n Line 2' |
||||
var expected = 'Line one <br/> Line 2' |
||||
var result = this.nl2brFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('replaces enters by break-tags', function () { |
||||
var input = 'Line one \n Line 2 \n Line 3' |
||||
var expected = 'Line one <br/> Line 2 <br/> Line 3' |
||||
var result = this.nl2brFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('does not change the text if no enter is present', function () { |
||||
var input, expected |
||||
input = expected = 'Some random line with no enters' |
||||
var result = this.nl2brFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
}) |
@ -0,0 +1,49 @@
@@ -0,0 +1,49 @@
|
||||
'use strict' |
||||
/* global describe, it, inject, expect, beforeEach */ |
||||
|
||||
describe('phoneNumber filter', function () { |
||||
beforeEach(module('myApp.filters')) |
||||
|
||||
beforeEach(inject(function (_$filter_) { |
||||
this.$filter = _$filter_ |
||||
})) |
||||
|
||||
beforeEach(function () { |
||||
this.phoneNumberFilter = this.$filter('phoneNumber') |
||||
}) |
||||
|
||||
it('can handle "zero" values', function () { |
||||
var input |
||||
var expected = '+' |
||||
var result = this.phoneNumberFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
|
||||
input = null |
||||
result = this.phoneNumberFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
|
||||
input = 0 |
||||
result = this.phoneNumberFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('removes all non-digits from a phoneNumber', function () { |
||||
var input = '123nonnumber333333e3' |
||||
var expected = '+1233333333' |
||||
var result = this.phoneNumberFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('converts phone number to a readable phone number (for Russia)', function () { |
||||
// 7 is for russian Country calling code (https://en.wikipedia.org/wiki/Telephone_numbers_in_Europe)
|
||||
var input = '71234567890' |
||||
var expected = '+7 (123) 456-78-90' |
||||
var result = this.phoneNumberFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
}) |
@ -0,0 +1,62 @@
@@ -0,0 +1,62 @@
|
||||
'use strict' |
||||
/* global describe, it, inject, expect, beforeEach, jasmine, tsNow*/ |
||||
|
||||
describe('relativeTime filter', function () { |
||||
beforeEach(module('myApp.filters')) |
||||
|
||||
beforeEach(inject(function (_$filter_, ___) { |
||||
this.$filter = _$filter_ |
||||
this._ = ___ |
||||
})) |
||||
|
||||
beforeEach(function () { |
||||
this.minuteSpy = jasmine.createSpy() |
||||
this.hourSpy = jasmine.createSpy() |
||||
// local vars are used to prevent scoping problems
|
||||
var ms = this.minuteSpy |
||||
var hs = this.hourSpy |
||||
this._.pluralize = function (msgid) { |
||||
if (msgid === 'relative_time_pluralize_minutes_ago') { |
||||
return ms |
||||
} else if (msgid === 'relative_time_pluralize_hours_ago') { |
||||
return hs |
||||
} |
||||
} |
||||
|
||||
this.relativeTimeFilter = this.$filter('relativeTime', {$filter: this.$filter, _: this._}) |
||||
}) |
||||
|
||||
it('can mark time as "just now"', function () { |
||||
var input = tsNow(true) |
||||
var expected = this._('relative_time_just_now') |
||||
var result = this.relativeTimeFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
// because the exact of tsNow in hard to estimate, a Spy is used instead of checking the return value
|
||||
it('can convert time that is max. 1 hour away', function () { |
||||
var input = tsNow(true) - 3500 |
||||
this.relativeTimeFilter(input) |
||||
|
||||
expect(this.minuteSpy).toHaveBeenCalled() |
||||
}) |
||||
|
||||
// because the exact of tsNow in hard to estimate, a Spy is used instead of checking the return value
|
||||
it('can convert time that is max. 24 hours away', function () { |
||||
var input = tsNow(true) - 86000 |
||||
this.relativeTimeFilter(input) |
||||
|
||||
expect(this.hourSpy).toHaveBeenCalled() |
||||
}) |
||||
|
||||
it('can convert time after 24 hours based on timestamp', function () { |
||||
var input = tsNow(true) - 1000000 |
||||
var expected = this.$filter('dateOrTime')(input, true) |
||||
var result = this.relativeTimeFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
// Further testing on the dateOrTimeFilter is present in dateOrTimeFilterSpec.js
|
||||
}) |
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
'use strict' |
||||
/* global describe, it, inject, expect, beforeEach */ |
||||
|
||||
describe('richText filter', function () { |
||||
beforeEach(module('myApp.filters')) |
||||
beforeEach(module('ngSanitize')) // necessary for linky filter
|
||||
|
||||
beforeEach(inject(function (_$filter_) { |
||||
this.$filter = _$filter_ |
||||
})) |
||||
|
||||
beforeEach(function () { |
||||
this.richTextFilter = this.$filter('richText') |
||||
}) |
||||
|
||||
it('changes url to actual link', function () { |
||||
var input = 'a text that links to https://www.github.com' |
||||
var expected = 'a text that links to <a target="_blank" href="https://www.github.com">https://www.github.com</a>' |
||||
var result = this.richTextFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('changes urls to actual links', function () { |
||||
var input = 'a text that links to https://www.github.com and https://www.github.com/zhukov/webogram' |
||||
var expected = 'a text that links to <a target="_blank" href="https://www.github.com">https://www.github.com</a> and <a target="_blank" href="https://www.github.com/zhukov/webogram">https://www.github.com/zhukov/webogram</a>' |
||||
var result = this.richTextFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
}) |
@ -0,0 +1,81 @@
@@ -0,0 +1,81 @@
|
||||
'use strict' |
||||
/* global describe, it, inject, expect, beforeEach */ |
||||
|
||||
describe('shortUrl filter', function () { |
||||
beforeEach(module('myApp.filters')) |
||||
|
||||
beforeEach(inject(function (_$filter_) { |
||||
this.$filter = _$filter_ |
||||
})) |
||||
|
||||
beforeEach(function () { |
||||
this.shortUrlFilter = this.$filter('shortUrl') |
||||
}) |
||||
|
||||
it('does not do anything if the input is not a string', function () { |
||||
var input = {} |
||||
var expected = input |
||||
var result = this.shortUrlFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
|
||||
input = [] |
||||
expected = input |
||||
result = this.shortUrlFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
|
||||
input = 11 |
||||
expected = input |
||||
result = this.shortUrlFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('removes "http(s)" from a Url', function () { |
||||
var input = 'https://github.com' |
||||
var expected = 'github.com' |
||||
var result = this.shortUrlFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
|
||||
input = 'http://github.com' |
||||
result = this.shortUrlFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('does not remove other protocols from a Url', function () { |
||||
var input, expected |
||||
input = expected = 'ftp://github.com' |
||||
var result = this.shortUrlFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
|
||||
input = expected = 'irc://github.com' |
||||
result = this.shortUrlFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
|
||||
input = expected = 'tg://github.com' |
||||
result = this.shortUrlFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('removes "www." from a Url', function () { |
||||
var input = 'www.github.com' |
||||
var expected = 'github.com' |
||||
var result = this.shortUrlFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('removes "https://" and "www." from a Url', function () { |
||||
var input = 'https://www.github.com' |
||||
var expected = 'github.com' |
||||
var result = this.shortUrlFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
}) |
@ -0,0 +1,64 @@
@@ -0,0 +1,64 @@
|
||||
'use strict' |
||||
/* global describe, it, inject, expect, beforeEach, Config */ |
||||
|
||||
describe('time filter', function () { |
||||
beforeEach(module('myApp.filters')) |
||||
|
||||
beforeEach(inject(function (_$filter_) { |
||||
this.$filter = _$filter_ |
||||
})) |
||||
|
||||
describe('on the mobile website', function () { |
||||
beforeEach(function () { |
||||
Config.Mobile = true |
||||
this.timeFilter = this.$filter('time') |
||||
}) |
||||
|
||||
it('can create a short time based on timestamp', function () { |
||||
var input = 1222 |
||||
var expected = '1:20 AM' |
||||
var result = this.timeFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('can recollect a short time based on timestamp', function () { |
||||
var input = 121155 |
||||
var expected = '10:39 AM' |
||||
var result1 = this.timeFilter(input) |
||||
|
||||
expect(result1).toBe(expected) |
||||
|
||||
var result2 = this.timeFilter(input) |
||||
|
||||
expect(result2).toBe(expected) |
||||
}) |
||||
}) |
||||
|
||||
describe('on the desktop website', function () { |
||||
beforeEach(function () { |
||||
Config.Mobile = false |
||||
this.timeFilter = this.$filter('time') |
||||
}) |
||||
|
||||
it('can create a medium-size time based on timestamp', function () { |
||||
var input = 1222 |
||||
var expected = '1:20:22 AM' |
||||
var result = this.timeFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('can recollect a medium-size time on timestamp', function () { |
||||
var input = 121155 |
||||
var expected = '10:39:15 AM' |
||||
var result1 = this.timeFilter(input) |
||||
|
||||
expect(result1).toBe(expected) |
||||
|
||||
var result2 = this.timeFilter(input) |
||||
|
||||
expect(result2).toBe(expected) |
||||
}) |
||||
}) |
||||
}) |
@ -0,0 +1,141 @@
@@ -0,0 +1,141 @@
|
||||
'use strict' |
||||
/* global describe, it, inject, expect, beforeEach , tsNow*/ |
||||
|
||||
describe('userStatus filter', function () { |
||||
beforeEach(module('myApp.filters')) |
||||
|
||||
beforeEach(inject(function (_$filter_, ___) { |
||||
this.$filter = _$filter_ |
||||
this._ = ___ |
||||
})) |
||||
|
||||
beforeEach(function () { |
||||
this.userStatusFilter = this.$filter('userStatus') |
||||
}) |
||||
|
||||
it('can recognize support users', function () { |
||||
var input = { id: 1000 } |
||||
var expected = this._('user_status_support') |
||||
var result = this.userStatusFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('can recognize service notifications', function () { |
||||
// id 777000 is the id of the service notifications channel
|
||||
var input = { id: 777000 } |
||||
var expected = this._('user_status_service_notifications') |
||||
var result = this.userStatusFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
describe('when the user is not a bot, it', function () { |
||||
it('can handle empty user statuses', function () { |
||||
var input = null |
||||
var expected = this._('user_status_long_ago') |
||||
var result = this.userStatusFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
|
||||
input = { id: 12321 } |
||||
result = this.userStatusFilter(input) |
||||
expect(result).toBe(expected) |
||||
|
||||
input = { id: 12321, status: {} } |
||||
result = this.userStatusFilter(input) |
||||
expect(result).toBe(expected) |
||||
|
||||
input = { id: 12321, status: {_: null} } |
||||
result = this.userStatusFilter(input) |
||||
expect(result).toBe(expected) |
||||
|
||||
input = { id: 12321, status: {_: null}, pFlag: {} } |
||||
result = this.userStatusFilter(input) |
||||
expect(result).toBe(expected) |
||||
|
||||
input = { id: 12321, status: {_: null}, pFlags: {bot: false} } |
||||
result = this.userStatusFilter(input) |
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('can display an online status', function () { |
||||
var input = { id: 12321, status: {_: 'userStatusOnline'} } |
||||
var expected = this._('user_status_online') |
||||
var result = this.userStatusFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('can display that the user was recently online', function () { |
||||
var input = { id: 12321, status: {_: 'userStatusRecently'} } |
||||
var expected = this._('user_status_recently') |
||||
var result = this.userStatusFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('can display that the user was offline since a certain time', function () { |
||||
var time = tsNow(true) - 360000 // 100 hours ago
|
||||
var relativeTimeFilter = this.$filter('relativeTime') |
||||
var input = { id: 12321, status: {_: 'userStatusOffline', was_online: time} } |
||||
var expected = this._('user_status_last_seen', relativeTimeFilter(time)) |
||||
var result = this.userStatusFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
// Further testing of relativeTimeFilter is done in relativeTimeFilterSpec.js
|
||||
|
||||
it('can display that the user was online last week', function () { |
||||
var input = { id: 12321, status: {_: 'userStatusLastWeek'} } |
||||
var expected = this._('user_status_last_week') |
||||
var result = this.userStatusFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('can display that the user was online last month', function () { |
||||
var input = { id: 12321, status: {_: 'userStatusLastMonth'} } |
||||
var expected = this._('user_status_last_month') |
||||
var result = this.userStatusFilter(input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
}) |
||||
|
||||
describe('when the user is a bot', function () { |
||||
beforeEach(function () { |
||||
this.input = { id: 12321, status: {_: null}, pFlags: {bot: true} } |
||||
}) |
||||
|
||||
it('it can tell that the user is a bot', function () { |
||||
var expected = this._('user_status_bot') |
||||
var result = this.userStatusFilter(this.input) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
describe('and the bot has privacy settings', function () { |
||||
beforeEach(function () { |
||||
this.privacySettings = true |
||||
}) |
||||
|
||||
it('it can tell that it is a bot with no acces to messages', function () { |
||||
var expected = this._('user_status_bot_privacy') |
||||
var result = this.userStatusFilter(this.input, this.privacySettings) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
|
||||
it('it can tell that it is a bot with acces to messages', function () { |
||||
// Flags indicate true/false
|
||||
this.input.pFlags.bot_chat_history = true |
||||
var expected = this._('user_status_bot_noprivacy') |
||||
var result = this.userStatusFilter(this.input, this.privacySettings) |
||||
|
||||
expect(result).toBe(expected) |
||||
}) |
||||
}) |
||||
}) |
||||
}) |
Loading…
Reference in new issue