forked from heusalagroup/fi.hg.core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnumUtils.test.ts
89 lines (68 loc) · 2.67 KB
/
EnumUtils.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright (c) 2023. Heusala Group Oy <info@heusalagroup.fi>. All rights reserved.
import { EnumUtils } from './EnumUtils';
enum TestType {
KEY0 = "0value",
KEY1 = "1value",
KEY = "value",
ANOTHER_KEY = "anotherValue",
}
enum NumericTestType {
KEY0 = 0,
KEY1 = 1,
KEY = 2,
ANOTHER_KEY = 3,
}
describe('EnumUtils', () => {
describe('getKeyValuePairs', () => {
it('should return key-value pairs for string based enum', () => {
const expected = [
["KEY0", "0value"],
["KEY1", "1value"],
["KEY", "value"],
["ANOTHER_KEY", "anotherValue"],
];
expect(EnumUtils.getKeyValuePairs(TestType)).toStrictEqual(expected);
});
it('should return key-value pairs for numeric enum', () => {
const expected = [
["KEY0", 0],
["KEY1", 1],
["KEY", 2],
["ANOTHER_KEY", 3],
];
expect(EnumUtils.getKeyValuePairs(NumericTestType)).toStrictEqual(expected);
});
});
describe('getValues', () => {
it('should return values for string based enum', () => {
const expected = ["0value", "1value", "value", "anotherValue"];
expect(EnumUtils.getValues(TestType)).toStrictEqual(expected);
});
it('should return values for numeric enum', () => {
const expected = [0, 1, 2, 3];
expect(EnumUtils.getValues(NumericTestType)).toStrictEqual(expected);
});
});
describe('getKeys', () => {
it('should return keys for string based enum', () => {
const expected = ["KEY0", "KEY1", "KEY", "ANOTHER_KEY"];
expect(EnumUtils.getKeys(TestType)).toStrictEqual(expected);
});
it('should return keys for numeric enum', () => {
const expected = ["KEY0", "KEY1", "KEY", "ANOTHER_KEY"];
expect(EnumUtils.getKeys(NumericTestType)).toStrictEqual(expected);
});
});
describe('createFilteredKeysFromValues', () => {
it('should return keys corresponding to provided string values', () => {
const values = ["0value", "1value"];
const expected = ["KEY0", "KEY1"];
expect(EnumUtils.createFilteredKeysFromValues(TestType, values)).toStrictEqual(expected);
});
it('should return keys corresponding to provided numeric values', () => {
const values : readonly number[] = [0, 1];
const expected = ["KEY0", "KEY1"];
expect(EnumUtils.createFilteredKeysFromValues(NumericTestType, values)).toStrictEqual(expected);
});
});
});