apple_kit

Apple-native services for Radroots iOS and macOS apps
git clone https://radroots.dev/git/apple_kit.git
Log | Files | Refs | README

RadrootsExternalActionsTestingTests.swift (1488B)


      1 import Foundation
      2 import Testing
      3 import RadrootsKit
      4 import RadrootsKitTesting
      5 
      6 @Test func fakeExternalActionsRecordsCapabilityAndOpenRequests() async throws {
      7     let web = try RadrootsExternalActionDestination.web("https://radroots.org")
      8     let nostr = try RadrootsExternalActionDestination.nostr("nostr:npub1qqqqqq")
      9     let actions = RadrootsFakeExternalActions(
     10         capabilityOverrides: [nostr: false],
     11         defaultCanOpen: true
     12     )
     13 
     14     #expect(await actions.canOpen(web).canOpen)
     15     #expect(!(await actions.canOpen(nostr).canOpen))
     16     try await actions.open(RadrootsExternalActionRequest(destination: web))
     17 
     18     #expect(await actions.capabilityRequestCount == 2)
     19     #expect(await actions.openRequestCount == 1)
     20     #expect(await actions.lastCapabilityDestination == nostr)
     21     #expect(await actions.lastOpenedDestination == web)
     22     #expect(await actions.openedDestinations == [web])
     23 }
     24 
     25 @Test func fakeExternalActionsReturnsConfiguredFailures() async throws {
     26     let destination = RadrootsExternalActionDestination.appSettings
     27     let actions = RadrootsFakeExternalActions(
     28         openOutcome: .failure(.unavailable("external actions unavailable"))
     29     )
     30 
     31     await #expect(throws: RadrootsExternalActionError.unavailable("external actions unavailable")) {
     32         try await actions.open(RadrootsExternalActionRequest(destination: destination))
     33     }
     34 
     35     #expect(await actions.openRequestCount == 1)
     36     #expect(await actions.lastOpenedDestination == destination)
     37 }