|
7 | 7 | "testing" |
8 | 8 |
|
9 | 9 | "github.com/micasa-dev/micasa/internal/data" |
| 10 | + "github.com/micasa-dev/micasa/internal/extract" |
10 | 11 | "github.com/micasa-dev/micasa/internal/locale" |
11 | 12 | "github.com/stretchr/testify/assert" |
12 | 13 | "github.com/stretchr/testify/require" |
@@ -34,3 +35,49 @@ func TestPreviewColumnsVendorFormatsPhone(t *testing.T) { |
34 | 35 | assert.Equal(t, "(555) 123-4567", phoneFmt("5551234567")) |
35 | 36 | assert.Equal(t, "not a phone", phoneFmt("not a phone")) |
36 | 37 | } |
| 38 | + |
| 39 | +func TestGroupOperationsByTableUsesRowLocale(t *testing.T) { |
| 40 | + // Not parallel: t.Setenv modifies process-global state. |
| 41 | + t.Setenv("LC_ALL", "en_US.UTF-8") |
| 42 | + cur, err := locale.ResolveDefault("") |
| 43 | + require.NoError(t, err) |
| 44 | + |
| 45 | + ops := []extract.Operation{ |
| 46 | + { |
| 47 | + Action: extract.ActionCreate, |
| 48 | + Table: data.TableVendors, |
| 49 | + Data: map[string]any{ |
| 50 | + data.ColName: "UK Plumber", |
| 51 | + data.ColPhone: "02079460958", |
| 52 | + data.ColLocale: "GB", |
| 53 | + }, |
| 54 | + }, |
| 55 | + { |
| 56 | + Action: extract.ActionCreate, |
| 57 | + Table: data.TableVendors, |
| 58 | + Data: map[string]any{ |
| 59 | + data.ColName: "US Plumber", |
| 60 | + data.ColPhone: "5551234567", |
| 61 | + }, |
| 62 | + }, |
| 63 | + } |
| 64 | + |
| 65 | + groups := groupOperationsByTable(ops, cur) |
| 66 | + require.Len(t, groups, 1) |
| 67 | + require.Len(t, groups[0].cells, 2) |
| 68 | + |
| 69 | + // Find phone column index. |
| 70 | + phoneIdx := -1 |
| 71 | + for i, spec := range groups[0].specs { |
| 72 | + if spec.Title == "Phone" { |
| 73 | + phoneIdx = i |
| 74 | + break |
| 75 | + } |
| 76 | + } |
| 77 | + require.NotEqual(t, -1, phoneIdx, "phone column not found") |
| 78 | + |
| 79 | + // UK vendor should use GB locale formatting. |
| 80 | + assert.Equal(t, "020 7946 0958", groups[0].cells[0][phoneIdx].Value) |
| 81 | + // US vendor (no locale) should fall back to system default (US). |
| 82 | + assert.Equal(t, "(555) 123-4567", groups[0].cells[1][phoneIdx].Value) |
| 83 | +} |
0 commit comments