wordpress-mobile / AztecEditor-iOS

A reusable native iOS visual HTML text editor component.
Mozilla Public License 2.0
611 stars 146 forks source link

Fix unit tests failing in Xcode 15 #1382

Closed mokagio closed 3 months ago

mokagio commented 6 months ago

WIP


These tests fail in CI, 15.0.1:

✖ testPasteImageWithoutFormatting, XCTAssertEqual failed: ("<p><strong>Pasted: This is an image </strong></p>") is not equal to ("<p><strong>Pasted: This is an image <img src="image.jpg"></strong></p>")

  | ✖ testPasteVideoWithoutFormatting, XCTAssertEqual failed: ("<p><strong>Pasted: This is a video </strong></p>") is not equal to ("<p><strong>Pasted: This is a video <video src="video.mp4" poster="video.jpg"></video></strong></p>")

Locally, on my Xcode 15.2, this other test fails, and only that:

CaptionShortcodeInputProcessorTests.swift:24: XCTAssertEqual failed: ("<figure  someattribute><img src="."><figcaption><b>Text</b><br><br><br></figcaption></figure>") is not equal to ("<figure someattribute><img src="."><figcaption><b>Text</b><br><br><br></figcaption></figure>")

The Xcode 15.2 test fails because of a different space in the output:

+ <figure  someattribute>
- <figure someattribute>

The following diff fixes the issue, but it would be good to get to the bottom of it, right?

diff --git a/WordPressEditor/WordPressEditorTests/WordPressPlugin/Calypso/CaptionShortcode/CaptionShortcodeInputProcessorTests.swift b/WordPressEditor/WordPressEditorTests/WordPressPlugin/Calypso/CaptionShortcode/CaptionShortcodeInputProcessorTests.swift
index d185ced6..b83695fc 100644
--- a/WordPressEditor/WordPressEditorTests/WordPressPlugin/Calypso/CaptionShortcode/CaptionShortcodeInputProcessorTests.swift
+++ b/WordPressEditor/WordPressEditorTests/WordPressPlugin/Calypso/CaptionShortcode/CaptionShortcodeInputProcessorTests.swift
@@ -19,12 +19,11 @@ class CaptionShortcodeInputProcessorTests: XCTestCase {
     ///
     func testCaptionShortcodeIsProperlyConvertedIntoFigureTagPreservingNestedTags() {
         let input = "[caption someattribute]<img src=\".\"><b>Text</b><br><br><br>[/caption]"
-        let expected = "<figure someattribute><img src=\".\"><figcaption><b>Text</b><br><br><br></figcaption></figure>"
+        let expected = "<figure  someattribute><img src=\".\"><figcaption><b>Text</b><br><br><br></figcaption></figure>"

         XCTAssertEqual(processor.process(input), expected)
     }

-
     /// Verifies that the caption shortcode's attributes are transferred over the Figure Tag.
     ///
     func testCaptionShortcodeAttributesAreProperlyPassedOntoTheFigureTag() {

The space issue look suspiciously similar to issues we encountered when migrating WordPress iOS. See https://github.com/wordpress-mobile/WordPress-iOS/commit/49aedbb510a55df61827ae357d5d1e9574f0ae79#diff-d0661df56dbfd6db7932a214bcaf9b0861007eee71a73562fc326176a5475439L41-R54

There, we noticed a formatter going from ` (the regular space) to\u{202F}`. I tried it in the code failing on Xcode 15.2, but it didn't help. That should not be surprising given the diff here on GitHub shows we need to add two spaces.


mokagio commented 3 months ago

There, we noticed a formatter going from ` (the regular space) to\u{202F}`. I tried it in the code failing on Xcode 15.2, but it didn't help. That should not be surprising given the diff here on GitHub shows we need to add two spaces.

This might be related. Notice the \u{fffc} in the plain value:

image

mokagio commented 3 months ago

Closing in favor of https://github.com/wordpress-mobile/AztecEditor-iOS/pull/1392 and #1393