-
Notifications
You must be signed in to change notification settings - Fork 767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Poll view state unit tests [PSF-1130] #6366
Merged
Merged
Changes from 14 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
bd9fa48
Refactor poll item factory to make it testable.
onurays 77dfd5f
Create initial test class.
onurays a886e93
Test sending poll state.
onurays 8854b81
Test ended poll state.
onurays 0fe4b9f
Test undisclosed poll state.
onurays 2c5ddca
Test voted poll state.
onurays 5a94889
Test ready poll state.
onurays 2cf40cb
Test sending option view states.
onurays 0f0492d
Test ready option view states.
onurays 8bb421a
Test poll voted option view states.
onurays d0d2929
Test undisclosed option view states.
onurays aab558a
Test ended poll option view states.
onurays a7bc2ef
Changelog added.
onurays 2be43e9
Test isVotable function.
onurays 532bc18
Refactor poll item view state factory.
onurays e63fa2d
Move epoxy related poll functions back to MessageItemFactory.
onurays a9358e9
Fix sending poll unit test.
onurays 1a668da
Fix ended poll unit test.
onurays 6f4e079
Fix undisclosed poll unit test.
onurays d7c2dbe
Fix voted poll unit test.
onurays 4f9b361
Fix ready poll unit test.
onurays 8100a2e
Remove duplicated unit tests.
onurays 30115fa
Code review fixes.
onurays 863cc7e
Code review fix.
onurays File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Poll view state unit tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactoryHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright (c) 2022 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package im.vector.app.features.home.room.detail.timeline.factory | ||
|
||
import android.text.Spannable | ||
import android.text.SpannableStringBuilder | ||
import android.text.Spanned | ||
import android.text.TextPaint | ||
import android.text.style.AbsoluteSizeSpan | ||
import android.text.style.ClickableSpan | ||
import android.text.style.ForegroundColorSpan | ||
import android.view.View | ||
import im.vector.app.R | ||
import im.vector.app.core.resources.ColorProvider | ||
import im.vector.app.core.resources.StringProvider | ||
import im.vector.app.core.utils.DimensionConverter | ||
import im.vector.app.features.home.room.detail.timeline.TimelineEventController | ||
import im.vector.app.features.home.room.detail.timeline.item.MessageInformationData | ||
|
||
object MessageItemFactoryHelper { | ||
|
||
fun annotateWithEdited( | ||
stringProvider: StringProvider, | ||
colorProvider: ColorProvider, | ||
dimensionConverter: DimensionConverter, | ||
linkifiedBody: CharSequence, | ||
callback: TimelineEventController.Callback?, | ||
informationData: MessageInformationData, | ||
): Spannable { | ||
val spannable = SpannableStringBuilder() | ||
spannable.append(linkifiedBody) | ||
val editedSuffix = stringProvider.getString(R.string.edited_suffix) | ||
spannable.append(" ").append(editedSuffix) | ||
val color = colorProvider.getColorFromAttribute(R.attr.vctr_content_secondary) | ||
val editStart = spannable.lastIndexOf(editedSuffix) | ||
val editEnd = editStart + editedSuffix.length | ||
spannable.setSpan( | ||
ForegroundColorSpan(color), | ||
editStart, | ||
editEnd, | ||
Spanned.SPAN_INCLUSIVE_EXCLUSIVE | ||
) | ||
|
||
// Note: text size is set to 14sp | ||
spannable.setSpan( | ||
AbsoluteSizeSpan(dimensionConverter.spToPx(13)), | ||
editStart, | ||
editEnd, | ||
Spanned.SPAN_INCLUSIVE_EXCLUSIVE | ||
) | ||
|
||
spannable.setSpan( | ||
object : ClickableSpan() { | ||
override fun onClick(widget: View) { | ||
callback?.onEditedDecorationClicked(informationData) | ||
} | ||
|
||
override fun updateDrawState(ds: TextPaint) { | ||
// nop | ||
} | ||
}, | ||
editStart, | ||
editEnd, | ||
Spanned.SPAN_INCLUSIVE_EXCLUSIVE | ||
) | ||
return spannable | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in general it is better to create classic injectable classes and avoid
object
. Objects are not scoped to only where they are needed and are not suitable for unit tests.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to a helper class after refactoring.