Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / apple / FindFamily / Tests / FindFamilyTests / ShareAcceptDialogTests.swift
ShareAcceptDialogTests.swift104 lines · 4.2 KiBRaw
| 1 | import XCTest |
| 2 | @testable import FindFamily |
| 3 | |
| 4 | final class ShareAcceptDialogTests: XCTestCase { |
| 5 | |
| 6 | // MARK: - Share dialog |
| 7 | |
| 8 | func testShareDialogShowsOnlyMyIDAndShareInviteLinkButton() { |
| 9 | let model = ShareInviteDialogModel( |
| 10 | myIDString: "ABCDE", |
| 11 | inviteLink: "https://ma.vayunmathur.com/ff/share#id=ABCDE&k=abc-123_" |
| 12 | ) |
| 13 | XCTAssertEqual(model.presentedFields, [.myID, .shareInviteLinkButton]) |
| 14 | XCTAssertEqual(model.myIDString, "ABCDE") |
| 15 | XCTAssertFalse(model.showsContactInfo) |
| 16 | } |
| 17 | |
| 18 | func testShareDialogInviteLinkShapeIsUnchanged() { |
| 19 | // Same link shape as before the strip: https bounce page, id and |
| 20 | // fingerprint in the fragment. Android builds the identical shape. |
| 21 | let link = "https://ma.vayunmathur.com/ff/share#id=ABCDE&k=abc-123_" |
| 22 | let model = ShareInviteDialogModel(myIDString: "ABCDE", inviteLink: link) |
| 23 | XCTAssertEqual(model.inviteLink, link) |
| 24 | XCTAssertTrue(model.inviteLink.hasPrefix("https://")) |
| 25 | XCTAssertTrue(model.inviteLink.contains("#id=ABCDE")) |
| 26 | XCTAssertTrue(model.inviteLink.contains("&k=")) |
| 27 | } |
| 28 | |
| 29 | // MARK: - Accept dialog |
| 30 | |
| 31 | func testAcceptDialogIDIsHardcodedPrefilledAndNotEditable() { |
| 32 | let model = AcceptPersonDialogModel( |
| 33 | contactID: 12345, existingName: "Ada", existingPhoto: nil, |
| 34 | existingStatus: nil, myID: 999 |
| 35 | ) |
| 36 | XCTAssertFalse(model.isIDEditable) |
| 37 | XCTAssertEqual(model.contactID, 12345) |
| 38 | XCTAssertEqual(model.contactIDString, Base26.encode(12345)) |
| 39 | XCTAssertEqual(model.presentedFields, [.contactID, .contactName, .requestLocationButton]) |
| 40 | XCTAssertFalse(model.showsContactPicker) |
| 41 | XCTAssertFalse(model.showsMyID) |
| 42 | XCTAssertFalse(model.showsShareInviteLinkButton) |
| 43 | } |
| 44 | |
| 45 | func testAcceptDialogShowsContactName() { |
| 46 | let named = AcceptPersonDialogModel( |
| 47 | contactID: 7, existingName: "Ada Lovelace", existingPhoto: "photo", |
| 48 | existingStatus: .awaitingRequest, myID: 999 |
| 49 | ) |
| 50 | XCTAssertEqual(named.contactName, "Ada Lovelace") |
| 51 | |
| 52 | // No stored row (fresh invite link): fall back to the ID-based name |
| 53 | // used for inbound requests, never an editable/contact-picked name. |
| 54 | let unnamed = AcceptPersonDialogModel( |
| 55 | contactID: 7, existingName: nil, existingPhoto: nil, |
| 56 | existingStatus: nil, myID: 999 |
| 57 | ) |
| 58 | XCTAssertEqual(unnamed.contactName, "ID \(Base26.encode(7))") |
| 59 | } |
| 60 | |
| 61 | func testRequestButtonIssuesLocationRequest() { |
| 62 | let model = AcceptPersonDialogModel( |
| 63 | contactID: 42, existingName: "Grace", existingPhoto: nil, |
| 64 | existingStatus: nil, myID: 999 |
| 65 | ) |
| 66 | XCTAssertTrue(model.requestEnabled) |
| 67 | XCTAssertEqual(model.resultingStatus, .awaitingResponse) |
| 68 | |
| 69 | let user = model.makeUser(verifiedBundleB64: "bundle", now: Date(timeIntervalSince1970: 0)) |
| 70 | XCTAssertEqual(user.id, 42) |
| 71 | XCTAssertEqual(user.name, "Grace") |
| 72 | XCTAssertEqual(user.requestStatus, .awaitingResponse) |
| 73 | XCTAssertTrue(user.sendingEnabled) |
| 74 | XCTAssertEqual(user.pqcEncryptionKey, "bundle") |
| 75 | } |
| 76 | |
| 77 | func testRequestButtonAcceptsInboundRequestAsMutual() { |
| 78 | let model = AcceptPersonDialogModel( |
| 79 | contactID: 42, existingName: "Grace", existingPhoto: nil, |
| 80 | existingStatus: .awaitingRequest, myID: 999 |
| 81 | ) |
| 82 | XCTAssertTrue(model.requestEnabled) |
| 83 | XCTAssertEqual(model.resultingStatus, .mutualConnection) |
| 84 | XCTAssertEqual( |
| 85 | model.makeUser(verifiedBundleB64: nil, now: Date()).requestStatus, |
| 86 | .mutualConnection |
| 87 | ) |
| 88 | } |
| 89 | |
| 90 | func testRequestButtonDisabledForSelfAndExistingConnections() { |
| 91 | XCTAssertFalse(AcceptPersonDialogModel( |
| 92 | contactID: 999, existingName: "Me", existingPhoto: nil, |
| 93 | existingStatus: nil, myID: 999 |
| 94 | ).requestEnabled) |
| 95 | XCTAssertFalse(AcceptPersonDialogModel( |
| 96 | contactID: 42, existingName: "Grace", existingPhoto: nil, |
| 97 | existingStatus: .mutualConnection, myID: 999 |
| 98 | ).requestEnabled) |
| 99 | XCTAssertFalse(AcceptPersonDialogModel( |
| 100 | contactID: 42, existingName: "Grace", existingPhoto: nil, |
| 101 | existingStatus: .awaitingResponse, myID: 999 |
| 102 | ).requestEnabled) |
| 103 | } |
| 104 | } |