From ff5191b6917f1a4768a772d1d80bb64bcbeec19d Mon Sep 17 00:00:00 2001 From: Douglas Alves Date: Fri, 24 Sep 2021 20:35:23 +0200 Subject: [PATCH] Add unit tests for Sticky label color use case --- .../PostPageListLabelColorUseCaseTest.kt | 54 ++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/WordPress/src/test/java/org/wordpress/android/viewmodel/pages/PostPageListLabelColorUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/viewmodel/pages/PostPageListLabelColorUseCaseTest.kt index fecdb9ec1623..3770db3f8ca9 100644 --- a/WordPress/src/test/java/org/wordpress/android/viewmodel/pages/PostPageListLabelColorUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/viewmodel/pages/PostPageListLabelColorUseCaseTest.kt @@ -140,9 +140,61 @@ class PostPageListLabelColorUseCaseTest { assertThat(labelsColor).isEqualTo(ERROR_COLOR) } - private fun dummyPostModel(): PostModel { + @Test + fun `label has info color on sticky post`() { + // Arrange + val stickyPost = dummyPostModel(sticky = true) + + // Act + val labelsColor = useCase.getLabelsColor( + stickyPost, + mock(), + hasUnhandledConflicts = false, + hasUnhandledAutoSave = false + ) + // Assert + assertThat(labelsColor).isEqualTo(STATE_INFO_COLOR) + } + + @Test + fun `label error color has precedence over info and progress color`() { + // Arrange + val stickyPost = dummyPostModel(sticky = true) + val hasUnhandledConflicts = true + val uploadState = UploadingPost(false) + + // Act + val labelsColor = useCase.getLabelsColor( + stickyPost, + uploadState, + hasUnhandledConflicts = hasUnhandledConflicts, + hasUnhandledAutoSave = false + ) + // Assert + assertThat(labelsColor).isEqualTo(ERROR_COLOR) + } + + @Test + fun `label progress color has precedence over info color`() { + // Arrange + val stickyPost = dummyPostModel(sticky = true) + val uploadState = UploadingPost(false) + + // Act + val labelsColor = useCase.getLabelsColor( + stickyPost, + uploadState, + hasUnhandledConflicts = false, + hasUnhandledAutoSave = false + ) + // Assert + assertThat(labelsColor).isEqualTo(PROGRESS_INFO_COLOR) + } + + private fun dummyPostModel(sticky: Boolean = false): PostModel { val post = PostModel() post.setDateCreated("1970-01-01'T'00:00:01Z") + post.setSticky(sticky) return post }