Save automatically, improve mocks

This commit is contained in:
Christoph Hagen
2025-02-05 12:24:33 +01:00
parent d41c54d174
commit 5abe6e1a9f
55 changed files with 701 additions and 381 deletions

View File

@@ -1,65 +1,90 @@
extension Post {
static var empty: Post {
.init(content: Content.mock,
id: "empty",
isDraft: true,
createdDate: .now,
startDate: .now,
endDate: nil,
tags: [],
german: .init(content: .mock,
text: "Text"),
english: .init(content: .mock,
text: "Text"),
linkedPage: nil)
}
enum Mock {
static var mock: Post {
Post(
content: Content.mock,
id: "mock",
isDraft: false,
createdDate: .now,
startDate: .now,
endDate: nil,
tags: [.nature, .sports, .hiking],
german: .init(
content: .mock,
title: "Der Titel",
text: "Sehr schöne und einsame Tour von Oberau zum Krottenkopf. Abwechslungsreich und stellenweise fordernd, aufgrund der Länge und der Höhenmeter auch anstrengend."),
english: .init(
content: .mock,
title: "The title",
text: "Very nice and solitary hike from Oberau to Krottenkopf. Challenging and rewarding, due to the length and height")
)
}
static func mockData(content: Content) -> [Post] {
[
Post(content: content,
id: "empty",
isDraft: true,
createdDate: .now,
startDate: .now,
endDate: nil,
tags: [],
german: .init(
content: content,
text: "Text"),
english: .init(
content: content,
text: "Text"),
linkedPage: nil),
Post(
content: content,
id: "hike",
isDraft: false,
createdDate: .now,
startDate: .now,
endDate: nil,
tags: [
content.tags.first(where: { $0.id == "nature" })!,
content.tags.first(where: { $0.id == "sports" })!,
content.tags.first(where: { $0.id == "hiking" })!
],
german: .init(
content: content,
title: "Eine Wanderung",
text: "Sehr schöne und einsame Tour von Oberau zum Krottenkopf. Abwechslungsreich und stellenweise fordernd, aufgrund der Länge und der Höhenmeter auch anstrengend."),
english: .init(
content: content,
title: "A hike",
text: "Very nice and solitary hike from Oberau to Krottenkopf. Challenging and rewarding, due to the length and height")
),
Post(
content: content,
id: "hike2",
isDraft: true,
createdDate: .now,
startDate: .now.addingTimeInterval(-86400), endDate: .now,
tags: [
content.tags.first(where: { $0.id == "nature" })!,
content.tags.first(where: { $0.id == "sports" })!,
content.tags.first(where: { $0.id == "hiking" })!,
content.tags.first(where: { $0.id == "mountains" })!
],
german: LocalizedPost(
content: content,
title: "Eine lange Wanderung",
text: "Sehr schöne und einsame Tour von Oberau zum Krottenkopf. Abwechslungsreich und stellenweise fordernd, aufgrund der Länge und der Höhenmeter auch anstrengend.",
images: [
content.files.first(where: { $0.id == "image1" })!,
content.files.first(where: { $0.id == "image2" })!,
content.files.first(where: { $0.id == "image3" })!,
content.files.first(where: { $0.id == "image4" })!
]),
english: LocalizedPost(
content: content,
title: "A longer hike",
text: "Very nice and solitary hike from Oberau to Krottenkopf. Challenging and rewarding, due to the length and height.",
images: [
content.files.first(where: { $0.id == "image1" })!,
content.files.first(where: { $0.id == "image2" })!,
content.files.first(where: { $0.id == "image3" })!,
content.files.first(where: { $0.id == "image4" })!
]))
]
}
static var fullMock: Post {
.init(
content: Content.mock,
id: "full",
isDraft: true,
createdDate: .now,
startDate: .now.addingTimeInterval(-86400), endDate: .now,
tags: [.nature, .sports, .hiking, .mountains],
german: .german,
english: .english)
static var empty: Post {
Content.mock.posts.first(where: { $0.id == "empty" })!
}
static var hike: Post {
Content.mock.posts.first(where: { $0.id == "hike" })!
}
static var hike2: Post {
Content.mock.posts.first(where: { $0.id == "hike2" })!
}
}
}
extension LocalizedPost {
static let german = LocalizedPost(
content: .mock,
title: "Ein langer Titel",
text: "Sehr schöne und einsame Tour von Oberau zum Krottenkopf. Abwechslungsreich und stellenweise fordernd, aufgrund der Länge und der Höhenmeter auch anstrengend.",
images: MockImage.images)
static let english = LocalizedPost(
content: .mock,
title: "A longer title",
text: "Very nice and solitary hike from Oberau to Krottenkopf. Challenging and rewarding, due to the length and height.",
images: MockImage.images)
}