Skip to content

Commit d55340c

Browse files
Jon Peterssonbuggmagnet
Jon Petersson
authored andcommitted
Fix selection of custom list location not being retained
1 parent ffbeb23 commit d55340c

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

ios/MullvadVPN/View controllers/SelectLocation/CustomListsDataSource.swift

+8-5
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,21 @@ class CustomListsDataSource: LocationDataSourceProtocol {
8585
return switch location {
8686
case let .country(countryCode):
8787
rootNode
88-
.countryFor(code: countryCode)?.copy(withParent: parentNode)
88+
.countryFor(code: countryCode)?
89+
.copy(withParent: parentNode)
8990

9091
case let .city(countryCode, cityCode):
9192
rootNode
92-
.countryFor(code: countryCode)?.copy(withParent: parentNode)
93-
.cityFor(codes: [countryCode, cityCode])
93+
.countryFor(code: countryCode)?
94+
.cityFor(codes: [countryCode, cityCode])?
95+
.copy(withParent: parentNode)
9496

9597
case let .hostname(countryCode, cityCode, hostCode):
9698
rootNode
97-
.countryFor(code: countryCode)?.copy(withParent: parentNode)
99+
.countryFor(code: countryCode)?
98100
.cityFor(codes: [countryCode, cityCode])?
99-
.hostFor(code: hostCode)
101+
.hostFor(code: hostCode)?
102+
.copy(withParent: parentNode)
100103
}
101104
}
102105
}

ios/MullvadVPN/View controllers/SelectLocation/LocationNode.swift

+2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ extension LocationNode {
8080
}
8181

8282
extension LocationNode {
83+
/// Recursively copies a node, its parent and its descendants from another
84+
/// node (tree), with an optional custom root parent.
8385
func copy(withParent parent: LocationNode? = nil) -> LocationNode {
8486
let node = LocationNode(
8587
name: name,

ios/MullvadVPNTests/Location/CustomListsDataSourceTests.swift

+12
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ class CustomListsDataSourceTests: XCTestCase {
3232
XCTAssertNotNil(youtubeNode.descendantNodeFor(codes: ["youtube", "us", "dal"]))
3333
}
3434

35+
func testParents() throws {
36+
let listNode = try XCTUnwrap(dataSource.nodes.first(where: { $0.name == "Netflix" }))
37+
let countryNode = try XCTUnwrap(listNode.descendantNodeFor(codes: ["netflix-se"]))
38+
let cityNode = try XCTUnwrap(listNode.descendantNodeFor(codes: ["netflix-se-got"]))
39+
let hostNode = try XCTUnwrap(listNode.descendantNodeFor(codes: ["netflix-se10-wireguard"]))
40+
41+
XCTAssertNil(listNode.parent)
42+
XCTAssertEqual(countryNode.parent, listNode)
43+
XCTAssertEqual(cityNode.parent, countryNode)
44+
XCTAssertEqual(hostNode.parent, cityNode)
45+
}
46+
3547
func testSearch() throws {
3648
let nodes = dataSource.search(by: "got")
3749
let rootNode = RootLocationNode(children: nodes)

0 commit comments

Comments
 (0)