|
5 | 5 | * 2.0. |
6 | 6 | */ |
7 | 7 |
|
8 | | -import { generateId } from './helper_functions'; |
| 8 | +import { |
| 9 | + generateId, |
| 10 | + normalizeTitleName, |
| 11 | + isValidNameFormat, |
| 12 | + isNotPurelyNumeric, |
| 13 | + startsWithLetter, |
| 14 | + meetsMinLength, |
| 15 | + meetsMaxLength, |
| 16 | + MIN_NAME_LENGTH, |
| 17 | + MAX_NAME_LENGTH, |
| 18 | +} from './helper_functions'; |
9 | 19 |
|
10 | 20 | describe('helper_functions', () => { |
11 | 21 | describe('generateId', () => { |
@@ -36,4 +46,172 @@ describe('helper_functions', () => { |
36 | 46 | expect(id).not.toContain('-'); |
37 | 47 | }); |
38 | 48 | }); |
| 49 | + |
| 50 | + describe('normalizeTitleName', () => { |
| 51 | + it('should convert to lowercase', () => { |
| 52 | + expect(normalizeTitleName('MyIntegration')).toBe('myintegration'); |
| 53 | + }); |
| 54 | + |
| 55 | + it('should replace spaces with underscores', () => { |
| 56 | + expect(normalizeTitleName('My Integration')).toBe('my_integration'); |
| 57 | + }); |
| 58 | + |
| 59 | + it('should collapse multiple spaces into single underscore', () => { |
| 60 | + expect(normalizeTitleName('My Integration')).toBe('my_integration'); |
| 61 | + }); |
| 62 | + |
| 63 | + it('should collapse multiple underscores into single underscore', () => { |
| 64 | + expect(normalizeTitleName('My___Integration')).toBe('my_integration'); |
| 65 | + }); |
| 66 | + |
| 67 | + it('should collapse mixed spaces and underscores into single underscore', () => { |
| 68 | + expect(normalizeTitleName('My _ Integration')).toBe('my_integration'); |
| 69 | + }); |
| 70 | + |
| 71 | + it('should trim leading and trailing whitespace', () => { |
| 72 | + expect(normalizeTitleName(' My Integration ')).toBe('my_integration'); |
| 73 | + }); |
| 74 | + |
| 75 | + it('should remove leading underscores', () => { |
| 76 | + expect(normalizeTitleName('_my_integration')).toBe('my_integration'); |
| 77 | + expect(normalizeTitleName('__my_integration')).toBe('my_integration'); |
| 78 | + }); |
| 79 | + |
| 80 | + it('should remove trailing underscores', () => { |
| 81 | + expect(normalizeTitleName('my_integration_')).toBe('my_integration'); |
| 82 | + expect(normalizeTitleName('my_integration__')).toBe('my_integration'); |
| 83 | + }); |
| 84 | + |
| 85 | + it('should handle trailing spaces that become underscores', () => { |
| 86 | + expect(normalizeTitleName('my integration ')).toBe('my_integration'); |
| 87 | + expect(normalizeTitleName(' my integration ')).toBe('my_integration'); |
| 88 | + }); |
| 89 | + }); |
| 90 | + |
| 91 | + describe('isValidNameFormat', () => { |
| 92 | + it('should return true for empty string', () => { |
| 93 | + expect(isValidNameFormat('')).toBe(true); |
| 94 | + }); |
| 95 | + |
| 96 | + it('should return true for alphanumeric characters', () => { |
| 97 | + expect(isValidNameFormat('MyIntegration123')).toBe(true); |
| 98 | + }); |
| 99 | + |
| 100 | + it('should return true for names with spaces', () => { |
| 101 | + expect(isValidNameFormat('My Integration')).toBe(true); |
| 102 | + }); |
| 103 | + |
| 104 | + it('should return true for names with underscores', () => { |
| 105 | + expect(isValidNameFormat('My_Integration')).toBe(true); |
| 106 | + }); |
| 107 | + |
| 108 | + it('should return false for names with special characters', () => { |
| 109 | + expect(isValidNameFormat('My-Integration')).toBe(false); |
| 110 | + expect(isValidNameFormat('My@Integration')).toBe(false); |
| 111 | + expect(isValidNameFormat('My!Integration')).toBe(false); |
| 112 | + expect(isValidNameFormat('My.Integration')).toBe(false); |
| 113 | + }); |
| 114 | + |
| 115 | + it('should return false for names with unicode characters', () => { |
| 116 | + expect(isValidNameFormat('Integración')).toBe(false); |
| 117 | + expect(isValidNameFormat('インテグレーション')).toBe(false); |
| 118 | + }); |
| 119 | + }); |
| 120 | + |
| 121 | + describe('isNotPurelyNumeric', () => { |
| 122 | + it('should return true for empty string', () => { |
| 123 | + expect(isNotPurelyNumeric('')).toBe(true); |
| 124 | + }); |
| 125 | + |
| 126 | + it('should return true for names with letters', () => { |
| 127 | + expect(isNotPurelyNumeric('Integration123')).toBe(true); |
| 128 | + expect(isNotPurelyNumeric('a')).toBe(true); |
| 129 | + }); |
| 130 | + |
| 131 | + it('should return true for names starting with numbers but containing letters', () => { |
| 132 | + expect(isNotPurelyNumeric('123Integration')).toBe(true); |
| 133 | + }); |
| 134 | + |
| 135 | + it('should return false for purely numeric names', () => { |
| 136 | + expect(isNotPurelyNumeric('123')).toBe(false); |
| 137 | + expect(isNotPurelyNumeric('1')).toBe(false); |
| 138 | + }); |
| 139 | + |
| 140 | + it('should return false for numeric names with spaces or underscores only', () => { |
| 141 | + expect(isNotPurelyNumeric('123 456')).toBe(false); |
| 142 | + expect(isNotPurelyNumeric('123_456')).toBe(false); |
| 143 | + }); |
| 144 | + |
| 145 | + it('should return true for names with letters and underscores/spaces', () => { |
| 146 | + expect(isNotPurelyNumeric('my_123')).toBe(true); |
| 147 | + expect(isNotPurelyNumeric('123 abc')).toBe(true); |
| 148 | + }); |
| 149 | + }); |
| 150 | + |
| 151 | + describe('startsWithLetter', () => { |
| 152 | + it('should return true for empty string', () => { |
| 153 | + expect(startsWithLetter('')).toBe(true); |
| 154 | + }); |
| 155 | + |
| 156 | + it('should return true for names starting with a letter', () => { |
| 157 | + expect(startsWithLetter('MyIntegration')).toBe(true); |
| 158 | + expect(startsWithLetter('a')).toBe(true); |
| 159 | + expect(startsWithLetter('A123')).toBe(true); |
| 160 | + }); |
| 161 | + |
| 162 | + it('should return false for names starting with a number', () => { |
| 163 | + expect(startsWithLetter('123Integration')).toBe(false); |
| 164 | + expect(startsWithLetter('1abc')).toBe(false); |
| 165 | + }); |
| 166 | + |
| 167 | + it('should return false for names starting with underscore', () => { |
| 168 | + expect(startsWithLetter('_integration')).toBe(false); |
| 169 | + }); |
| 170 | + |
| 171 | + it('should return true for names with leading spaces (trimmed before check)', () => { |
| 172 | + // Leading spaces are trimmed, so ' integration' becomes 'integration' which starts with a letter |
| 173 | + expect(startsWithLetter(' integration')).toBe(true); |
| 174 | + }); |
| 175 | + }); |
| 176 | + |
| 177 | + describe('meetsMinLength', () => { |
| 178 | + it('should return true for empty string', () => { |
| 179 | + expect(meetsMinLength('')).toBe(true); |
| 180 | + }); |
| 181 | + |
| 182 | + it('should return true for names with 2 or more characters', () => { |
| 183 | + expect(meetsMinLength('ab')).toBe(true); |
| 184 | + expect(meetsMinLength('abc')).toBe(true); |
| 185 | + expect(meetsMinLength('my integration')).toBe(true); |
| 186 | + }); |
| 187 | + |
| 188 | + it('should return false for single character names', () => { |
| 189 | + expect(meetsMinLength('a')).toBe(false); |
| 190 | + }); |
| 191 | + }); |
| 192 | + |
| 193 | + describe('meetsMaxLength', () => { |
| 194 | + it('should return true for empty string', () => { |
| 195 | + expect(meetsMaxLength('')).toBe(true); |
| 196 | + }); |
| 197 | + |
| 198 | + it('should return true for names within limit', () => { |
| 199 | + expect(meetsMaxLength('ab')).toBe(true); |
| 200 | + expect(meetsMaxLength('a'.repeat(256))).toBe(true); |
| 201 | + }); |
| 202 | + |
| 203 | + it('should return false for names exceeding 256 characters', () => { |
| 204 | + expect(meetsMaxLength('a'.repeat(257))).toBe(false); |
| 205 | + }); |
| 206 | + }); |
| 207 | + |
| 208 | + describe('constants', () => { |
| 209 | + it('should have correct MIN_NAME_LENGTH', () => { |
| 210 | + expect(MIN_NAME_LENGTH).toBe(2); |
| 211 | + }); |
| 212 | + |
| 213 | + it('should have correct MAX_NAME_LENGTH', () => { |
| 214 | + expect(MAX_NAME_LENGTH).toBe(256); |
| 215 | + }); |
| 216 | + }); |
39 | 217 | }); |
0 commit comments