diff --git a/client/src/templates/Challenges/classic/Editor.js b/client/src/templates/Challenges/classic/Editor.js index 710ff448bd..72d84b46eb 100644 --- a/client/src/templates/Challenges/classic/Editor.js +++ b/client/src/templates/Challenges/classic/Editor.js @@ -16,7 +16,7 @@ import { } from '../redux'; import { userSelector, isDonationModalOpenSelector } from '../../../redux'; import { Loader } from '../../../components/helpers'; -import { sortFiles } from '../../../../../utils/sort-files'; +import { toSortedArray } from '../../../../../utils/sort-files'; import './editor.css'; @@ -164,7 +164,7 @@ class Editor extends Component { // NOTE: the ARIA state is controlled by fileKey, so changes to it must // trigger a re-render. Hence state: this.state = { - fileKey: sortFiles(challengeFiles)[0].key + fileKey: toSortedArray(challengeFiles)[0].key }; this.options = { diff --git a/curriculum/test/test-challenges.js b/curriculum/test/test-challenges.js index 4b3a5e865f..9cae567b65 100644 --- a/curriculum/test/test-challenges.js +++ b/curriculum/test/test-challenges.js @@ -42,7 +42,7 @@ const { } = require('../../client/utils/challengeTypes'); const { dasherize } = require('../../utils/slugs'); -const { sortFiles } = require('../../utils/sort-files'); +const { toSortedArray } = require('../../utils/sort-files'); const { testedLang } = require('../utils'); @@ -423,7 +423,7 @@ async function createTestRunner(challenge, solution, buildChallenge) { }); } else if (solution) { // fallback for single solution - const sortedFiles = sortFiles(files); + const sortedFiles = toSortedArray(files); files[sortedFiles[0].key].contents = solution; } else { diff --git a/utils/sort-files.js b/utils/sort-files.js index c94f8ae98c..443cab4481 100644 --- a/utils/sort-files.js +++ b/utils/sort-files.js @@ -1,4 +1,4 @@ -exports.sortFiles = function sortFiles(challengeFiles) { +exports.toSortedArray = function toSortedArray(challengeFiles) { const xs = Object.values(challengeFiles); // TODO: refactor this to use an ext array ['html', 'js', 'css'] and loop over // that. diff --git a/utils/sort-files.test.js b/utils/sort-files.test.js index 68b62e09c3..244caf6397 100644 --- a/utils/sort-files.test.js +++ b/utils/sort-files.test.js @@ -1,23 +1,23 @@ /* global expect */ -const { sortFiles } = require('./sort-files'); +const { toSortedArray } = require('./sort-files'); const { challengeFiles } = require('./__fixtures__/challenges'); describe('sort-files', () => { - describe('sortFiles', () => { + describe('toSortedArray', () => { it('should return an array', () => { - const sorted = sortFiles(challengeFiles); + const sorted = toSortedArray(challengeFiles); expect(Array.isArray(sorted)).toBe(true); }); it('should not modify the challenges', () => { - const sorted = sortFiles(challengeFiles); + const sorted = toSortedArray(challengeFiles); const expected = Object.values(challengeFiles); expect(sorted).toEqual(expect.arrayContaining(expected)); expect(sorted.length).toEqual(expected.length); }); it('should sort the objects into html, js, css order', () => { - const sorted = sortFiles(challengeFiles); + const sorted = toSortedArray(challengeFiles); const sortedKeys = sorted.map(({ key }) => key); const expected = ['indexhtml', 'indexjsx', 'indexjs', 'indexcss']; expect(sortedKeys).toStrictEqual(expected);