refactor: sortFiles -> toSortedArray
This commit is contained in:
committed by
Mrugesh Mohapatra
parent
1ee5e24d0f
commit
52cb6adf02
@@ -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.
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user