-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(editor): Fix sorting problem in older browsers that don't support…
… `toSorted` (#11204)
- Loading branch information
Showing
7 changed files
with
110 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { sortByProperty } from '@/utils/sortUtils'; | ||
|
||
const arrayOfObjects = [ | ||
{ name: 'Álvaro', age: 30 }, | ||
{ name: 'Élodie', age: 28 }, | ||
{ name: 'Željko', age: 25 }, | ||
{ name: 'Bob', age: 35 }, | ||
]; | ||
|
||
describe('sortUtils', () => { | ||
it('"sortByProperty" should sort an array of objects by a property', () => { | ||
const sortedArray = sortByProperty('name', arrayOfObjects); | ||
expect(sortedArray).toEqual([ | ||
{ name: 'Álvaro', age: 30 }, | ||
{ name: 'Bob', age: 35 }, | ||
{ name: 'Élodie', age: 28 }, | ||
{ name: 'Željko', age: 25 }, | ||
]); | ||
}); | ||
|
||
it('"sortByProperty" should sort an array of objects by a property in descending order', () => { | ||
const sortedArray = sortByProperty('name', arrayOfObjects, 'desc'); | ||
expect(sortedArray).toEqual([ | ||
{ name: 'Željko', age: 25 }, | ||
{ name: 'Élodie', age: 28 }, | ||
{ name: 'Bob', age: 35 }, | ||
{ name: 'Álvaro', age: 30 }, | ||
]); | ||
}); | ||
|
||
it('"sortByProperty" should sort an array of objects by a property if its number', () => { | ||
const sortedArray = sortByProperty('age', arrayOfObjects); | ||
expect(sortedArray).toEqual([ | ||
{ name: 'Željko', age: 25 }, | ||
{ name: 'Élodie', age: 28 }, | ||
{ name: 'Álvaro', age: 30 }, | ||
{ name: 'Bob', age: 35 }, | ||
]); | ||
}); | ||
|
||
it('"sortByProperty" should sort an array of objects by a property in descending order if its number', () => { | ||
const sortedArray = sortByProperty('age', arrayOfObjects, 'desc'); | ||
expect(sortedArray).toEqual([ | ||
{ name: 'Bob', age: 35 }, | ||
{ name: 'Álvaro', age: 30 }, | ||
{ name: 'Élodie', age: 28 }, | ||
{ name: 'Željko', age: 25 }, | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters