Skip to content

Commit 961d1ab

Browse files
Merge pull request #239 from mohith2883/feature-Add-tests-for-constructTransformation
test: Add tests for constructTransformation
2 parents cab0d57 + 5475fa6 commit 961d1ab

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { constructTransformation, promptArrayToString } from '../../src/lib/transformations';
3+
4+
describe('constructTransformation', () => {
5+
it('should construct a transformation string with a prefix, qualifier, and string value', () => {
6+
const transformation = constructTransformation({
7+
prefix: 'w',
8+
qualifier: 'width',
9+
value: '100'
10+
});
11+
expect(transformation).toBe('w_width:100');
12+
});
13+
14+
it('should construct a transformation string with a prefix, qualifier, and number value', () => {
15+
const transformation = constructTransformation({
16+
prefix: 'h',
17+
qualifier: 'height',
18+
value: 250
19+
});
20+
expect(transformation).toBe('h_height:250');
21+
});
22+
23+
it('should construct a transformation string with a qualifier and value when no prefix is provided', () => {
24+
const transformation = constructTransformation({
25+
qualifier: 'c',
26+
value: 'fill'
27+
});
28+
expect(transformation).toBe('c_fill');
29+
});
30+
31+
it('should construct a transformation with only prefix and qualifier for a boolean true value', () => {
32+
const transformation = constructTransformation({
33+
prefix: 'e',
34+
qualifier: 'grayscale',
35+
value: true
36+
});
37+
expect(transformation).toBe('e_grayscale');
38+
});
39+
40+
it('should construct a transformation with only prefix and qualifier for a string "true" value', () => {
41+
const transformation = constructTransformation({
42+
prefix: 'e',
43+
qualifier: 'sharpen',
44+
value: 'true'
45+
});
46+
expect(transformation).toBe('e_sharpen');
47+
});
48+
49+
it('should return only the qualifier when value is true and there is no prefix', () => {
50+
const transformation = constructTransformation({
51+
qualifier: 'grayscale',
52+
value: true
53+
});
54+
expect(transformation).toBe('grayscale');
55+
});
56+
57+
it('should apply converters to the value if the test passes', () => {
58+
const converters = [{
59+
test: (value: any) => Array.isArray(value),
60+
convert: (value: any) => value.join(':')
61+
}];
62+
const transformation = constructTransformation({
63+
qualifier: 'co',
64+
value: ['rgb', '2bff00'],
65+
converters
66+
});
67+
expect(transformation).toBe('co_rgb:2bff00');
68+
});
69+
70+
it('should not apply a converter if the test fails', () => {
71+
const converters = [{
72+
test: (value: any) => Array.isArray(value),
73+
convert: (value: any) => value.join(':')
74+
}];
75+
const transformation = constructTransformation({
76+
qualifier: 'w',
77+
value: 900,
78+
converters
79+
});
80+
expect(transformation).toBe('w_900');
81+
});
82+
83+
it('should correctly handle a value of 0', () => {
84+
const transformation = constructTransformation({
85+
qualifier: 'q',
86+
value: 0
87+
});
88+
expect(transformation).toBe('q_0');
89+
});
90+
91+
it('should correctly handle an empty string value', () => {
92+
const transformation = constructTransformation({
93+
prefix: 'l',
94+
qualifier: 'text',
95+
value: ''
96+
});
97+
expect(transformation).toBe('l_text:');
98+
});
99+
100+
it('should return undefined if the value is not a boolean, string, or number', () => {
101+
const transformation = constructTransformation({
102+
qualifier: 'a',
103+
value: undefined
104+
});
105+
expect(transformation).toBeUndefined();
106+
});
107+
108+
it('should return undefined for a boolean false value', () => {
109+
const transformation = constructTransformation({
110+
qualifier: 'e',
111+
value: false
112+
});
113+
expect(transformation).toBeUndefined();
114+
});
115+
});
116+
117+
describe('promptArrayToString', () => {
118+
it('should convert an array of strings to a single string with parentheses and semicolons', () => {
119+
const result = promptArrayToString(['hello', 'world']);
120+
expect(result).toBe('(hello;world)');
121+
});
122+
});

0 commit comments

Comments
 (0)