From 5ba6f04bae27136430ab2a5c35c05e221538ec0c Mon Sep 17 00:00:00 2001 From: Tucker McKnight Date: Mon, 8 Feb 2021 23:11:33 -0700 Subject: Fix incorrect article sorting Currently, an article with an ID of 1000 will show up earlier than one with ID = 900, because the IDs are being treated as strings and compared alphabetically. (1 comes before 9, and the comparison stops there.) We need to parse them as integers to ensure that 900 is less than 1000. Signed-off-by: Tucker McKnight --- js/tests/unit/controller/ContentControllerSpec.js | 38 +++++++++-------------- 1 file changed, 15 insertions(+), 23 deletions(-) (limited to 'js/tests') diff --git a/js/tests/unit/controller/ContentControllerSpec.js b/js/tests/unit/controller/ContentControllerSpec.js index 2e49e74db..e8992ca8c 100644 --- a/js/tests/unit/controller/ContentControllerSpec.js +++ b/js/tests/unit/controller/ContentControllerSpec.js @@ -64,27 +64,19 @@ describe('ContentController', function () { })); - it('should return order by', - inject(function ($controller, SettingsResource, FEED_TYPE) { - var route = { - current: { - $$route: { - type: FEED_TYPE.FOLDER - } - } - }; - - var ctrl = $controller('ContentController', { - data: {}, - $route: route - }); - - expect(ctrl.orderBy()).toBe('-id'); - - SettingsResource.set('oldestFirst', true); + it('should sort feed items', inject(function ($controller) { + var ctrl = $controller('ContentController', { + data: {} + }); + var first = {value: 11, type: 'number'}; + var second = {value: 12, type: 'number'}; + var third = {value: 101, type: 'number'}; + expect(ctrl.sortIds(first, second)).toBe(1); + expect(ctrl.sortIds(second, first)).toBe(-1); + expect(ctrl.sortIds(second, second)).toBe(-1); + expect(ctrl.sortIds(first, third)).toBe(1); + })); - expect(ctrl.orderBy()).toBe('id'); - })); it('should return order if custom ordering', inject(function ($controller, SettingsResource, FeedResource, @@ -107,11 +99,11 @@ describe('ContentController', function () { } }); - expect(ctrl.orderBy()).toBe('id'); + expect(ctrl.oldestFirst).toBe(true); - SettingsResource.set('oldestFirst', true); + SettingsResource.set('oldestFirst', false); - expect(ctrl.orderBy()).toBe('id'); + expect(ctrl.oldestFirst).toBe(true); })); -- cgit v1.2.3