Skip to content

Commit a0391de

Browse files
Copilotdcalhoun
andcommitted
Convert tests to Swift Testing and verify navigator.userAgent
Co-authored-by: dcalhoun <[email protected]>
1 parent 3cfa4e4 commit a0391de

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed
Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,50 @@
1-
import XCTest
1+
import Foundation
2+
import Testing
23
import WebKit
34
@testable import GutenbergKit
45

5-
final class GBWebViewTests: XCTestCase {
6+
@Suite("GBWebView Tests")
7+
struct GBWebViewTests {
68

7-
func testApplicationNameForUserAgent() {
9+
@Test("Application name for user agent is set correctly")
10+
func testApplicationNameForUserAgent() async throws {
811
// Given
912
let webView = GBWebView()
1013

1114
// When
1215
webView.applicationNameForUserAgent = "GutenbergKit/\(GBKVersion.version)"
1316

1417
// Then
15-
XCTAssertEqual(webView.applicationNameForUserAgent, "GutenbergKit/\(GBKVersion.version)",
16-
"Application name should be set correctly")
18+
#expect(webView.applicationNameForUserAgent == "GutenbergKit/\(GBKVersion.version)")
1719
}
1820

19-
func testVersionConstantExists() {
21+
@Test("Version constant exists and is valid")
22+
func testVersionConstantExists() async throws {
2023
// Then
21-
XCTAssertFalse(GBKVersion.version.isEmpty,
22-
"Version constant should not be empty")
23-
XCTAssertTrue(GBKVersion.version.contains("."),
24-
"Version should be in semantic versioning format")
24+
#expect(!GBKVersion.version.isEmpty)
25+
#expect(GBKVersion.version.contains("."))
26+
}
27+
28+
@Test("Navigator user agent includes GutenbergKit identifier")
29+
func testNavigatorUserAgentIncludesGutenbergKit() async throws {
30+
// Given
31+
let webView = GBWebView()
32+
webView.applicationNameForUserAgent = "GutenbergKit/\(GBKVersion.version)"
33+
34+
// Load a simple HTML page to ensure the WebView is ready
35+
let html = "<html><body>Test</body></html>"
36+
webView.loadHTMLString(html, baseURL: nil)
37+
38+
// Wait for the page to load
39+
try await Task.sleep(for: .milliseconds(500))
40+
41+
// When - evaluate navigator.userAgent in the WebView
42+
let userAgent = try await webView.evaluateJavaScript("navigator.userAgent") as? String
43+
44+
// Then
45+
#expect(userAgent != nil)
46+
if let userAgent = userAgent {
47+
#expect(userAgent.contains("GutenbergKit/\(GBKVersion.version)"))
48+
}
2549
}
2650
}

0 commit comments

Comments
 (0)