diff options
author | Lukas Reschke <lukas@owncloud.com> | 2014-09-16 17:29:03 +0200 |
---|---|---|
committer | Lukas Reschke <lukas@owncloud.com> | 2014-09-16 17:29:03 +0200 |
commit | d2743e6ad66ba6827a0e49487ed83667671895c8 (patch) | |
tree | 1d50bf0f5364779e3f9e407a126d5694e69f4f00 /core/js/tests | |
parent | 4669ea38357f3f33caaf056d859e6318b75b72e1 (diff) | |
parent | f2001a48a4e91bc6427a2a63ba9022ceaf1d305d (diff) | |
download | nextcloud-server-d2743e6ad66ba6827a0e49487ed83667671895c8.tar.gz nextcloud-server-d2743e6ad66ba6827a0e49487ed83667671895c8.zip |
Merge pull request #7254 from owncloud/core-sortalgo
Fixed JS sort comparator to be consistent between JS and PHP
Diffstat (limited to 'core/js/tests')
-rw-r--r-- | core/js/tests/specHelper.js | 2 | ||||
-rw-r--r-- | core/js/tests/specs/coreSpec.js | 159 |
2 files changed, 161 insertions, 0 deletions
diff --git a/core/js/tests/specHelper.js b/core/js/tests/specHelper.js index 66e5d3578b2..b62a0efe40d 100644 --- a/core/js/tests/specHelper.js +++ b/core/js/tests/specHelper.js @@ -77,6 +77,8 @@ window.Snap.prototype = { close: function() {} }; +window.isPhantom = /phantom/i.test(navigator.userAgent); + // global setup for all tests (function setupTests() { var fakeServer = null, diff --git a/core/js/tests/specs/coreSpec.js b/core/js/tests/specs/coreSpec.js index c61528f6686..2c5c22905b0 100644 --- a/core/js/tests/specs/coreSpec.js +++ b/core/js/tests/specs/coreSpec.js @@ -496,5 +496,164 @@ describe('Core base tests', function() { }); }); }); + describe('naturalSortCompare', function() { + // cit() will skip tests if running on PhantomJS because it has issues with + // localeCompare(). See https://github.com/ariya/phantomjs/issues/11063 + // + // Please make sure to run these tests in Chrome/Firefox manually + // to make sure they run. + var cit = window.isPhantom?xit:it; + + // must provide the same results as \OC_Util::naturalSortCompare + it('sorts alphabetically', function() { + var a = [ + 'def', + 'xyz', + 'abc' + ]; + a.sort(OC.Util.naturalSortCompare); + expect(a).toEqual([ + 'abc', + 'def', + 'xyz' + ]); + }); + cit('sorts with different casing', function() { + var a = [ + 'aaa', + 'bbb', + 'BBB', + 'AAA' + ]; + a.sort(OC.Util.naturalSortCompare); + expect(a).toEqual([ + 'aaa', + 'AAA', + 'bbb', + 'BBB' + ]); + }); + it('sorts with numbers', function() { + var a = [ + '124.txt', + 'abc1', + '123.txt', + 'abc', + 'abc2', + 'def (2).txt', + 'ghi 10.txt', + 'abc12', + 'def.txt', + 'def (1).txt', + 'ghi 2.txt', + 'def (10).txt', + 'abc10', + 'def (12).txt', + 'z', + 'ghi.txt', + 'za', + 'ghi 1.txt', + 'ghi 12.txt', + 'zz', + '15.txt', + '15b.txt' + ]; + a.sort(OC.Util.naturalSortCompare); + expect(a).toEqual([ + '15.txt', + '15b.txt', + '123.txt', + '124.txt', + 'abc', + 'abc1', + 'abc2', + 'abc10', + 'abc12', + 'def.txt', + 'def (1).txt', + 'def (2).txt', + 'def (10).txt', + 'def (12).txt', + 'ghi.txt', + 'ghi 1.txt', + 'ghi 2.txt', + 'ghi 10.txt', + 'ghi 12.txt', + 'z', + 'za', + 'zz' + ]); + }); + it('sorts with chinese characters', function() { + var a = [ + '十.txt', + '一.txt', + '二.txt', + '十 2.txt', + '三.txt', + '四.txt', + 'abc.txt', + '五.txt', + '七.txt', + '八.txt', + '九.txt', + '六.txt', + '十一.txt', + '波.txt', + '破.txt', + '莫.txt', + '啊.txt', + '123.txt' + ]; + a.sort(OC.Util.naturalSortCompare); + expect(a).toEqual([ + '123.txt', + 'abc.txt', + '一.txt', + '七.txt', + '三.txt', + '九.txt', + '二.txt', + '五.txt', + '八.txt', + '六.txt', + '十.txt', + '十 2.txt', + '十一.txt', + '啊.txt', + '四.txt', + '波.txt', + '破.txt', + '莫.txt' + ]); + }); + cit('sorts with umlauts', function() { + var a = [ + 'öh.txt', + 'Äh.txt', + 'oh.txt', + 'Üh 2.txt', + 'Üh.txt', + 'ah.txt', + 'Öh.txt', + 'uh.txt', + 'üh.txt', + 'äh.txt' + ]; + a.sort(OC.Util.naturalSortCompare); + expect(a).toEqual([ + 'ah.txt', + 'äh.txt', + 'Äh.txt', + 'oh.txt', + 'öh.txt', + 'Öh.txt', + 'uh.txt', + 'üh.txt', + 'Üh.txt', + 'Üh 2.txt' + ]); + }); + }); }); |