Show country on the device list beside IP.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
hashbro
2026-09-14 23:27:37 +08:00
parent 8c9a15c523
commit 74a85b415b
3 changed files with 84 additions and 2 deletions
+36
View File
@@ -59,4 +59,40 @@ class DeviceCountryTest extends TestCase
$this->assertSame('FR', $device->resolvedCountry());
$this->assertSame('1.2.3.4(法国)', $device->formattedIp());
}
#[Test]
public function device_list_includes_country_column(): void
{
Device::query()->create([
'device_id' => 'dev-country-cn',
'ip' => '8.8.8.8',
'country' => 'CN',
]);
Device::query()->create([
'device_id' => 'dev-country-visit',
'ip' => '1.2.3.4',
]);
PageVisit::query()->create([
'channel_id' => '0.0.01',
'client_uid' => 'bbbbbbbbbbbbbbbb',
'ip' => '1.2.3.4',
'country' => 'FR',
]);
$admin = Admin::query()->create(['username' => 'admin', 'password' => 'admin123']);
$this->actingAs($admin, 'admin')
->get(route('admin.devices.index'))
->assertOk()
->assertSee('国家');
$rows = $this->actingAs($admin, 'admin')
->getJson(route('admin.devices.data'))
->assertOk()
->json('data');
$byId = collect($rows)->keyBy('device_id');
$this->assertSame('CN', $byId['dev-country-cn']['country']);
$this->assertSame('中国', $byId['dev-country-cn']['country_label']);
$this->assertSame('FR', $byId['dev-country-visit']['country']);
$this->assertSame('法国', $byId['dev-country-visit']['country_label']);
}
}