From a9169ce2477bacdbbae03b16d6c8181caced5d52 Mon Sep 17 00:00:00 2001 From: Yuichiro Kinoshita Date: Wed, 18 Sep 2024 00:03:58 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=83=86=E3=82=B9=E3=83=88=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../note/timeline/TimelineCacheDAOTest.kt | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/modules/data/src/androidTest/java/net/pantasystem/milktea/data/infrastructure/note/timeline/TimelineCacheDAOTest.kt b/modules/data/src/androidTest/java/net/pantasystem/milktea/data/infrastructure/note/timeline/TimelineCacheDAOTest.kt index d10d99ff57..0525426c8e 100644 --- a/modules/data/src/androidTest/java/net/pantasystem/milktea/data/infrastructure/note/timeline/TimelineCacheDAOTest.kt +++ b/modules/data/src/androidTest/java/net/pantasystem/milktea/data/infrastructure/note/timeline/TimelineCacheDAOTest.kt @@ -200,6 +200,82 @@ class TimelineCacheDAOTest { ) } + @Test + fun findLastPreviousId() = runTest { + val accountId = 1L + val pageId = 1L + timelineCacheDAO.clear(accountId, pageId) + val testData = (1 until 1000).map { + val noteId = it.toString().padStart(4, '0') + Assert.assertEquals(4, noteId.length) + TimelineItemEntity( + accountId = accountId, + pageId = pageId, + noteId = noteId, + noteLocalId = NoteEntity.makeEntityId( + Note.Id(accountId, noteId) + ), + id = 0 + ) + } + noteDAO.insertAll( + testData.map { + NoteEntity.fromModel(Note.make( + Note.Id(it.accountId, it.noteId), + User.Id(it.accountId, "user") + )) + } + ) + timelineCacheDAO.insertAll(testData) + Assert.assertEquals( + testData.size.toLong(), noteDAO.count() + ) + Assert.assertEquals( + testData.size.toLong(), + timelineCacheDAO.count() + ) + val lastPreviousId = timelineCacheDAO.findLastPreviousId(accountId, pageId) + Assert.assertNotNull(lastPreviousId) + Assert.assertEquals("0001", lastPreviousId) + } + + @Test + fun findFirstLaterId() = runTest { + val accountId = 1L + val pageId = 1L + timelineCacheDAO.clear(accountId, pageId) + val testData = (1 until 1000).map { + val noteId = it.toString().padStart(4, '0') + Assert.assertEquals(4, noteId.length) + TimelineItemEntity( + accountId = accountId, + pageId = pageId, + noteId = noteId, + noteLocalId = NoteEntity.makeEntityId( + Note.Id(accountId, noteId) + ), + id = 0 + ) + } + noteDAO.insertAll( + testData.map { + NoteEntity.fromModel(Note.make( + Note.Id(it.accountId, it.noteId), + User.Id(it.accountId, "user") + )) + } + ) + timelineCacheDAO.insertAll(testData) + Assert.assertEquals( + testData.size.toLong(), noteDAO.count() + ) + Assert.assertEquals( + testData.size.toLong(), + timelineCacheDAO.count() + ) + val firstLaterId = timelineCacheDAO.findFirstLaterId(accountId, pageId) + Assert.assertEquals("0999", firstLaterId) + } @After fun after() {