Files
Bubberstation/tgui/packages/common/color.test.ts
SkyratBot b215646850 [MIRROR] Tgui: Events & Colors in typescript (#27754)
* Tgui: Events & Colors in typescript (#83218)

## About The Pull Request
Made more common tgui bits in typescript with tests. Not much else to
see here
## Why It's Good For The Game
Typescript conversion + More documentation + type safety

You now get full docs and type info as nature intended:

![image](https://github.com/tgstation/tgstation/assets/42397676/17a7aad6-56d3-4e22-89fa-585cda4c5315)

---------

Co-authored-by: Style Mistake <stylemistake@ gmail.com>

* Tgui: Events & Colors in typescript

---------

Co-authored-by: Jeremiah <42397676+jlsnow301@users.noreply.github.com>
Co-authored-by: Style Mistake <stylemistake@ gmail.com>
2024-05-18 02:30:15 +02:00

50 lines
1.4 KiB
TypeScript

import { Color } from './color';
describe('Color', () => {
it('should create a color with default values', () => {
const color = new Color();
expect(color.r).toBe(0);
expect(color.g).toBe(0);
expect(color.b).toBe(0);
expect(color.a).toBe(1);
});
it('should create a color from hex', () => {
const color = Color.fromHex('#ff0000');
expect(color.r).toBe(255);
expect(color.g).toBe(0);
expect(color.b).toBe(0);
});
it('should darken a color', () => {
const color = new Color(100, 100, 100).darken(50);
expect(color.r).toBe(50);
expect(color.g).toBe(50);
expect(color.b).toBe(50);
});
it('should lighten a color', () => {
const color = new Color(100, 100, 100).lighten(50);
expect(color.r).toBe(150);
expect(color.g).toBe(150);
expect(color.b).toBe(150);
});
it('should interpolate between two colors', () => {
const color1 = new Color(0, 0, 0);
const color2 = new Color(100, 100, 100);
const color = Color.lerp(color1, color2, 0.5);
expect(color.r).toBe(50);
expect(color.g).toBe(50);
expect(color.b).toBe(50);
});
it('should lookup a color in an array', () => {
const colors = [new Color(0, 0, 0), new Color(100, 100, 100)];
const color = Color.lookup(0.5, colors);
expect(color.r).toBe(50);
expect(color.g).toBe(50);
expect(color.b).toBe(50);
});
});