From 32481e8285e881de03b733904d49a201e7614f65 Mon Sep 17 00:00:00 2001 From: Annmarie Ziegler Date: Wed, 1 May 2024 10:49:08 -0400 Subject: [PATCH 1/4] Add check for existence of post before getting the date --- .../wordpress/android/ui/posts/PublishSettingsViewModel.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PublishSettingsViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PublishSettingsViewModel.kt index 6b9ac3478a36..7366cc610df0 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PublishSettingsViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PublishSettingsViewModel.kt @@ -71,8 +71,10 @@ constructor( open fun start(postRepository: EditPostRepository?) { editPostRepository = postRepository - val startCalendar = postRepository?.let { getCurrentPublishDateAsCalendar(it) } - ?: localeManagerWrapper.getCurrentCalendar() + val startCalendar = postRepository?.takeIf { it.hasPost() }?.let { + getCurrentPublishDateAsCalendar(it) + } ?: + localeManagerWrapper.getCurrentCalendar() updateDateAndTimeFromCalendar(startCalendar) onPostStatusChanged(postRepository?.getPost()) } From 67b45387f404f00bf03bb59bda5487cf6e2438c1 Mon Sep 17 00:00:00 2001 From: Annmarie Ziegler Date: Wed, 1 May 2024 10:50:09 -0400 Subject: [PATCH 2/4] Add test for using current calander if postRepository does not have a post --- .../EditPostPublishSettingsViewModelTest.kt | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/WordPress/src/test/java/org/wordpress/android/ui/posts/EditPostPublishSettingsViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/posts/EditPostPublishSettingsViewModelTest.kt index ff79f33bbd8f..02e9c9da6801 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/posts/EditPostPublishSettingsViewModelTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/posts/EditPostPublishSettingsViewModelTest.kt @@ -450,4 +450,25 @@ class EditPostPublishSettingsViewModelTest : BaseUnitTest() { assertThat(schedulingReminderPeriod).isEqualTo(ONE_HOUR) } + + @Test + fun `on start sets current date when post not present in the repository`() { + var uiModel: PublishUiModel? = null + viewModel.onUiModel.observeForever { + uiModel = it + } + + whenever(editPostRepository.hasPost()).thenReturn(false) + whenever(editPostRepository.getPost()).thenReturn(null) + + viewModel.start(editPostRepository) + + assertThat(viewModel.year).isEqualTo(2019) + assertThat(viewModel.month).isEqualTo(6) + assertThat(viewModel.day).isEqualTo(6) + assertThat(viewModel.hour).isEqualTo(10) + assertThat(viewModel.minute).isEqualTo(20) + + assertThat(uiModel!!.publishDateLabel).isEqualTo("Immediately") + } } From 96460b9b6ef44304420ae4cff833da8ae79d7180 Mon Sep 17 00:00:00 2001 From: Annmarie Ziegler Date: Wed, 1 May 2024 11:01:48 -0400 Subject: [PATCH 3/4] Ensure there is always a value for hasPost() --- .../android/ui/posts/EditPostPublishSettingsViewModelTest.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/WordPress/src/test/java/org/wordpress/android/ui/posts/EditPostPublishSettingsViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/posts/EditPostPublishSettingsViewModelTest.kt index 02e9c9da6801..ecd6b449465b 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/posts/EditPostPublishSettingsViewModelTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/posts/EditPostPublishSettingsViewModelTest.kt @@ -95,6 +95,7 @@ class EditPostPublishSettingsViewModelTest : BaseUnitTest() { null } whenever(editPostRepository.getPost()).thenReturn(post) + whenever(editPostRepository.hasPost()).thenReturn(true) } @Test From 980cb73a5002849a25519b5751044108eb7d449f Mon Sep 17 00:00:00 2001 From: Ajesh R Pai Date: Thu, 2 May 2024 10:25:03 +0530 Subject: [PATCH 4/4] =?UTF-8?q?=E2=86=91=20Updates:=20formatting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/wordpress/android/ui/posts/PublishSettingsViewModel.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PublishSettingsViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PublishSettingsViewModel.kt index 7366cc610df0..0c3a87edcbef 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PublishSettingsViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PublishSettingsViewModel.kt @@ -73,8 +73,7 @@ constructor( editPostRepository = postRepository val startCalendar = postRepository?.takeIf { it.hasPost() }?.let { getCurrentPublishDateAsCalendar(it) - } ?: - localeManagerWrapper.getCurrentCalendar() + } ?: localeManagerWrapper.getCurrentCalendar() updateDateAndTimeFromCalendar(startCalendar) onPostStatusChanged(postRepository?.getPost()) }