|
1 | | -import XCTest |
| 1 | +import Foundation |
| 2 | +import Testing |
2 | 3 | import WebKit |
3 | 4 | @testable import GutenbergKit |
4 | 5 |
|
5 | | -final class GBWebViewTests: XCTestCase { |
| 6 | +@Suite("GBWebView Tests") |
| 7 | +struct GBWebViewTests { |
6 | 8 |
|
7 | | - func testApplicationNameForUserAgent() { |
| 9 | + @Test("Application name for user agent is set correctly") |
| 10 | + func testApplicationNameForUserAgent() async throws { |
8 | 11 | // Given |
9 | 12 | let webView = GBWebView() |
10 | 13 |
|
11 | 14 | // When |
12 | 15 | webView.applicationNameForUserAgent = "GutenbergKit/\(GBKVersion.version)" |
13 | 16 |
|
14 | 17 | // Then |
15 | | - XCTAssertEqual(webView.applicationNameForUserAgent, "GutenbergKit/\(GBKVersion.version)", |
16 | | - "Application name should be set correctly") |
| 18 | + #expect(webView.applicationNameForUserAgent == "GutenbergKit/\(GBKVersion.version)") |
17 | 19 | } |
18 | 20 |
|
19 | | - func testVersionConstantExists() { |
| 21 | + @Test("Version constant exists and is valid") |
| 22 | + func testVersionConstantExists() async throws { |
20 | 23 | // 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 | + } |
25 | 49 | } |
26 | 50 | } |
0 commit comments