Skip to content

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
merged 3 commits into from
Apr 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
@@ -13,9 +13,7 @@ steps:

- label: ':eslint: Lint React App'
command: make lint-js
plugins: &plugins
- $CI_TOOLKIT_PLUGIN
- $NVM_PLUGIN
plugins: *plugins
Copy link
Member Author

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.


- label: ':android: Publish Android Library'
command: |
@@ -26,6 +24,12 @@ steps:
queue: android
plugins: *plugins

- label: ':android: Test Android Library'
command: make test-android
agents:
queue: android
plugins: *plugins

- label: ':swift: Test Swift Package'
command: make test-swift-package
plugins: *plugins
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -42,6 +42,10 @@ local-android-library: build
echo "--- :android: Building Library"
./android/gradlew -p ./android :gutenberg:publishToMavenLocal -exclude-task prepareToPublishToS3

test-android:
echo "--- :android: Running Android Tests"
./android/gradlew -p ./android :gutenberg:test

build-swift-package: build
$(call XCODEBUILD_CMD, build)

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)
}
}