-
Notifications
You must be signed in to change notification settings - Fork 3
test: Assert Android web global configuration #118
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
Merged
+144
−3
Merged
Changes from all commits
Commits
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 hidden or 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 hidden or 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
133 changes: 133 additions & 0 deletions
133
android/Gutenberg/src/test/java/org/wordpress/gutenberg/EditorConfigurationTest.kt
This file contains hidden or 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,133 @@ | ||
package org.wordpress.gutenberg | ||
|
||
import org.junit.Test | ||
import org.junit.Assert.* | ||
import org.junit.Before | ||
|
||
class EditorConfigurationTest { | ||
private lateinit var editorConfig: EditorConfiguration | ||
|
||
@Before | ||
fun setup() { | ||
editorConfig = EditorConfiguration.builder() | ||
.setTitle("Test Title") | ||
.setContent("Test Content") | ||
.setPostId(123) | ||
.setPostType("post") | ||
.setThemeStyles(true) | ||
.setPlugins(true) | ||
.setHideTitle(false) | ||
.setSiteURL("https://example.com") | ||
.setSiteApiRoot("https://example.com/wp-json") | ||
.setSiteApiNamespace(arrayOf("wp/v2")) | ||
.setNamespaceExcludedPaths(arrayOf("users")) | ||
.setAuthHeader("Bearer token") | ||
.setWebViewGlobals(listOf( | ||
WebViewGlobal("testString", WebViewGlobalValue.StringValue("test")), | ||
WebViewGlobal("testNumber", WebViewGlobalValue.NumberValue(42.0)), | ||
WebViewGlobal("testBoolean", WebViewGlobalValue.BooleanValue(true)) | ||
)) | ||
.build() | ||
} | ||
|
||
@Test | ||
fun `test EditorConfiguration builder creates correct configuration`() { | ||
assertEquals("Test Title", editorConfig.title) | ||
assertEquals("Test Content", editorConfig.content) | ||
assertEquals(123, editorConfig.postId) | ||
assertEquals("post", editorConfig.postType) | ||
assertTrue(editorConfig.themeStyles) | ||
assertTrue(editorConfig.plugins) | ||
assertFalse(editorConfig.hideTitle) | ||
assertEquals("https://example.com", editorConfig.siteURL) | ||
assertEquals("https://example.com/wp-json", editorConfig.siteApiRoot) | ||
assertArrayEquals(arrayOf("wp/v2"), editorConfig.siteApiNamespace) | ||
assertArrayEquals(arrayOf("users"), editorConfig.namespaceExcludedPaths) | ||
assertEquals("Bearer token", editorConfig.authHeader) | ||
assertEquals(3, editorConfig.webViewGlobals.size) | ||
} | ||
|
||
@Test | ||
fun `test WebViewGlobal StringValue toJavaScript conversion`() { | ||
val stringValue = WebViewGlobalValue.StringValue("test\nvalue") | ||
assertEquals("\"test\\nvalue\"", stringValue.toJavaScript()) | ||
} | ||
|
||
@Test | ||
fun `test WebViewGlobal NumberValue toJavaScript conversion`() { | ||
val numberValue = WebViewGlobalValue.NumberValue(42.0) | ||
assertEquals("42.0", numberValue.toJavaScript()) | ||
} | ||
|
||
@Test | ||
fun `test WebViewGlobal BooleanValue toJavaScript conversion`() { | ||
val booleanValue = WebViewGlobalValue.BooleanValue(true) | ||
assertEquals("true", booleanValue.toJavaScript()) | ||
} | ||
|
||
@Test | ||
fun `test WebViewGlobal ObjectValue toJavaScript conversion`() { | ||
val objectValue = WebViewGlobalValue.ObjectValue(mapOf( | ||
"key1" to WebViewGlobalValue.StringValue("value1"), | ||
"key2" to WebViewGlobalValue.NumberValue(42.0) | ||
)) | ||
assertEquals("{\"key1\": \"value1\",\"key2\": 42.0}", objectValue.toJavaScript()) | ||
} | ||
|
||
@Test | ||
fun `test WebViewGlobal ArrayValue toJavaScript conversion`() { | ||
val arrayValue = WebViewGlobalValue.ArrayValue(listOf( | ||
WebViewGlobalValue.StringValue("value1"), | ||
WebViewGlobalValue.NumberValue(42.0) | ||
)) | ||
assertEquals("[\"value1\",42.0]", arrayValue.toJavaScript()) | ||
} | ||
|
||
@Test | ||
fun `test WebViewGlobal NullValue toJavaScript conversion`() { | ||
val nullValue = WebViewGlobalValue.NullValue | ||
assertEquals("null", nullValue.toJavaScript()) | ||
} | ||
|
||
@Test | ||
fun `test WebViewGlobal valid identifier`() { | ||
val validGlobal = WebViewGlobal("validName", WebViewGlobalValue.StringValue("test")) | ||
assertEquals("validName", validGlobal.name) | ||
} | ||
|
||
@Test(expected = IllegalArgumentException::class) | ||
fun `test WebViewGlobal invalid identifier throws exception`() { | ||
WebViewGlobal("123invalid", WebViewGlobalValue.StringValue("test")) | ||
} | ||
|
||
@Test | ||
fun `test EditorConfiguration equals and hashCode`() { | ||
val config1 = EditorConfiguration.builder() | ||
.setTitle("Test") | ||
.setContent("Content") | ||
.build() | ||
|
||
val config2 = EditorConfiguration.builder() | ||
.setTitle("Test") | ||
.setContent("Content") | ||
.build() | ||
|
||
assertEquals(config1, config2) | ||
assertEquals(config1.hashCode(), config2.hashCode()) | ||
} | ||
|
||
@Test | ||
fun `test EditorConfiguration not equals`() { | ||
val config1 = EditorConfiguration.builder() | ||
.setTitle("Test1") | ||
.setContent("Content") | ||
.build() | ||
|
||
val config2 = EditorConfiguration.builder() | ||
.setTitle("Test2") | ||
.setContent("Content") | ||
.build() | ||
|
||
assertNotEquals(config1, config2) | ||
} | ||
} |
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.
This task appeared to be an outlier, where all other tasks rely upon this existing plugins anchor definition.