refactor: sort-files -> common utils

This commit is contained in:
Oliver Eyton-Williams
2020-06-05 18:00:05 +02:00
committed by Mrugesh Mohapatra
parent 063145fe90
commit 88de5bc602
4 changed files with 4 additions and 5 deletions

26
utils/sort-files.test.js Normal file
View File

@ -0,0 +1,26 @@
/* global expect */
const { sortFiles } = require('./sort-files');
const { challengeFiles } = require('./__fixtures__/challenges');
describe('sort-files', () => {
describe('sortFiles', () => {
it('should return an array', () => {
const sorted = sortFiles(challengeFiles);
expect(Array.isArray(sorted)).toBe(true);
});
it('should not modify the challenges', () => {
const sorted = sortFiles(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 sortedKeys = sorted.map(({ key }) => key);
const expected = ['indexhtml', 'indexjsx', 'indexjs', 'indexcss'];
expect(sortedKeys).toStrictEqual(expected);
});
});
});