-
Notifications
You must be signed in to change notification settings - Fork 544
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
Fix Part #277 : Added UrlImage Loading Tests #5681
Open
TanishMoral11
wants to merge
5
commits into
oppia:develop
Choose a base branch
from
TanishMoral11:feature/test-url-image-parser-loading
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+78
−3
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5190531
Added UrlImage Loading Tests
TanishMoral11 453d8eb
Merge branch 'develop' into feature/test-url-image-parser-loading
TanishMoral11 fb53bf8
Merge branch 'develop' into feature/test-url-image-parser-loading
TanishMoral11 5014df2
Merge branch 'develop' into feature/test-url-image-parser-loading
TanishMoral11 a4c0669
Merge branch 'develop' into feature/test-url-image-parser-loading
TanishMoral11 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 |
---|---|---|
|
@@ -2,6 +2,7 @@ package org.oppia.android.util.parser.image | |
|
||
import android.app.Application | ||
import android.content.Context | ||
import android.os.Looper | ||
import android.widget.TextView | ||
import androidx.test.core.app.ApplicationProvider | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
@@ -26,6 +27,7 @@ import org.oppia.android.util.locale.LocaleProdModule | |
import org.oppia.android.util.logging.LoggerModule | ||
import org.oppia.android.util.parser.html.CustomHtmlContentHandler.ImageRetriever.Type.BLOCK_IMAGE | ||
import org.oppia.android.util.parser.html.CustomHtmlContentHandler.ImageRetriever.Type.INLINE_TEXT_IMAGE | ||
import org.robolectric.Shadows | ||
import org.robolectric.annotation.LooperMode | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
@@ -58,9 +60,6 @@ class UrlImageParserTest { | |
) | ||
} | ||
|
||
// TODO(#277): Add more test cases for loading images. The below doesn't include layout or | ||
// sizing/positioning. | ||
|
||
@Test | ||
fun testGetDrawable_bitmap_loadsBitmapImage() { | ||
urlImageParser.getDrawable("test_image.png") | ||
|
@@ -79,6 +78,82 @@ class UrlImageParserTest { | |
assertThat(loadedBitmaps.first()).contains("test_image.svg") | ||
} | ||
|
||
@Test | ||
fun testLoadDrawable_bitmap_fromUrl() { | ||
val imageUrl = "https://example.com/test_image.png" | ||
urlImageParser.loadDrawable(imageUrl, BLOCK_IMAGE) | ||
|
||
// Wait for Glide to finish loading | ||
Shadows.shadowOf(Looper.getMainLooper()).idle() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here and elsewhere, use |
||
|
||
val loadedBitmaps = testGlideImageLoader.getLoadedBitmaps() | ||
assertThat(loadedBitmaps).hasSize(1) | ||
assertThat(loadedBitmaps.first()).contains("test_image.png") | ||
} | ||
|
||
@Test | ||
fun testLoadDrawable_svg_fromUrl_blockType() { | ||
val imageUrl = "https://example.com/test_image.svg" | ||
urlImageParser.loadDrawable(imageUrl, BLOCK_IMAGE) | ||
|
||
Shadows.shadowOf(Looper.getMainLooper()).idle() | ||
|
||
val loadedSvgs = testGlideImageLoader.getLoadedBlockSvgs() | ||
assertThat(loadedSvgs).hasSize(1) | ||
assertThat(loadedSvgs.first()).contains("test_image.svg") | ||
} | ||
|
||
@Test | ||
fun testLoadDrawable_svgz_fromUrl_blockType() { | ||
val imageUrl = "https://example.com/test_image.svgz" | ||
urlImageParser.loadDrawable(imageUrl, BLOCK_IMAGE) | ||
|
||
Shadows.shadowOf(Looper.getMainLooper()).idle() | ||
|
||
val loadedSvgs = testGlideImageLoader.getLoadedBlockSvgs() | ||
assertThat(loadedSvgs).hasSize(1) | ||
assertThat(loadedSvgs.first()).contains("test_image.svgz") | ||
} | ||
|
||
@Test | ||
fun testLoadDrawable_latex_inlineType_fromUrl() { | ||
val rawLatex = "\\frac{2}{6}" | ||
urlImageParser.loadMathDrawable( | ||
rawLatex = rawLatex, | ||
lineHeight = 20f, | ||
type = INLINE_TEXT_IMAGE | ||
) | ||
|
||
Shadows.shadowOf(Looper.getMainLooper()).idle() | ||
|
||
val loadedMathDrawables = testGlideImageLoader.getLoadedMathDrawables() | ||
assertThat(loadedMathDrawables).hasSize(1) | ||
assertThat(loadedMathDrawables.first().rawLatex).isEqualTo("\\frac{2}{6}") | ||
assertThat(loadedMathDrawables.first().useInlineRendering).isTrue() | ||
} | ||
|
||
@Test | ||
fun testLoadMultipleImages() { | ||
val imageUrl1 = "https://example.com/test_image1.png" | ||
val imageUrl2 = "https://example.com/test_image2.svg" | ||
val imageUrl3 = "https://example.com/test_image3.svgz" | ||
|
||
urlImageParser.loadDrawable(imageUrl1, BLOCK_IMAGE) | ||
urlImageParser.loadDrawable(imageUrl2, BLOCK_IMAGE) | ||
urlImageParser.loadDrawable(imageUrl3, BLOCK_IMAGE) | ||
|
||
Shadows.shadowOf(Looper.getMainLooper()).idle() | ||
|
||
val loadedBitmaps = testGlideImageLoader.getLoadedBitmaps() | ||
val loadedBlockSvgs = testGlideImageLoader.getLoadedBlockSvgs() | ||
|
||
assertThat(loadedBitmaps).hasSize(1) | ||
assertThat(loadedBlockSvgs).hasSize(2) | ||
assertThat(loadedBitmaps.first()).contains("test_image1.png") | ||
assertThat(loadedBlockSvgs.first()).contains("test_image2.svg") | ||
assertThat(loadedBlockSvgs[1]).contains("test_image3.svgz") | ||
} | ||
|
||
@Test | ||
fun testGetDrawable_svgz_loadsSvgzBlockImage() { | ||
urlImageParser.getDrawable("test_image.svgz") | ||
|
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.
Here and elsewhere, suggested rename:
systemUnderTest_arrangement_expectedOutcome