Skip to content

Commit

Permalink
fix(PageList): Sort numbers numeric (2 > 10)
Browse files Browse the repository at this point in the history
Fixes: #1447

Signed-off-by: Jonas <[email protected]>
  • Loading branch information
mejo- committed Sep 4, 2024
1 parent 5580306 commit df90a98
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
40 changes: 39 additions & 1 deletion src/tests/util/sortOrders.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,45 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { byOrder } from '../../util/sortOrders.js'
import { byName, byTitle, byOrder } from '../../util/sortOrders.js'

global.OC = {
getLanguage: () => 'en',
}

test('by name', () => {
const unsorted = [
{ name: '2' },
{ name: 'a' },
{ name: '10' },
{ name: '1' },
]
const sorted = [
{ name: '1' },
{ name: '2' },
{ name: '10' },
{ name: 'a' },
]
expect(unsorted.sort(byName))
.toStrictEqual(sorted)
})

test('by title', () => {
const unsorted = [
{ title: '2' },
{ title: 'a' },
{ title: '10' },
{ title: '1' },
]
const sorted = [
{ title: '1' },
{ title: '2' },
{ title: '10' },
{ title: 'a' },
]
expect(unsorted.sort(byTitle))
.toStrictEqual(sorted)
})

test('by indices', () => {
const one = { index: 0 }
Expand Down
4 changes: 2 additions & 2 deletions src/util/sortOrders.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

const byName = (a, b) => a.name.localeCompare(b.name, OC.getLanguage())
const byTitle = (a, b) => a.title.localeCompare(b.title, OC.getLanguage())
const byName = (a, b) => a.name.localeCompare(b.name, OC.getLanguage(), { numeric: true })
const byTitle = (a, b) => a.title.localeCompare(b.title, OC.getLanguage(), { numeric: true })
const byTimestamp = (a, b) => b.timestamp - a.timestamp

const byOrder = (a, b) => {
Expand Down

0 comments on commit df90a98

Please sign in to comment.