package com.cottondb.messages.chat import android.app.Application import android.graphics.Bitmap import kotlinx.coroutines.runBlocking import org.junit.After import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import org.robolectric.annotation.Config /** * People's photos in Comms (owner via the coordinator, 24 Nov 2026: display pictures no longer showed in WhatsApp * chats). The core answers a face's photo as its media key (a person's `avatar_key`, a contact's, a group's * `photo_key`); the picture loader opened only `msg:`, `file:` and `uri:` keys, so every such photo fell back to * initials. A plain key is now opened by the core (`media.ensure`). Invented key and picture. */ @RunWith(RobolectricTestRunner::class) @Config(sdk = [35], application = Application::class) class FacePhotoTest { @After fun end() { ChatPictures.media = null } @Test fun a_persons_photo_by_its_media_key_is_opened_by_the_core() = runBlocking { val file = java.io.File.createTempFile("face", ".png") Bitmap.createBitmap(64, 64, Bitmap.Config.ARGB_8888).compress(Bitmap.CompressFormat.PNG, 100, file.outputStream()) val asked = mutableListOf() ChatPictures.media = { key -> asked += key; file } val key = "db-invented/people/p-asha/whatsapp/3f2a.jpg" // The file then opens as every message picture does (ImageDecoder, which Robolectric does not run). ChatPictures.load(androidx.test.core.app.ApplicationProvider.getApplicationContext(), key, 96, 96) assertEquals("a photo's plain media key is asked of the core, not dropped", listOf(key), asked) } }