forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [2U-530] added alphabetically sorting for course list (#58)
* feat: added alphabetically sorting for course list * refactor: sorted all tabs * refactor: added tests
- Loading branch information
1 parent
079261b
commit 5880bfb
Showing
5 changed files
with
44 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* Alphabetical sorting for arrays of courses and libraries. | ||
* | ||
* @param {array} arr - Array of courses or libraries. | ||
* @returns {array} - An array of alphabetically sorted courses or libraries. | ||
*/ | ||
const sortAlphabeticallyArray = (arr) => [...arr] | ||
.sort((firstArrayData, secondArrayData) => firstArrayData | ||
.displayName.localeCompare(secondArrayData.displayName)); | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export { sortAlphabeticallyArray }; |
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,26 @@ | ||
import { sortAlphabeticallyArray } from './utils'; | ||
|
||
const testData = [ | ||
{ displayName: 'Apple' }, | ||
{ displayName: 'Orange' }, | ||
{ displayName: 'Banana' }, | ||
]; | ||
|
||
describe('sortAlphabeticallyArray', () => { | ||
it('sortAlphabeticallyArray sorts array alphabetically', () => { | ||
const sortedData = sortAlphabeticallyArray(testData); | ||
|
||
expect(sortedData).toEqual([ | ||
{ displayName: 'Apple' }, | ||
{ displayName: 'Banana' }, | ||
{ displayName: 'Orange' }, | ||
]); | ||
}); | ||
|
||
it('sortAlphabeticallyArray does not mutate the original array', () => { | ||
const originalData = [...testData]; | ||
sortAlphabeticallyArray(testData); | ||
|
||
expect(testData).toEqual(originalData); | ||
}); | ||
}); |