|
1 | | -import Foundation |
2 | 1 | import Testing |
3 | 2 | import WebKit |
4 | 3 | @testable import GutenbergKit |
5 | 4 |
|
6 | | -@Suite("GBWebView Tests") |
7 | 5 | struct GBWebViewTests { |
8 | | - |
9 | | - @Test("Application name for user agent is set correctly") |
| 6 | + |
| 7 | + @MainActor |
10 | 8 | func testApplicationNameForUserAgent() async throws { |
11 | | - // Given |
12 | | - let webView = GBWebView() |
13 | | - |
14 | | - // When |
15 | | - webView.applicationNameForUserAgent = "GutenbergKit/\(GBKVersion.version)" |
16 | | - |
17 | | - // Then |
18 | | - #expect(webView.applicationNameForUserAgent == "GutenbergKit/\(GBKVersion.version)") |
19 | | - } |
20 | | - |
21 | | - @Test("Version constant exists and is valid") |
22 | | - func testVersionConstantExists() async throws { |
23 | | - // Then |
24 | | - #expect(!GBKVersion.version.isEmpty) |
25 | | - #expect(GBKVersion.version.contains(".")) |
| 9 | + let result = try await GBWebView().evaluateJavaScript("navigator.userAgent") |
| 10 | + let string = try #require(result as? String) |
| 11 | + |
| 12 | + #expect(string.hasSuffix("GutenbergKit/\(GBKVersion.version)")) |
26 | 13 | } |
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?.contains("GutenbergKit/\(GBKVersion.version)") == true) |
| 14 | + |
| 15 | + func testVersionConstantExists() { |
| 16 | + #expect(GBKVersion.version.isEmpty, "Version constant should not be empty") |
| 17 | + #expect(GBKVersion.version.contains("."), "Version should be in semantic versioning format") |
46 | 18 | } |
47 | 19 | } |
0 commit comments