Skip to content

Commit f127395

Browse files
committed
Add tests
1 parent bb9d3f9 commit f127395

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

ios/Tests/GutenbergKitTests/EditorConfigurationBuilderTests.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,29 @@ struct EditorConfigurationBuilderTests {
156156
func editorConfigurationBuilderSetsEditorAssetsEndpointCorrectly() throws {
157157
#expect(EditorConfigurationBuilder().setEditorAssetsEndpoint(URL(string: "https://example.com/wp-content/plugins/gutenberg/build/")).build().editorAssetsEndpoint == URL(string: "https://example.com/wp-content/plugins/gutenberg/build/"))
158158
}
159+
160+
@Test("Applies values correctly")
161+
func editorConfigurationBuilderAppliesValuesCorrectly() throws {
162+
let string = "test"
163+
let nilString: String? = nil
164+
165+
let int = 1
166+
let nilInt: Int? = nil
167+
168+
#expect(EditorConfigurationBuilder().apply(string, { $0.setTitle($1) }).build().title == string)
169+
#expect(EditorConfigurationBuilder().apply(nilString, { $0.setTitle($1)}).build().title == "")
170+
171+
#expect(EditorConfigurationBuilder().apply(int, { $0.setPostID($1) }).build().postID == int)
172+
#expect(EditorConfigurationBuilder().apply(nilInt, { $0.setPostID($1)}).build().postID == nil)
173+
}
174+
175+
@Test("apply never calls the closure if the value is nil")
176+
func editorConfigurationBuilderApplyDoesNotCallClosureWithNilValue() throws {
177+
let string: String? = nil
178+
179+
_ = EditorConfigurationBuilder().apply(string, { builder, value in
180+
Issue.record("Closure was called")
181+
return builder
182+
})
183+
}
159184
}

0 commit comments

Comments
 (0)