|
1 | 1 | //
|
2 |
| -// URLQueryItemTests.swift |
| 2 | +// URLExtensionTests.swift |
3 | 3 | // DuckDuckGo
|
4 | 4 | //
|
5 | 5 | // Copyright © 2022 DuckDuckGo. All rights reserved.
|
|
20 | 20 | import XCTest
|
21 | 21 | @testable import AIChat
|
22 | 22 |
|
23 |
| -class URLQueryItemTests: XCTestCase { |
| 23 | +class URLExtensionTests: XCTestCase { |
24 | 24 |
|
25 | 25 | func testAddingQueryItemToEmptyURL() {
|
26 | 26 | let url = URL(string: "https://example.com")!
|
@@ -81,6 +81,46 @@ class URLQueryItemTests: XCTestCase {
|
81 | 81 | XCTAssertEqual(result.host, "example.com")
|
82 | 82 | XCTAssertEqual(result.queryItemsDictionary, ["key": ""])
|
83 | 83 | }
|
| 84 | + |
| 85 | + func testIsDuckAIURLWithValidURL() { |
| 86 | + if let url = URL(string: "https://duckduckgo.com/?ia=chat") { |
| 87 | + XCTAssertTrue(url.isDuckAIURL, "The URL should be identified as a DuckDuckGo AI URL.") |
| 88 | + } else { |
| 89 | + XCTFail("Failed to create URL from string.") |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + func testIsDuckAIURLWithInvalidDomain() { |
| 94 | + if let url = URL(string: "https://example.com/?ia=chat") { |
| 95 | + XCTAssertFalse(url.isDuckAIURL, "The URL should not be identified as a DuckDuckGo AI URL due to the domain.") |
| 96 | + } else { |
| 97 | + XCTFail("Failed to create URL from string.") |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + func testIsDuckAIURLWithMissingQueryItem() { |
| 102 | + if let url = URL(string: "https://duckduckgo.com/") { |
| 103 | + XCTAssertFalse(url.isDuckAIURL, "The URL should not be identified as a DuckDuckGo AI URL due to missing query item.") |
| 104 | + } else { |
| 105 | + XCTFail("Failed to create URL from string.") |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + func testIsDuckAIURLWithDifferentQueryItem() { |
| 110 | + if let url = URL(string: "https://duckduckgo.com/?ia=search") { |
| 111 | + XCTAssertFalse(url.isDuckAIURL, "The URL should not be identified as a DuckDuckGo AI URL due to different query item value.") |
| 112 | + } else { |
| 113 | + XCTFail("Failed to create URL from string.") |
| 114 | + } |
| 115 | + } |
| 116 | + |
| 117 | + func testIsDuckAIURLWithAdditionalQueryItems() { |
| 118 | + if let url = URL(string: "https://duckduckgo.com/?ia=chat&other=param") { |
| 119 | + XCTAssertTrue(url.isDuckAIURL, "The URL should be identified as a DuckDuckGo AI URL even with additional query items.") |
| 120 | + } else { |
| 121 | + XCTFail("Failed to create URL from string.") |
| 122 | + } |
| 123 | + } |
84 | 124 | }
|
85 | 125 |
|
86 | 126 | extension URL {
|
|
0 commit comments