feat(utils): add taglistOrderVariants function to format taglist order

This commit is contained in:
Joxit 2023-05-01 23:22:48 +02:00
parent a77103a2d4
commit 2b63fb725c
No known key found for this signature in database
GPG key ID: F526592B8E012263
3 changed files with 56 additions and 1 deletions

34
test/utils.test.js Normal file
View file

@ -0,0 +1,34 @@
import { taglistOrderVariants } from '../src/scripts/utils.js';
import assert from 'assert';
describe('utils tests', () => {
describe('taglistOrderVariants', () => {
it(`should return the input when it's well formed and num first`, () => {
const expected = ['num-asc;alpha-asc', 'num-asc;alpha-desc', 'num-desc;alpha-asc', 'num-desc;alpha-asc'];
expected.forEach(
(e) => assert.deepEqual(taglistOrderVariants(e), e)
);
});
it(`should return the input when it's well formed and alpha first`, () => {
const expected = ['alpha-asc;num-asc', 'alpha-asc;num-desc', 'alpha-desc;num-asc', 'alpha-desc;num-asc'];
expected.forEach(
(e) => assert.deepEqual(taglistOrderVariants(e), e)
);
});
it('should return correct variant of `num-asc;alpha-asc`', () => {
const expected = 'num-asc;alpha-asc';
['asc', 'num-asc'].forEach(
(e) => assert.deepEqual(taglistOrderVariants(e), expected)
);
});
it('should return correct variant of `alpha-desc;num-desc`', () => {
const expected = 'alpha-desc;num-desc';
['desc', 'alpha-desc'].forEach(
(e) => assert.deepEqual(taglistOrderVariants(e), expected)
);
});
});
});