-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13266 from woocommerce/issue/12760-enlarge-receip…
…t-contents [Receipts] Enlarge receipt contents so that it's easily readable
- Loading branch information
Showing
6 changed files
with
170 additions
and
3 deletions.
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
17 changes: 17 additions & 0 deletions
17
...main/kotlin/com/woocommerce/android/ui/payments/receipt/preview/ReceiptHtmlInterceptor.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,17 @@ | ||
package com.woocommerce.android.ui.payments.receipt.preview | ||
|
||
import javax.inject.Inject | ||
|
||
class ReceiptHtmlInterceptor @Inject constructor() { | ||
|
||
fun interceptHtmlContent(originalHtml: String): String { | ||
return if (originalHtml.contains("<head>")) { | ||
originalHtml.replace( | ||
"<head>", | ||
"<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">" | ||
) | ||
} else { | ||
originalHtml | ||
} | ||
} | ||
} |
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
47 changes: 47 additions & 0 deletions
47
.../kotlin/com/woocommerce/android/ui/payments/receipt/preview/ReceiptHtmlInterceptorTest.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,47 @@ | ||
import com.woocommerce.android.ui.payments.receipt.preview.ReceiptHtmlInterceptor | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
|
||
class ReceiptHtmlInterceptorTest { | ||
|
||
private val interceptor = ReceiptHtmlInterceptor() | ||
|
||
@Test | ||
fun `given original html, when head is present, then should add viewport meta tag`() { | ||
val originalHtml = """ | ||
<html> | ||
<head><title>Test</title></head> | ||
<body>Content</body> | ||
</html> | ||
""".trimIndent() | ||
|
||
val modifiedHtml = interceptor.interceptHtmlContent(originalHtml) | ||
|
||
assertTrue( | ||
modifiedHtml.contains("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">") | ||
) | ||
} | ||
|
||
@Test | ||
fun `given original content, when head is missing, then return original content`() { | ||
val originalHtml = """ | ||
<html> | ||
<body>Content</body> | ||
</html> | ||
""".trimIndent() | ||
|
||
val modifiedHtml = interceptor.interceptHtmlContent(originalHtml) | ||
|
||
assertEquals(originalHtml, modifiedHtml) | ||
} | ||
|
||
@Test | ||
fun `given empty content, then handle empty input`() { | ||
val originalHtml = "" | ||
|
||
val modifiedHtml = interceptor.interceptHtmlContent(originalHtml) | ||
|
||
assertEquals(originalHtml, modifiedHtml) | ||
} | ||
} |
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