Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,22 @@
}
}
},
"Open PDF instructions" : {
"localizations" : {
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "PDF-Anleitung öffnen"
}
},
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Open PDF instructions"
}
}
}
},
"Open Reading Mode" : {
"comment" : "A button that opens a reading mode.",
"isCommentAutoGenerated" : true,
Expand Down Expand Up @@ -1493,4 +1509,4 @@
}
},
"version" : "1.3"
}
}
8 changes: 8 additions & 0 deletions LoopLine/Services/ImportedPDFStorage.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import Foundation

enum ImportedPDFStorage {
static func fileURL(for project: Project) -> URL? {
guard project.sourceType == .pdf, let storedReference = project.sourceFilePath else {
return nil
}

return fileURL(for: storedReference)
}

static func directoryURL() throws -> URL {
let applicationSupportDirectory = try FileManager.default.url(
for: .applicationSupportDirectory,
Expand Down
6 changes: 1 addition & 5 deletions LoopLine/ViewModels/PDFReadingViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ final class PDFReadingViewModel {
var markupError: PDFMarkupError?

func pdfURL(for project: Project) -> URL? {
guard project.sourceType == .pdf, let sourceFilePath = project.sourceFilePath else {
return nil
}

return ImportedPDFStorage.fileURL(for: sourceFilePath)
ImportedPDFStorage.fileURL(for: project)
}

func selectedMetricValue(for project: Project) -> Int {
Expand Down
26 changes: 21 additions & 5 deletions LoopLine/Views/ProjectDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,19 @@ struct ProjectDetailView: View {
private var mediaHeader: some View {
Group {
if project.sourceType == .pdf, let sourceFilePath = project.sourceFilePath {
StoredPDFPreview(storedReference: sourceFilePath, height: 190)
.clipShape(RoundedRectangle(cornerRadius: LoopLineTheme.cornerRadius, style: .continuous))
.overlay {
RoundedRectangle(cornerRadius: LoopLineTheme.cornerRadius, style: .continuous)
.stroke(LoopLineTheme.subtleStroke, lineWidth: 1)
if ImportedPDFStorage.fileURL(for: project) != nil {
NavigationLink {
PDFReadingView(project: project)
} label: {
pdfPreview(storedReference: sourceFilePath)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.accessibilityLabel("Open PDF instructions")
.accessibilityIdentifier("openPDFPreview")
} else {
pdfPreview(storedReference: sourceFilePath)
}
} else if project.sourceType == .image, let sourceFilePath = project.sourceFilePath {
StoredImagePreview(storedReference: sourceFilePath, height: 190)
.clipShape(RoundedRectangle(cornerRadius: LoopLineTheme.cornerRadius, style: .continuous))
Expand All @@ -82,6 +89,15 @@ struct ProjectDetailView: View {
}
}

private func pdfPreview(storedReference: String) -> some View {
StoredPDFPreview(storedReference: storedReference, height: 190)
.clipShape(RoundedRectangle(cornerRadius: LoopLineTheme.cornerRadius, style: .continuous))
.overlay {
RoundedRectangle(cornerRadius: LoopLineTheme.cornerRadius, style: .continuous)
.stroke(LoopLineTheme.subtleStroke, lineWidth: 1)
}
}

private var titleBlock: some View {
VStack(alignment: .leading, spacing: 10) {
Text(project.name)
Expand Down
17 changes: 17 additions & 0 deletions LoopLineTests/ProjectPersistenceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@ import XCTest
@testable import LoopLine

final class ProjectPersistenceTests: XCTestCase {
@MainActor
func testPDFURLRequiresPDFSourceAndExistingFile() throws {
let fileURL = FileManager.default.temporaryDirectory
.appendingPathComponent("LoopLine-PDF-Resolver-\(UUID().uuidString).pdf")
try Data().write(to: fileURL)
defer { try? FileManager.default.removeItem(at: fileURL) }

let pdfProject = Project(name: "PDF", sourceType: .pdf, sourceFilePath: fileURL.path)
XCTAssertEqual(ImportedPDFStorage.fileURL(for: pdfProject), fileURL)

let textProject = Project(name: "Text", sourceType: .text, sourceFilePath: fileURL.path)
XCTAssertNil(ImportedPDFStorage.fileURL(for: textProject))

let missingPDFProject = Project(name: "Missing PDF", sourceType: .pdf)
XCTAssertNil(ImportedPDFStorage.fileURL(for: missingPDFProject))
}

@MainActor
func testProjectPreservesTrackingValuesAfterSaveAndFetch() throws {
let container = try ModelContainer(
Expand Down
18 changes: 18 additions & 0 deletions LoopLineUITests/ReadingModeUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,22 @@ final class ReadingModeUITests: XCTestCase {
let pdfReadingMode = app.descendants(matching: .any)["pdfReadingMode"]
XCTAssertTrue(pdfReadingMode.waitForExistence(timeout: 5))
}

@MainActor
func testUserCanOpenReadingModeFromPDFPreview() throws {
let app = XCUIApplication()
app.launchArguments.append("-uiTesting")
app.launch()

let project = app.buttons["uiTestPDFProject"]
XCTAssertTrue(project.waitForExistence(timeout: 5))
project.tap()

let pdfPreview = app.buttons["openPDFPreview"]
XCTAssertTrue(pdfPreview.waitForExistence(timeout: 5))
pdfPreview.tap()

let pdfReadingMode = app.descendants(matching: .any)["pdfReadingMode"]
XCTAssertTrue(pdfReadingMode.waitForExistence(timeout: 5))
}
}
Loading