mirror of
https://github.com/Joxit/docker-registry-ui.git
synced 2025-04-30 17:09:55 +03:00
fix(utils): taglistOrderVariants improved format
This commit is contained in:
parent
2b63fb725c
commit
a3e987482e
2 changed files with 25 additions and 16 deletions
|
@ -1,33 +1,37 @@
|
|||
import { taglistOrderVariants } from '../src/scripts/utils.js';
|
||||
import { DockerRegistryUIError } from '../src/scripts/error.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)
|
||||
);
|
||||
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)
|
||||
);
|
||||
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)
|
||||
);
|
||||
[undefined, '', '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)
|
||||
['desc'].forEach((e) => assert.deepEqual(taglistOrderVariants(e), expected));
|
||||
});
|
||||
|
||||
it('should extend correctly orders', () => {
|
||||
['alpha-desc', 'alpha-asc'].forEach((e) => assert.deepEqual(taglistOrderVariants(e), `${e};num-asc`));
|
||||
['num-desc', 'num-asc'].forEach((e) => assert.deepEqual(taglistOrderVariants(e), `${e};alpha-asc`));
|
||||
});
|
||||
|
||||
it('should throw error on incorrect values', () => {
|
||||
['alpha-desc;alpha-asc', 'foobar'].forEach((e) =>
|
||||
assert.throws(() => taglistOrderVariants(e), DockerRegistryUIError, `Did not throw on ${e}`)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue