Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/resources/scripts/lib/helpers.spec.ts
7458 views
1
import { hexToRgba } from '@/lib/helpers';
2
3
describe('@/lib/helpers.ts', function () {
4
describe('hexToRgba()', function () {
5
it('should return the expected rgba', function () {
6
expect(hexToRgba('#ffffff')).toBe('rgba(255, 255, 255, 1)');
7
expect(hexToRgba('#00aabb')).toBe('rgba(0, 170, 187, 1)');
8
expect(hexToRgba('#efefef')).toBe('rgba(239, 239, 239, 1)');
9
});
10
11
it('should ignore case', function () {
12
expect(hexToRgba('#FF00A3')).toBe('rgba(255, 0, 163, 1)');
13
});
14
15
it('should allow alpha channel changes', function () {
16
expect(hexToRgba('#ece5a8', 0.5)).toBe('rgba(236, 229, 168, 0.5)');
17
expect(hexToRgba('#ece5a8', 0.1)).toBe('rgba(236, 229, 168, 0.1)');
18
expect(hexToRgba('#000000', 0)).toBe('rgba(0, 0, 0, 0)');
19
});
20
21
it('should handle invalid strings', function () {
22
expect(hexToRgba('')).toBe('');
23
expect(hexToRgba('foobar')).toBe('foobar');
24
expect(hexToRgba('#fff')).toBe('#fff');
25
expect(hexToRgba('#')).toBe('#');
26
expect(hexToRgba('#fffffy')).toBe('#fffffy');
27
});
28
});
29
});
30
31