Skip to content

Commit

Permalink
Merge branch 'fix-selection-of-custom-list-location-not-being-retaine…
Browse files Browse the repository at this point in the history
…d-ios-569'
  • Loading branch information
buggmagnet committed Mar 21, 2024
2 parents ffbeb23 + d55340c commit ab1424d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,21 @@ class CustomListsDataSource: LocationDataSourceProtocol {
return switch location {
case let .country(countryCode):
rootNode
.countryFor(code: countryCode)?.copy(withParent: parentNode)
.countryFor(code: countryCode)?
.copy(withParent: parentNode)

case let .city(countryCode, cityCode):
rootNode
.countryFor(code: countryCode)?.copy(withParent: parentNode)
.cityFor(codes: [countryCode, cityCode])
.countryFor(code: countryCode)?
.cityFor(codes: [countryCode, cityCode])?
.copy(withParent: parentNode)

case let .hostname(countryCode, cityCode, hostCode):
rootNode
.countryFor(code: countryCode)?.copy(withParent: parentNode)
.countryFor(code: countryCode)?
.cityFor(codes: [countryCode, cityCode])?
.hostFor(code: hostCode)
.hostFor(code: hostCode)?
.copy(withParent: parentNode)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ extension LocationNode {
}

extension LocationNode {
/// Recursively copies a node, its parent and its descendants from another
/// node (tree), with an optional custom root parent.
func copy(withParent parent: LocationNode? = nil) -> LocationNode {
let node = LocationNode(
name: name,
Expand Down
12 changes: 12 additions & 0 deletions ios/MullvadVPNTests/Location/CustomListsDataSourceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ class CustomListsDataSourceTests: XCTestCase {
XCTAssertNotNil(youtubeNode.descendantNodeFor(codes: ["youtube", "us", "dal"]))
}

func testParents() throws {
let listNode = try XCTUnwrap(dataSource.nodes.first(where: { $0.name == "Netflix" }))
let countryNode = try XCTUnwrap(listNode.descendantNodeFor(codes: ["netflix-se"]))
let cityNode = try XCTUnwrap(listNode.descendantNodeFor(codes: ["netflix-se-got"]))
let hostNode = try XCTUnwrap(listNode.descendantNodeFor(codes: ["netflix-se10-wireguard"]))

XCTAssertNil(listNode.parent)
XCTAssertEqual(countryNode.parent, listNode)
XCTAssertEqual(cityNode.parent, countryNode)
XCTAssertEqual(hostNode.parent, cityNode)
}

func testSearch() throws {
let nodes = dataSource.search(by: "got")
let rootNode = RootLocationNode(children: nodes)
Expand Down

0 comments on commit ab1424d

Please sign in to comment.