-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathindex.test.mjs
More file actions
80 lines (65 loc) · 2.05 KB
/
index.test.mjs
File metadata and controls
80 lines (65 loc) · 2.05 KB
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
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import {
indentClassNames,
cleanClassNames,
applyIndentation,
} from '../utils.mjs';
describe('cleanClassNames', () => {
it('removes newlines and extra spaces', () => {
const input = ' text-xl \r font-bold \n\n text-center ';
const expected = 'text-xl font-bold text-center';
assert.equal(cleanClassNames(input), expected);
});
it('trims leading and trailing spaces', () => {
const input = ' mt-4 ';
const expected = 'mt-4';
assert.equal(cleanClassNames(input), expected);
});
it('returns empty string when input is empty', () => {
assert.equal(cleanClassNames(''), '');
});
});
describe('applyIndentation', () => {
it('adds indentation to each class name', () => {
const input = 'text-xl font-bold text-center';
const indent = ' ';
const expected = ['text-xl', ' font-bold', ' text-center'].join('\n');
assert.equal(applyIndentation(input, indent), expected);
});
});
describe('indentClassNames', () => {
it('returns null if rule is missing required properties', () => {
assert.equal(indentClassNames(null), null);
assert.equal(indentClassNames({}), null);
assert.equal(indentClassNames({ params: 'foo' }), null);
assert.equal(indentClassNames({ params: 'foo', raws: {} }), null);
});
it('cleans and indents class names correctly', () => {
const rule = {
params: ' text-xl \n font-bold \n text-center ',
raws: {
before: ' ',
},
};
const result = indentClassNames({ ...rule });
const expectedParams = ['text-xl', ' font-bold', ' text-center'].join(
'\n'
);
assert.deepEqual(result, {
...rule,
params: expectedParams,
});
});
it('returns the same rule object with modified params', () => {
const rule = {
params: 'p-4 mb-2',
raws: { before: ' \n' },
};
const result = indentClassNames(rule);
assert.deepEqual(result, {
...result,
params: 'p-4\n mb-2',
});
});
});