|
| 1 | +import { IterableEdgeInsets } from './IterableEdgeInsets'; |
| 2 | +import type { IterableEdgeInsetDetails } from '../types'; |
| 3 | + |
| 4 | +describe('IterableEdgeInsets', () => { |
| 5 | + describe('constructor', () => { |
| 6 | + it('should create instance with valid parameters', () => { |
| 7 | + // GIVEN valid edge inset parameters |
| 8 | + const top = 10; |
| 9 | + const left = 20; |
| 10 | + const bottom = 30; |
| 11 | + const right = 40; |
| 12 | + |
| 13 | + // WHEN creating an IterableEdgeInsets instance |
| 14 | + const edgeInsets = new IterableEdgeInsets(top, left, bottom, right); |
| 15 | + |
| 16 | + // THEN it should have the correct properties |
| 17 | + expect(edgeInsets.top).toBe(top); |
| 18 | + expect(edgeInsets.left).toBe(left); |
| 19 | + expect(edgeInsets.bottom).toBe(bottom); |
| 20 | + expect(edgeInsets.right).toBe(right); |
| 21 | + }); |
| 22 | + |
| 23 | + it('should create instance with zero values', () => { |
| 24 | + // GIVEN zero edge inset parameters |
| 25 | + const top = 0; |
| 26 | + const left = 0; |
| 27 | + const bottom = 0; |
| 28 | + const right = 0; |
| 29 | + |
| 30 | + // WHEN creating an IterableEdgeInsets instance |
| 31 | + const edgeInsets = new IterableEdgeInsets(top, left, bottom, right); |
| 32 | + |
| 33 | + // THEN it should have zero values |
| 34 | + expect(edgeInsets.top).toBe(0); |
| 35 | + expect(edgeInsets.left).toBe(0); |
| 36 | + expect(edgeInsets.bottom).toBe(0); |
| 37 | + expect(edgeInsets.right).toBe(0); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should create instance with negative values', () => { |
| 41 | + // GIVEN negative edge inset parameters |
| 42 | + const top = -5; |
| 43 | + const left = -10; |
| 44 | + const bottom = -15; |
| 45 | + const right = -20; |
| 46 | + |
| 47 | + // WHEN creating an IterableEdgeInsets instance |
| 48 | + const edgeInsets = new IterableEdgeInsets(top, left, bottom, right); |
| 49 | + |
| 50 | + // THEN it should have the negative values |
| 51 | + expect(edgeInsets.top).toBe(-5); |
| 52 | + expect(edgeInsets.left).toBe(-10); |
| 53 | + expect(edgeInsets.bottom).toBe(-15); |
| 54 | + expect(edgeInsets.right).toBe(-20); |
| 55 | + }); |
| 56 | + |
| 57 | + it('should create instance with decimal values', () => { |
| 58 | + // GIVEN decimal edge inset parameters |
| 59 | + const top = 1.5; |
| 60 | + const left = 2.7; |
| 61 | + const bottom = 3.9; |
| 62 | + const right = 4.1; |
| 63 | + |
| 64 | + // WHEN creating an IterableEdgeInsets instance |
| 65 | + const edgeInsets = new IterableEdgeInsets(top, left, bottom, right); |
| 66 | + |
| 67 | + // THEN it should have the decimal values |
| 68 | + expect(edgeInsets.top).toBe(1.5); |
| 69 | + expect(edgeInsets.left).toBe(2.7); |
| 70 | + expect(edgeInsets.bottom).toBe(3.9); |
| 71 | + expect(edgeInsets.right).toBe(4.1); |
| 72 | + }); |
| 73 | + |
| 74 | + it('should create instance with large values', () => { |
| 75 | + // GIVEN large edge inset parameters |
| 76 | + const top = 1000; |
| 77 | + const left = 2000; |
| 78 | + const bottom = 3000; |
| 79 | + const right = 4000; |
| 80 | + |
| 81 | + // WHEN creating an IterableEdgeInsets instance |
| 82 | + const edgeInsets = new IterableEdgeInsets(top, left, bottom, right); |
| 83 | + |
| 84 | + // THEN it should have the large values |
| 85 | + expect(edgeInsets.top).toBe(1000); |
| 86 | + expect(edgeInsets.left).toBe(2000); |
| 87 | + expect(edgeInsets.bottom).toBe(3000); |
| 88 | + expect(edgeInsets.right).toBe(4000); |
| 89 | + }); |
| 90 | + }); |
| 91 | + |
| 92 | + describe('fromDict', () => { |
| 93 | + it('should create instance from valid dictionary', () => { |
| 94 | + // GIVEN a valid dictionary with edge inset details |
| 95 | + const dict: IterableEdgeInsetDetails = { |
| 96 | + top: 10, |
| 97 | + left: 20, |
| 98 | + bottom: 30, |
| 99 | + right: 40 |
| 100 | + }; |
| 101 | + |
| 102 | + // WHEN creating from dictionary |
| 103 | + const edgeInsets = IterableEdgeInsets.fromDict(dict); |
| 104 | + |
| 105 | + // THEN it should have the correct properties |
| 106 | + expect(edgeInsets.top).toBe(10); |
| 107 | + expect(edgeInsets.left).toBe(20); |
| 108 | + expect(edgeInsets.bottom).toBe(30); |
| 109 | + expect(edgeInsets.right).toBe(40); |
| 110 | + }); |
| 111 | + |
| 112 | + it('should create instance from dictionary with zero values', () => { |
| 113 | + // GIVEN a dictionary with zero values |
| 114 | + const dict: IterableEdgeInsetDetails = { |
| 115 | + top: 0, |
| 116 | + left: 0, |
| 117 | + bottom: 0, |
| 118 | + right: 0 |
| 119 | + }; |
| 120 | + |
| 121 | + // WHEN creating from dictionary |
| 122 | + const edgeInsets = IterableEdgeInsets.fromDict(dict); |
| 123 | + |
| 124 | + // THEN it should have zero values |
| 125 | + expect(edgeInsets.top).toBe(0); |
| 126 | + expect(edgeInsets.left).toBe(0); |
| 127 | + expect(edgeInsets.bottom).toBe(0); |
| 128 | + expect(edgeInsets.right).toBe(0); |
| 129 | + }); |
| 130 | + |
| 131 | + it('should create instance from dictionary with negative values', () => { |
| 132 | + // GIVEN a dictionary with negative values |
| 133 | + const dict: IterableEdgeInsetDetails = { |
| 134 | + top: -5, |
| 135 | + left: -10, |
| 136 | + bottom: -15, |
| 137 | + right: -20 |
| 138 | + }; |
| 139 | + |
| 140 | + // WHEN creating from dictionary |
| 141 | + const edgeInsets = IterableEdgeInsets.fromDict(dict); |
| 142 | + |
| 143 | + // THEN it should have the negative values |
| 144 | + expect(edgeInsets.top).toBe(-5); |
| 145 | + expect(edgeInsets.left).toBe(-10); |
| 146 | + expect(edgeInsets.bottom).toBe(-15); |
| 147 | + expect(edgeInsets.right).toBe(-20); |
| 148 | + }); |
| 149 | + |
| 150 | + it('should create instance from dictionary with decimal values', () => { |
| 151 | + // GIVEN a dictionary with decimal values |
| 152 | + const dict: IterableEdgeInsetDetails = { |
| 153 | + top: 1.5, |
| 154 | + left: 2.7, |
| 155 | + bottom: 3.9, |
| 156 | + right: 4.1 |
| 157 | + }; |
| 158 | + |
| 159 | + // WHEN creating from dictionary |
| 160 | + const edgeInsets = IterableEdgeInsets.fromDict(dict); |
| 161 | + |
| 162 | + // THEN it should have the decimal values |
| 163 | + expect(edgeInsets.top).toBe(1.5); |
| 164 | + expect(edgeInsets.left).toBe(2.7); |
| 165 | + expect(edgeInsets.bottom).toBe(3.9); |
| 166 | + expect(edgeInsets.right).toBe(4.1); |
| 167 | + }); |
| 168 | + |
| 169 | + it('should create instance from dictionary with mixed positive and negative values', () => { |
| 170 | + // GIVEN a dictionary with mixed values |
| 171 | + const dict: IterableEdgeInsetDetails = { |
| 172 | + top: 10, |
| 173 | + left: -5, |
| 174 | + bottom: 0, |
| 175 | + right: 15 |
| 176 | + }; |
| 177 | + |
| 178 | + // WHEN creating from dictionary |
| 179 | + const edgeInsets = IterableEdgeInsets.fromDict(dict); |
| 180 | + |
| 181 | + // THEN it should have the mixed values |
| 182 | + expect(edgeInsets.top).toBe(10); |
| 183 | + expect(edgeInsets.left).toBe(-5); |
| 184 | + expect(edgeInsets.bottom).toBe(0); |
| 185 | + expect(edgeInsets.right).toBe(15); |
| 186 | + }); |
| 187 | + }); |
| 188 | + |
| 189 | + describe('property access', () => { |
| 190 | + it('should allow property modification', () => { |
| 191 | + // GIVEN an IterableEdgeInsets instance |
| 192 | + const edgeInsets = new IterableEdgeInsets(10, 20, 30, 40); |
| 193 | + |
| 194 | + // WHEN modifying properties |
| 195 | + edgeInsets.top = 100; |
| 196 | + edgeInsets.left = 200; |
| 197 | + edgeInsets.bottom = 300; |
| 198 | + edgeInsets.right = 400; |
| 199 | + |
| 200 | + // THEN the properties should be updated |
| 201 | + expect(edgeInsets.top).toBe(100); |
| 202 | + expect(edgeInsets.left).toBe(200); |
| 203 | + expect(edgeInsets.bottom).toBe(300); |
| 204 | + expect(edgeInsets.right).toBe(400); |
| 205 | + }); |
| 206 | + |
| 207 | + it('should maintain property independence', () => { |
| 208 | + // GIVEN an IterableEdgeInsets instance |
| 209 | + const edgeInsets = new IterableEdgeInsets(10, 20, 30, 40); |
| 210 | + |
| 211 | + // WHEN modifying one property |
| 212 | + edgeInsets.top = 999; |
| 213 | + |
| 214 | + // THEN other properties should remain unchanged |
| 215 | + expect(edgeInsets.top).toBe(999); |
| 216 | + expect(edgeInsets.left).toBe(20); |
| 217 | + expect(edgeInsets.bottom).toBe(30); |
| 218 | + expect(edgeInsets.right).toBe(40); |
| 219 | + }); |
| 220 | + }); |
| 221 | + |
| 222 | + describe('edge cases', () => { |
| 223 | + it('should handle NaN values', () => { |
| 224 | + // GIVEN NaN values |
| 225 | + const top = NaN; |
| 226 | + const left = NaN; |
| 227 | + const bottom = NaN; |
| 228 | + const right = NaN; |
| 229 | + |
| 230 | + // WHEN creating an IterableEdgeInsets instance |
| 231 | + const edgeInsets = new IterableEdgeInsets(top, left, bottom, right); |
| 232 | + |
| 233 | + // THEN it should store NaN values |
| 234 | + expect(edgeInsets.top).toBeNaN(); |
| 235 | + expect(edgeInsets.left).toBeNaN(); |
| 236 | + expect(edgeInsets.bottom).toBeNaN(); |
| 237 | + expect(edgeInsets.right).toBeNaN(); |
| 238 | + }); |
| 239 | + |
| 240 | + it('should handle Infinity values', () => { |
| 241 | + // GIVEN Infinity values |
| 242 | + const top = Infinity; |
| 243 | + const left = -Infinity; |
| 244 | + const bottom = Infinity; |
| 245 | + const right = -Infinity; |
| 246 | + |
| 247 | + // WHEN creating an IterableEdgeInsets instance |
| 248 | + const edgeInsets = new IterableEdgeInsets(top, left, bottom, right); |
| 249 | + |
| 250 | + // THEN it should store Infinity values |
| 251 | + expect(edgeInsets.top).toBe(Infinity); |
| 252 | + expect(edgeInsets.left).toBe(-Infinity); |
| 253 | + expect(edgeInsets.bottom).toBe(Infinity); |
| 254 | + expect(edgeInsets.right).toBe(-Infinity); |
| 255 | + }); |
| 256 | + |
| 257 | + it('should handle very small decimal values', () => { |
| 258 | + // GIVEN very small decimal values |
| 259 | + const top = 0.0001; |
| 260 | + const left = 0.0002; |
| 261 | + const bottom = 0.0003; |
| 262 | + const right = 0.0004; |
| 263 | + |
| 264 | + // WHEN creating an IterableEdgeInsets instance |
| 265 | + const edgeInsets = new IterableEdgeInsets(top, left, bottom, right); |
| 266 | + |
| 267 | + // THEN it should store the small decimal values |
| 268 | + expect(edgeInsets.top).toBe(0.0001); |
| 269 | + expect(edgeInsets.left).toBe(0.0002); |
| 270 | + expect(edgeInsets.bottom).toBe(0.0003); |
| 271 | + expect(edgeInsets.right).toBe(0.0004); |
| 272 | + }); |
| 273 | + }); |
| 274 | + |
| 275 | + describe('interface compliance', () => { |
| 276 | + it('should implement IterableEdgeInsetDetails interface', () => { |
| 277 | + // GIVEN an IterableEdgeInsets instance |
| 278 | + const edgeInsets = new IterableEdgeInsets(10, 20, 30, 40); |
| 279 | + |
| 280 | + // THEN it should have all required properties |
| 281 | + expect(edgeInsets).toHaveProperty('top'); |
| 282 | + expect(edgeInsets).toHaveProperty('left'); |
| 283 | + expect(edgeInsets).toHaveProperty('bottom'); |
| 284 | + expect(edgeInsets).toHaveProperty('right'); |
| 285 | + |
| 286 | + // AND all properties should be numbers |
| 287 | + expect(typeof edgeInsets.top).toBe('number'); |
| 288 | + expect(typeof edgeInsets.left).toBe('number'); |
| 289 | + expect(typeof edgeInsets.bottom).toBe('number'); |
| 290 | + expect(typeof edgeInsets.right).toBe('number'); |
| 291 | + }); |
| 292 | + |
| 293 | + it('should be assignable to IterableEdgeInsetDetails', () => { |
| 294 | + // GIVEN an IterableEdgeInsets instance |
| 295 | + const edgeInsets = new IterableEdgeInsets(10, 20, 30, 40); |
| 296 | + |
| 297 | + // WHEN assigning to IterableEdgeInsetDetails |
| 298 | + const details: IterableEdgeInsetDetails = edgeInsets; |
| 299 | + |
| 300 | + // THEN it should work without type errors |
| 301 | + expect(details.top).toBe(10); |
| 302 | + expect(details.left).toBe(20); |
| 303 | + expect(details.bottom).toBe(30); |
| 304 | + expect(details.right).toBe(40); |
| 305 | + }); |
| 306 | + }); |
| 307 | + |
| 308 | + describe('fromDict with edge cases', () => { |
| 309 | + it('should handle dictionary with NaN values', () => { |
| 310 | + // GIVEN a dictionary with NaN values |
| 311 | + const dict: IterableEdgeInsetDetails = { |
| 312 | + top: NaN, |
| 313 | + left: NaN, |
| 314 | + bottom: NaN, |
| 315 | + right: NaN |
| 316 | + }; |
| 317 | + |
| 318 | + // WHEN creating from dictionary |
| 319 | + const edgeInsets = IterableEdgeInsets.fromDict(dict); |
| 320 | + |
| 321 | + // THEN it should have NaN values |
| 322 | + expect(edgeInsets.top).toBeNaN(); |
| 323 | + expect(edgeInsets.left).toBeNaN(); |
| 324 | + expect(edgeInsets.bottom).toBeNaN(); |
| 325 | + expect(edgeInsets.right).toBeNaN(); |
| 326 | + }); |
| 327 | + |
| 328 | + it('should handle dictionary with Infinity values', () => { |
| 329 | + // GIVEN a dictionary with Infinity values |
| 330 | + const dict: IterableEdgeInsetDetails = { |
| 331 | + top: Infinity, |
| 332 | + left: -Infinity, |
| 333 | + bottom: Infinity, |
| 334 | + right: -Infinity |
| 335 | + }; |
| 336 | + |
| 337 | + // WHEN creating from dictionary |
| 338 | + const edgeInsets = IterableEdgeInsets.fromDict(dict); |
| 339 | + |
| 340 | + // THEN it should have Infinity values |
| 341 | + expect(edgeInsets.top).toBe(Infinity); |
| 342 | + expect(edgeInsets.left).toBe(-Infinity); |
| 343 | + expect(edgeInsets.bottom).toBe(Infinity); |
| 344 | + expect(edgeInsets.right).toBe(-Infinity); |
| 345 | + }); |
| 346 | + }); |
| 347 | +}); |
0 commit comments