|
17 | 17 | test('formatBoardRecord casts record ID to string to prevent JS precision loss', function () { |
18 | 18 | $task = Task::factory()->todo()->withPosition('65535.0000000000')->create(); |
19 | 19 |
|
| 20 | + // Use a snowflake-like ID above Number.MAX_SAFE_INTEGER to exercise precision edge case |
| 21 | + $task->id = 420533451316027392; |
| 22 | + |
20 | 23 | $board = app(TestBoard::class)->getBoard(); |
21 | 24 | $formatted = $board->formatBoardRecord($task); |
22 | 25 |
|
23 | 26 | // The ID must be a string so @js() emits a JSON string ("123") not a number (123) |
24 | 27 | // This prevents JavaScript precision loss for large IDs like snowflakes |
25 | 28 | expect($formatted['id'])->toBeString(); |
| 29 | + expect($formatted['id'])->toBe('420533451316027392'); |
26 | 30 | }); |
27 | 31 |
|
28 | | - test('card blade renders recordKey as string in wire:click for large IDs', function () { |
29 | | - $task = Task::factory()->todo()->withPosition('65535.0000000000')->create(); |
30 | | - |
31 | | - // Simulate what @js() does: json_encode the record ID |
32 | | - // If ID is an integer, json_encode produces a number literal which JS truncates |
33 | | - $idAsInt = (int) $task->id; |
34 | | - $jsonFromInt = json_encode(['recordKey' => $idAsInt]); |
35 | | - |
36 | | - // If ID is a string, json_encode produces a quoted string which JS preserves |
37 | | - $idAsString = (string) $task->id; |
38 | | - $jsonFromString = json_encode(['recordKey' => $idAsString]); |
39 | | - |
| 32 | + test('json_encode emits quoted recordKey for large string IDs', function () { |
40 | 33 | // For a snowflake like 420533451316027392: |
41 | 34 | // json_encode(int) -> {"recordKey":420533451316027392} <- JS reads as 420533451316027400 (WRONG) |
42 | 35 | // json_encode(string) -> {"recordKey":"420533451316027392"} <- JS reads correctly |
43 | 36 | $snowflakeId = 420533451316027392; |
44 | | - $jsonSnowflakeInt = json_encode(['recordKey' => $snowflakeId]); |
| 37 | + |
45 | 38 | $jsonSnowflakeStr = json_encode(['recordKey' => (string) $snowflakeId]); |
| 39 | + $jsonSnowflakeInt = json_encode(['recordKey' => $snowflakeId]); |
46 | 40 |
|
47 | 41 | // The string version wraps in quotes, preserving exact value |
48 | 42 | expect($jsonSnowflakeStr)->toContain('"420533451316027392"'); |
|
0 commit comments