-
Notifications
You must be signed in to change notification settings - Fork 392
/
Copy pathAllLocationsDataSourceTests.swift
67 lines (54 loc) · 2.25 KB
/
AllLocationsDataSourceTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// AllLocationsDataSourceTests.swift
// MullvadVPNTests
//
// Created by Jon Petersson on 2024-02-29.
// Copyright © 2024 Mullvad VPN AB. All rights reserved.
//
@testable import MullvadSettings
@testable import MullvadVPN
import XCTest
class AllLocationsDataSourceTests: XCTestCase {
var allLocationNodes = [LocationNode]()
var dataSource: AllLocationDataSource!
override func setUp() async throws {
setUpDataSource()
}
func testNodeTree() throws {
let rootNode = RootLocationNode(children: dataSource.nodes)
// Testing a selection.
XCTAssertNotNil(rootNode.descendantNodeFor(code: "se"))
XCTAssertNotNil(rootNode.descendantNodeFor(code: "dal"))
XCTAssertNotNil(rootNode.descendantNodeFor(code: "es1-wireguard"))
XCTAssertNotNil(rootNode.descendantNodeFor(code: "se2-wireguard"))
}
func testSearch() throws {
let nodes = dataSource.search(by: "got")
let rootNode = RootLocationNode(children: nodes)
XCTAssertTrue(rootNode.descendantNodeFor(code: "got")?.isHiddenFromSearch == false)
XCTAssertTrue(rootNode.descendantNodeFor(code: "sto")?.isHiddenFromSearch == true)
}
func testSearchWithEmptyText() throws {
let nodes = dataSource.search(by: "")
XCTAssertEqual(nodes, dataSource.nodes)
}
func testNodeByLocation() throws {
var nodeByLocation = dataSource.node(by: .country("es"))
var nodeByCode = dataSource.nodes.first?.descendantNodeFor(code: "es")
XCTAssertEqual(nodeByLocation, nodeByCode)
nodeByLocation = dataSource.node(by: .city("es", "mad"))
nodeByCode = dataSource.nodes.first?.descendantNodeFor(code: "mad")
XCTAssertEqual(nodeByLocation, nodeByCode)
nodeByLocation = dataSource.node(by: .hostname("es", "mad", "es1-wireguard"))
nodeByCode = dataSource.nodes.first?.descendantNodeFor(code: "es1-wireguard")
XCTAssertEqual(nodeByLocation, nodeByCode)
}
}
extension AllLocationsDataSourceTests {
private func setUpDataSource() {
let response = ServerRelaysResponseStubs.sampleRelays
let relays = response.wireguard.relays
dataSource = AllLocationDataSource()
dataSource.reload(response, relays: relays)
}
}