Jotley / app · jotley.ai / Jotley-iOSTests / InkspringIdeaLinkTests.swift
| 1 | import Foundation |
| 2 | import Testing |
| 3 | @testable import Jotley_iOS |
| 4 | |
| 5 | struct InkspringIdeaLinkTests { |
| 6 | private func query(_ url: URL) -> [String: String] { |
| 7 | let items = URLComponents(url: url, resolvingAgainstBaseURL: false)?.queryItems ?? [] |
| 8 | return Dictionary(uniqueKeysWithValues: items.map { ($0.name, $0.value ?? "") }) |
| 9 | } |
| 10 | |
| 11 | @Test func buildsNewIdeaLinkWithSource() throws { |
| 12 | let url = try #require(InkspringIdeaLink.url(title: "Weekly sync", text: "Ship the beta\nThen write the post")) |
| 13 | #expect(url.scheme == "inkspring") |
| 14 | #expect(url.host == "new-idea") |
| 15 | let values = query(url) |
| 16 | #expect(values["title"] == "Weekly sync") |
| 17 | #expect(values["text"] == "Ship the beta\nThen write the post") |
| 18 | #expect(values["source"] == "jotley") |
| 19 | } |
| 20 | |
| 21 | @Test func encodesPlusSoInkspringKeepsIt() throws { |
| 22 | let url = try #require(InkspringIdeaLink.url(title: nil, text: "C++ tips")) |
| 23 | #expect(url.absoluteString.contains("C%2B%2B")) |
| 24 | #expect(!url.absoluteString.contains("title=")) |
| 25 | } |
| 26 | |
| 27 | @Test func prefersSummaryAndStripsBoldMarkers() { |
| 28 | let text = InkspringIdeaLink.ideaText(summary: "**Key Points**\n- One idea", transcript: "raw words") |
| 29 | #expect(text == "Key Points\n- One idea") |
| 30 | #expect(InkspringIdeaLink.plainText("## Summary\nThe source outlines #1 ideas") == "Summary\nThe source outlines #1 ideas") |
| 31 | } |
| 32 | |
| 33 | @Test func fallsBackToTranscriptAndNothingWhenEmpty() { |
| 34 | #expect(InkspringIdeaLink.ideaText(summary: nil, transcript: " raw words ") == "raw words") |
| 35 | #expect(InkspringIdeaLink.ideaText(summary: " ", transcript: " ") == nil) |
| 36 | #expect(InkspringIdeaLink.url(title: "x", text: " ") == nil) |
| 37 | } |
| 38 | |
| 39 | @Test func shortensLongTextTo2000Units() throws { |
| 40 | let text = try #require(InkspringIdeaLink.ideaText(summary: nil, transcript: String(repeating: "word ", count: 1_000))) |
| 41 | #expect(text.utf16.count <= 2_000) |
| 42 | #expect(text.hasSuffix("…")) |
| 43 | } |
| 44 | } |